Skip to content
mentoor

Topic 5 of 5 · 5 min read

Recognising commands that must never auto-run

Goal: Spot the command in an agent's run log that should have required approval or been blocked, and name the rule that stops it.

Some commands cannot be undone or reach beyond the project, so they should always need a human or be blocked outright, whatever mode the agent is in. Learn the short list and you can read a run log quickly.

Check yourself · 1 of 3

Which command should never auto-run, in any approval mode?

Choose one answer

Why it matters

Most agent mistakes are cheap: a bad edit, a failed test. A few are not. Deleted history, a dropped table or a leaked key stays a problem long after you notice. Agents also act fast and with confidence, and sometimes pick a destructive shortcut to get unstuck, such as deleting a lock file or resetting the branch.

The short list

  • History rewrites: git push --force, git reset --hard, git clean -fd, git checkout . with uncommitted work.
  • Recursive deletes: rm -rf with a variable or a path outside the project, such as rm -rf $DIR/. An empty $DIR becomes /.
  • Piped installers: curl https://… | sh. You run code you never read.
  • Production reach: database migrations, kubectl apply, terraform apply, deploy scripts, anything with a production connection string.
  • Credential reads: cat ~/.ssh/id_ed25519, printenv, reading .env files, cloud credential folders.
  • Publishing: npm publish, docker push, sending email or messages.

How to do it

  1. Deny the unambiguous ones (rm -rf, force push, credential paths) so no mode can run them.
  2. Ask for the ones that are sometimes right (a migration against a dev database, a normal push).
  3. Keep production credentials out of the agent's environment. A command cannot run against production if the agent has no way in.
  4. Read run logs for the pattern, not the tool name: destructive verb, wide target, no way back.

Before and after

Log line: rm -rf $BUILD_DIR/* where the script earlier failed to set BUILD_DIR. Before: allowed because rm was on the allow list. After: rm -rf is denied; the agent must delete a named folder with a plain command, and a git commit protects the work first.

What goes wrong

  • Allowing rm or git as a whole, which includes their worst forms.
  • Trusting the dev database name. Check the connection string: a "dev" label on a production host is a common slip.
  • Believing a rule is enough alone. Also use backups, branches and a sandbox so a mistake can be undone.

Examples

Reading a run log

Three lines: npm test (fine), git reset --hard origin/main (discards uncommitted work), curl https://get.example.sh | bash (runs unread code). Only the first should auto-run. Name the rule for the other two: deny git reset --hard and deny piped shell installers.

The empty variable

A cleanup script runs rm -rf "$OUT"/ and $OUT is empty. The target becomes the root of the filesystem. A deny rule on rm -rf and a sandbox that hides everything outside the project both stop it.

Key points

  • Treat irreversible or out-of-project commands as always-ask or always-deny, in every mode.
  • The core list: history rewrites, recursive deletes, piped installers, production changes, credential reads and publishing.
  • Deny the clearly bad forms and ask for the sometimes-right ones.
  • Keep production credentials out of the agent's environment so the command cannot reach production at all.
  • Rules limit the chance of a mistake; branches, backups and sandboxes limit its cost.

Common mistakes

  • Allowing rm or git as a whole program.
  • Reviewing only the final summary, not the commands in the run log.
  • Having production credentials in the same shell the agent uses.
  • Relying on rules and having no commit or backup to return to.

Check yourself · 2 of 3

Why is rm -rf $DIR/ risky in a script an agent runs?

Choose one answer

Check yourself · 3 of 3

What best limits the damage from a destructive command that slips past the rules?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic