Why it matters
Agents run cleanup to make a build pass: remove a directory, reset a branch, drop and recreate a database. Those commands are normal in a developer's hands and catastrophic when the agent has guessed the target. The engineering problem is that the dangerous action is usually not the requested one but a side effect, and the feedback that would reveal the loss is missing because tests run against fixtures that recreate the data.
Mental model
It is a table saw with a guard: the protection is physical, not a warning label. The metaphor breaks because the guard can be removed by a flag the agent passes on its own, so the block has to live below the command line.
How it works
Step 1 of 7
Classify by reversibility, not alarm
Four properties, decided independently, and the strictest answer wins. A migration that looks alarming and can be rolled back is a different case from a quiet reset that cannot.
question · current
Command · resolved target
The command as typed is not the target. A glob, a symlink or a branch name resolves somewhere else, and the resolved target is what gets classified before anything executes.
Root of the hierarchy
Also in focus
- Scope · where does it write?
- Reversibility · can it be rebuilt?
- Blast radius · who else is affected?
- Record the before-state
Figure. A proposed command classified before it runs by scope, reversibility, blast radius and detectability. Each property has the safe answer and the failure that looks routine, and the crossed branch is the instruction-only guard, which is input where a block is needed.
What to notice. The commands, paths and refs are an authored example; the page publishes no counts, so none are drawn. This is a permission decomposition, not a severity ladder: a command can be in scope and still irreversible, so the properties are decided independently and the strictest answer wins. Omitted: the approval interface and the snapshot retention window, which the page treats as operations.
Text version
A permission tree for a destructive command. The root is a command with its resolved target, classified by absolute path and real path. Four properties hang from it. Scope asks where it writes: a gate under the task root passes, and a crossed glob or symlink escape is blocked with the resolved path logged. Reversibility asks whether the state can be rebuilt: a snapshot or soft delete makes it reversible, and an irreversible action needs a named human approval that shows the exact target and logs the identity. Blast radius asks who else is affected: a shared branch or table is blocked from force-push with remote refs compared, while a task-owned branch or namespace is allowed and recorded. Detectability records a before-state hash or row count, with a dry run before bulk mutation. A crossed instruction-only guard is ruled out because prompt text cannot block a command. Steps classify by reversibility, resolve the target, snapshot or dry run, require approval, block shared refs, record the before-state and rule out the prompt.
- List every command and API call in the environment that destroys state, and mark each one reversible or not.
- Block the irreversible set at the tool layer and return a structured refusal the agent can read.
- Require a named human approval for anything left, showing the exact resolved target.
- Prefer soft delete, a backup branch or a snapshot before any bulk mutation.
- Scope delete commands to a task-owned path or namespace and reject globs that escape it.
- Record the before-state hash or row count so a bad action is detectable afterwards.
Trade-offs
| Choice | Good for | Cost | Fails when |
|---|---|---|---|
| Hard block in the tool layer | Reliable and auditable | Agent cannot finish legitimate cleanup | Task requires deleting generated artefacts |
| Approval prompt | Human judgement | Fatigue and click-through | Runs are unattended |
| Snapshot before mutation | Reversible | Storage and restore time | Data is large or external |
| Prompt instruction only | No engineering | Bypassed by any injected instruction | Anything irreversible is at stake |
Good for
Reliable and auditable
Cost
Agent cannot finish legitimate cleanup
Fails when
Task requires deleting generated artefacts
- Task requires deleting generated artefacts
- Runs are unattended
- Data is large or external
- Anything irreversible is at stake
Figure. Each choice with what it buys, what it costs, and the case where it loses.
What to notice. The fourth column is the decision: if the losing case describes your situation, the choice is wrong.
Text version
Four trade-offs: Hard block in the tool layer is good for Reliable and auditable, costs Agent cannot finish legitimate cleanup, and fails when Task requires deleting generated artefacts. Approval prompt is good for Human judgement, costs Fatigue and click-through, and fails when Runs are unattended. Snapshot before mutation is good for Reversible, costs Storage and restore time, and fails when Data is large or external. Prompt instruction only is good for No engineering, costs Bypassed by any injected instruction, and fails when Anything irreversible is at stake
Failure modes
- Glob escape. A delete scoped to a build directory resolves to the repository root. Debug: log resolved absolute paths before execution and assert they sit under the task root.
- History rewrite. The agent force-pushes to make a check pass and discards a colleague's commits. Debug: compare remote refs before and after, and block force-push on shared branches.
- Silent data drop. A migration drops a column and the tests use a fixture that recreates it. Debug: diff the schema against the pre-run snapshot.
In production
Audit destructive commands with the resolved target and the approving identity. Keep snapshots for the retention window and rehearse a restore.
Common misconceptions
People think: A careful prompt is enough protection.
Actually: Prompts are input, not policy, so the block has to live where the command executes.
People think: Destructive actions are always obvious.
Actually: The risky ones look like routine cleanup and pass tests because fixtures hide the loss.
Interview angle
Classify by reversibility and put the block in the execution layer. A strong answer shows the resolved target to an approver and mentions snapshots plus a tested restore. Instructing the model to be careful, without discussing globs or force-push, is the answer that fails the first time.
Sources
- OWASP, Top 10 for LLM Applications — excessive agency and unsafe tool execution.
- Git, git-reset documentation — the modes that discard working tree state.
- Anthropic, Claude Code security — permission modes and approval for risky commands.