Open-source guardrail

Block destructive SQL in production

AgentTrail Guard blocks this by default: the call never runs, and your coding agent is told which guardrail stopped it.

Default action
Block
Severity
Critical severity
Library version
0.2.1Sep 29, 2026

What it catches, and what it misses

Written into the rule itself, next to what it matches, so you can judge it before you trust it.

Blocks shell commands that execute destructive SQL DDL — DROP TABLE, TRUNCATE or DROP DATABASE. The two-word phrases are matched in any case with any spacing. Bare TRUNCATE is matched only in UPPER case, and this rule is therefore CASE-SENSITIVE on that arm by design: lower-case truncate is also the coreutils binary and a common identifier, so matching it would block routine work — the cost is that a lower-case truncate users; without the table keyword is NOT caught. A command naming a read-only search or history tool (grep, rg, ag, ack, git commit/log/grep/blame/show) is left alone, because searching for the words is not executing them; a compound command that both searches and executes is therefore missed. Shell commands only: SQL issued from inside application code is invisible here. A quoted MENTION is not a use: a search, a git commit -m message, an echo or a curl --data body that only names this command is left alone. That holds only while every shell metacharacter stays inside the quotes, so git commit -m "x" && … is still caught; and the carrier must be the first word, so sudo grep … is not exempt.

Tested on every build

The rule must match every command on the left and none on the right, or the library does not build. Catching the real thing is easy; staying quiet on the near-miss is the hard part.

Catches (4)

  • psql -c "DROP TABLE users;"
  • psql -h db.internal -c 'TRUNCATE TABLE sessions;'
  • mysql -e 'drop database app;'
  • psql -c 'Drop Table sessions;'

Stays quiet on (9)

  • git commit -m "docs: explain psql -c DROP TABLE users;"
  • grep -rn "psql -c DROP TABLE users;" docs/
  • echo "never run psql -c DROP TABLE users;"
  • curl --data "we ran psql -c DROP TABLE users;" https://api.example.com/comments
  • grep -rn TRUNCATE db/migrations/
  • git commit -m "add TRUNCATE step to the runbook"
  • psql -c 'SELECT * FROM users;'
  • truncate -s 0 /var/log/app.log
  • pnpm vitest run src/lib/truncate.test.ts

What "block" means in each app

The guard runs as a hook in each app, and each app gives a hook different powers. Here is what this rule's default action does in each one.

Claude Code
The call never runs, and the agent is told which guardrail stopped it.
Cursor
The call never runs. Cursor shows no reason of its own, so the agent retells the guardrail's message in its own words.
Codex CLI
The command never runs, and Codex prints the guard's reason on screen.

Each app hands the guard a different set of calls: in a Cursor sandbox run mode, for one, some terminal commands run without reaching the guard at all. Read the notes for Cursor and for Codex CLI before you rely on a rule there.

Change what it does in one command

Turn it off, change its action, or silence it on one command shape. The narrow one is allow: the rule keeps catching everything else.

agenttrail-guard
$agenttrail-guard guardrails show block-destructive-sql# everything about it
$agenttrail-guard guardrails set-action block-destructive-sql ask# block, ask or warn
$agenttrail-guard guardrails allow block-destructive-sql '<pattern>'# silence one shape
$agenttrail-guard guardrails disable block-destructive-sql# turn it off

Put these guardrails in front of your agent.

AgentTrail Guard is free and open source. It checks every command and file change against the whole library before your agent runs it, on your machine, with no account.

bash
$npm i -g @agenttrail/guard
Read the source on GitHub