15 commands an AI agent runs while trying to help.
The real incident, the 15 commands an agent runs while trying to help, the skill that makes it check each one first, the 6 locks and the "it already ran" checklist.
By Agent Cop. We build Cop, which checks AI agents' tool calls against rules mapped to MITRE ATLAS and the OWASP agentic Top 10. Our lab runs 7 agents on 7 stacks around the clock. This kit comes from an incident we lived through.
What happenedNobody attacked the agent.
A coding agent drives a server from PowerShell. It is asked to move a folder. It sends:
ssh root@vps "mv $SRC/* $DST/"
With double quotes, PowerShell expands $SRC and $DST itself, using their local values. They are empty. The server receives a mv that starts from the root /*. The file system gets moved and the server does not come back. We had to fall back to an older machine.
| What the agent meant | What it wrote | What the server received |
|---|---|---|
| Move a folder | mv $SRC/* $DST/ | A mv /*: the whole root |
The agent was not hacked. It did not leave its mission. It did exactly what it was asked, and that was the worst possible outcome.
Why keyword guardrails are not enough
In our lab, we replayed 12 of these commands against our first detection rules, the ones that look for patterns like rm -rf. Only one fired. The danger is not in the word. It is in the target (the root, a system folder, production) and in the shape of the command (a variable that can be empty). That is what we are teaching Cop right now.
Part 1The 15 commands, from innocent request to damage
Every row starts from a normal request. None of them needs an attacker.
| # | The request | The command | What breaks |
|---|---|---|---|
| 1 | "Move the old release on the server" | ssh vps "mv $SRC/* $DST/" | Run from PowerShell, the variables are empty on the local side: the mv starts from the root /*. |
| 2 | "Delete the build folder" | rm -rf /$DIR | $DIR is empty: the command becomes rm -rf /. |
| 3 | "Clean up the site folder" | rm -r /var/www | Every site on the server goes, not just yours. |
| 4 | "Delete the old logs" | find / -name "*.log" -delete | Every log on the machine, including the ones that would have explained the incident. |
| 5 | "Fix the site permissions" | chown -R www-data / | On the root: sudo and ssh stop working. With chmod -R 777, everyone writes everywhere. |
| 6 | "Deploy the build" | rsync -a --delete ./build/ vps:/ | --delete to the root: everything not in the build is wiped. |
| 7 | "Get the repo clean" | git reset --hard && git clean -fdx | Uncommitted work and ignored files (your .env included) are gone. |
| 8 | "Free up some disk space" | docker system prune -af --volumes | Volumes go with the images: so do the containers' databases. |
| 9 | "Tear down the test environment" | terraform destroy -auto-approve | In the wrong workspace, production goes, with no confirmation. |
| 10 | "Delete the test namespace" | kubectl delete namespace app | The active context was production. |
| 11 | "Purge the test accounts" | DELETE FROM users | No WHERE: the whole table. |
| 12 | "Open port 8080" | ufw reset | Firewall reset: the server is wide open, or locked away from you. |
| 13 | "Restore the default nginx config" | echo '' > /etc/nginx/nginx.conf | Config overwritten: every site goes down on the next reload. |
| 14 | "Run the migration on staging" | the same command, on the production host | Production gets a change that was tested nowhere. |
| 15 | "Replace the old domain everywhere" | sed -i 's/old/new/g' $(grep -rl old /etc) | Dozens of system files changed at once, with no backup. |
The same 15, with the agent-shell-guard skill loaded
None of these commands contains a scary word. Each one has a target you can check before it runs. That is what the skill makes your agent do, row by row:
| # | The command | What the skill tells your agent to do |
|---|---|---|
| 1 | ssh vps "mv $SRC/* $DST/" | Refuses the inline ssh with variables. Writes a script with ${SRC:?} and ${DST:?}, shows it, sends it with scp. |
| 2 | rm -rf /$DIR | Resolves $DIR first. Empty: stops, and writes ${DIR:?} so the command fails instead of hitting /. |
| 3 | rm -r /var/www | /var is a system folder: refuses, and proposes the exact site folder instead. |
| 4 | find / -name "*.log" -delete | Target /: refuses, and proposes the app's log folder, with a find without -delete first. |
| 5 | chown -R www-data / | Target /: refuses. chown -R on the site folder only, after showing it. |
| 6 | rsync -a --delete ./build/ vps:/ | Remote target /: refuses. rsync -n to the release folder first, then asks. |
| 7 | git reset --hard && git clean -fdx | Lists what will be lost first (git status, git clean -n, ignored files like .env), then asks. |
| 8 | docker system prune -af --volumes | Shows the volumes that would go (docker volume ls), then asks for that exact command. |
| 9 | terraform destroy -auto-approve | Prints the Terraform workspace, runs terraform plan, never adds -auto-approve on its own. |
| 10 | kubectl delete namespace app | Prints the kube context, says "production" out loud, runs --dry-run=server first. |
| 11 | DELETE FROM users | A table without WHERE: refuses. SELECT COUNT(*) with the WHERE first, then asks. |
| 12 | ufw reset | Shows the current rules (ufw status) and what a reset removes, then asks. |
| 13 | echo '' > /etc/nginx/nginx.conf | > on an existing file in /etc: shows it, proposes a backup copy, then asks. |
| 14 | the same command, on the production host | Prints the host first. Production is said in one line, then it waits for your yes. |
| 15 | sed -i 's/old/new/g' $(grep -rl old /etc) | Files in /etc: refuses the bulk edit, lists the files, proposes one file at a time with a backup. |
Get the agent-shell-guard skill
One folder with a SKILL.md file, for Claude Code and Codex. Before any command that deletes, moves, overwrites or runs on another machine, your agent resolves the real target, refuses / and system folders, checks the host or context, dry-runs, then asks you for that exact command. It also audits your agent's past commands.
How to install it, and the whole file to read first: Part 3.
Part 2The 6 locks to set before you give your agent a shell
1. No inline remote commands, ever
A local script, reviewed, uploaded with scp, then run with ssh vps 'bash /tmp/script.sh'. Single quotes stop your local shell from touching the variables.
2. The script stops at the first doubt
set -euo pipefail at the top. And ${DIR:?} for every variable inside a path: if it is empty, the command refuses to run instead of aiming at /.
3. No production keys in the agent's environment
It works with staging credentials. Production goes through you, or through a pipeline with its own guardrails.
4. Human approval on destructive commands
Most coding agents can ask before running a command. Turn it on at least for rm -r, mv from the root, rsync --delete, find -delete, chown -R, git reset --hard, git clean, docker prune, down -v, terraform destroy, kubectl delete, DELETE and UPDATE without WHERE, iptables -F, ufw reset.
5. The dry run before the real run
rsync -n, terraform plan, kubectl --dry-run=server, git clean -n, and a SELECT COUNT(*) with the same WHERE before any DELETE.
6. A snapshot before any server operation
And a restore you have already tested once. The day it breaks, you restore in minutes instead of rebuilding.
Does your agent have a shell, keys, access to production?
Describe it or drop its files. Agent Cop's free Scan tells you in a minute what it can do and what can go wrong.
Scan my agent, freePart 3The agent-shell-guard skill, ready to install in Claude Code or Codex
A skill is a folder with a SKILL.md file. Your agent reads its description and loads it whenever a command matches: no prompt to remember, nothing to paste in every session. These are the rules we have applied to our own agents since the incident.
- 5 checks before a risky command: resolve the target, refuse forbidden targets, check where it runs, dry run, ask for that exact command.
- Commands sent to another machine: a reviewed script uploaded with
scp, never an inlinessh "…"with variables. - If it already ran: the first-hour steps, so the agent stops digging.
- Audit mode: ask it to audit your agent's command history.
Install it
Unzip it into your agent's skills folder, from the folder where you downloaded it. Restart the agent so it picks the skill up.
# Claude Code (macOS, Linux, WSL) mkdir -p ~/.claude/skills && unzip -o agent-shell-guard.zip -d ~/.claude/skills # Codex mkdir -p ~/.codex/skills && unzip -o agent-shell-guard.zip -d ~/.codex/skills # Windows PowerShell (Claude Code) Expand-Archive agent-shell-guard.zip -DestinationPath $HOME\.claude\skills -Force
Read it before you install it
You should never install an agent instruction you have not read. Here is the whole file:
Show SKILL.md
---
name: agent-shell-guard
description: Stops destructive shell commands before they run. Use before any command that deletes, moves, overwrites, resets or changes permissions (rm, mv, cp -r over existing files, rsync --delete, find -delete, chown -R, chmod -R, sed -i or any in-place edit across several files, git reset --hard, git clean, docker prune, docker compose down -v, terraform destroy, kubectl delete, SQL DELETE, UPDATE, DROP or TRUNCATE, database migrations, iptables, ufw, > on an existing file), before any command sent to another machine (ssh, scp, docker exec, kubectl exec, Invoke-Command), and when the user asks to audit an agent's command history.
---
# Agent shell guard
Most server disasters do not come from an attacker. They come from a helpful agent that runs the right command on
the wrong target: an empty variable, the wrong quotes, the wrong host, the wrong context.
Your rule: **never run a command whose real target you have not checked.**
## Before a risky command: 5 checks
Run these checks, in this order, before any command listed in this skill's description.
1. **Resolve the target.** Expand every variable and glob yourself and write the absolute paths the command will
touch. If a variable can be empty or unset, stop: set it explicitly, or write it as `${VAR:?}` so the command
fails instead of falling back to `/`.
2. **Refuse forbidden targets.** Do not run the command if the resolved target is `/`, `/*`, a system folder (`/etc`,
`/usr`, `/var`, `/bin`, `/boot`, `/home`, `/root`), a whole disk, a whole database, or a table without `WHERE`.
Say why and propose a narrower command.
3. **Check where it runs.** Print the host (`hostname`), the kube context (`kubectl config current-context`), the
Terraform workspace (`terraform workspace show`) or the database name. If it is production, say so in one line.
4. **Dry run first** when one exists: `ls` of the glob, `rsync -n`, `terraform plan`, `kubectl --dry-run=server`,
`git clean -n`, `SELECT COUNT(*)` with the same `WHERE`.
5. **Ask for this exact command.** Show the command, the resolved target, where it runs, what will be lost and how
to undo it (snapshot, backup, git). Wait for an explicit yes. A general instruction ("clean it up", "deploy it",
"free some space") is not a yes for a destructive command.
## Commands sent to another machine
- Never send an inline remote command that contains a variable, a glob, a pipe, a redirection or several commands
(`ssh host "…"`, `docker exec … sh -c "…"`, `Invoke-Command`). With double quotes, your local shell (bash, zsh,
PowerShell) replaces the variables **before** the command leaves. If they are empty locally, `mv $SRC/* $DST/`
reaches the server as a `mv` that starts from the root.
- Instead: write a local script that starts with `set -euo pipefail`, use `${VAR:?}` for every variable inside a
path, show the script, upload it with `scp`, then run it with single quotes: `ssh host 'bash /tmp/<name>.sh'`.
- Inside the script, before any `rm`, `mv`, `cp -r`, `chown -R` or symlink change, print the resolved source and
destination and exit if one is empty or root-level.
## Never
- Never add `--force`, `-y`, `-auto-approve`, `--no-preserve-root` or `yes |` to get past a confirmation, unless the
user approved that exact command.
- Never put a destructive command after `&&` or `;` behind a step that can fail silently or leave a variable empty.
- Never read a `.env` file and never print a secret.
## If a destructive command already ran
1. Stop. No more commands until the user knows what happened.
2. Keep the current session open; a new connection may not get through.
3. Do not reboot: what still runs in memory can help recovery.
4. Find the exact command, its time and its target in the history and logs.
5. Measure the damage without writing anything (`ls -la /`, `df -h`, service status).
6. Recommend restoring from the last snapshot or backup rather than repairing by hand.
7. List the secrets that may have been printed, copied or deleted, so the user can rotate them.
8. Propose the rule that would have stopped it.
## Audit mode
When the user asks you to audit an agent's command history (pasted or from a log file), answer with one table:
`command | resolved target | verdict (SAFE, RISKY, DESTRUCTIVE) | what can be lost | the safe version`
- A variable that can be empty inside a path makes a command at least RISKY. Show what the command becomes if it is
empty.
- A remote command with double quotes and a variable is RISKY: the variable is replaced on the local machine.
- A command that deletes, moves, overwrites or resets on `/`, a system folder, production or a whole database is
DESTRUCTIVE.
- Do not invent context. If the target is unclear, write "unknown target".
End with the 3 rules to add to this agent's instructions so it does not happen again. Before reading a history,
remind the user to remove addresses, hostnames and anything that looks like a secret.
## Limits
This skill changes how the agent decides. It does not block anything at the system level: an agent that ignores
its instructions can still run the command. To block for real, turn on your agent's approval mode for shell
commands, or put a tool-call firewall in front of it, such as Cop (https://agent-cop.com).
Made by Agent Cop from a real incident, November 2026. Free to use, share and adapt.
A skill changes how the agent decides. It does not block anything at the system level. Keep lock 4 on (approval for destructive commands), or put a tool-call firewall such as Cop in front of the agent.
No skills in your agent? Paste this block instead
Into CLAUDE.md, AGENTS.md, .cursorrules or the system prompt.
## Shell rules (no exceptions)
- Never run an inline remote command (ssh host "…", docker exec, Invoke-Command) that contains a variable, a pipe, a redirection or several commands. Write a local script, show it to me, upload it with scp, then run it with: ssh host 'bash /tmp/<script>.sh'.
- Every script starts with set -euo pipefail. Every variable inside a path is written ${VAR:?}.
- Before any command that deletes, moves, overwrites or resets (rm, mv, rsync --delete, find -delete, chown -R, chmod -R, git reset --hard, git clean, docker prune, compose down -v, terraform destroy, kubectl delete, SQL DELETE or UPDATE, iptables, ufw, > on an existing file): show the exact command, the target resolved as an absolute path and what will be lost, then wait for my written approval.
- Refuse any target equal to /, /*, a system folder (/etc, /usr, /var, /bin, /boot, /home) or a whole database.
- Run the dry-run version first when one exists: rsync -n, terraform plan, kubectl --dry-run=server, git clean -n, SELECT COUNT(*) with the same WHERE.
- Before acting on a server, check the host, the kube context or the database. If it is production, say so in one line and wait for my approval.
- Never read a .env file and never print a secret.Part 4The "it already ran" checklist: what to do in the first hour
- Stop the agent. No more commands until you understand what happened.
- Keep your session open. If you are still connected to the server, do not log out: a new connection may not get through.
- Do not reboot. What is still running in memory can help you recover.
- Find the exact command. Agent history, logs,
history. Write down the time and the target. - Measure the damage without writing anything.
ls -la /,df -h, service status. - Restore rather than repair. Last snapshot or last backup: faster and safer than fixing by hand.
- Rotate the secrets if they could have been printed, copied or deleted.
- Write the lock that would have stopped it and add it to the skill from Part 3.
BonusThe skill also audits your agent's past commands
Once the skill is installed, ask your agent: "Use agent-shell-guard to audit these commands", and paste its latest commands or point it at a log file. First remove addresses, hostnames and anything that looks like a secret. You get one table: command, resolved target, verdict (SAFE, RISKY, DESTRUCTIVE), what can be lost, and the safe version, then the 3 rules to add so it does not happen again.
RecapYou now have:
- The agent-shell-guard skill, ready to install in Claude Code or Codex
- The 15 commands, from innocent request to damage
- The 6 locks to set before you give your agent a shell
- The "it already ran" checklist: what to do in the first hour
- The skill also audits your agent's past commands
Next: know what your agent can do, before it does it
The Scan is free, no account needed. Describe your agent and it lists its permissions, the risks and what to lock first.
Scan my agent, freeSources: PowerShell, about_Quoting_Rules (double quotes expand variables). Bash, the set builtin (-e, -u, pipefail). Bash, shell parameter expansion (${VAR:?}). OWASP GenAI Security Project. Kit created in November 2026 by Agent Cop.