Skip to content
AI Engineer Guide.

concept · coding · intermediate · concept 20 of 30

Destructive actions

0 of 30 complete

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

Four properties decide a commandInteractive
13 nodes · 4 branches
validation gatequestionnoteruled out or rejected

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
Step 1/7 · Classify by reversibility, not alarm

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.

  1. List every command and API call in the environment that destroys state, and mark each one reversible or not.
  2. Block the irreversible set at the tool layer and return a structured refusal the agent can read.
  3. Require a named human approval for anything left, showing the exact resolved target.
  4. Prefer soft delete, a backup branch or a snapshot before any bulk mutation.
  5. Scope delete commands to a task-owned path or namespace and reject globs that escape it.
  6. Record the before-state hash or row count so a bad action is detectable afterwards.

Trade-offs

ChoiceGood forCostFails when
Hard block in the tool layerReliable and auditableAgent cannot finish legitimate cleanupTask requires deleting generated artefacts
Approval promptHuman judgementFatigue and click-throughRuns are unattended
Snapshot before mutationReversibleStorage and restore timeData is large or external
Prompt instruction onlyNo engineeringBypassed by any injected instructionAnything irreversible is at stake
Trade-off mapInteractive

Good for

Reliable and auditable

Cost

Agent cannot finish legitimate cleanup

Fails when

Task requires deleting generated artefacts

  1. Task requires deleting generated artefacts
  2. Runs are unattended
  3. Data is large or external
  4. 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