{"slug": "how-to-block-ai-coding-agents-from-running-rm-rf-force-push-and-other-banned", "title": "How to block AI coding agents from running rm -rf, force push and other banned commands", "summary": "A new blog post lays out a three-layer approach to stopping AI coding agents from executing destructive commands such as `rm -rf`, `git push --force` and `prisma migrate reset`: server-side branch protection on GitHub or GitLab, per-agent deny rules and hooks in Claude Code, Codex and Cursor, and containment in a container, disposable VM or fresh clone. The post promotes Harbor, a tool that enforces team guardrails at command-execution time across Claude Code, Codex, Cursor and GitHub Copilot and, rather than issuing a bare denial, tells the agent the sanctioned alternative — for example substituting `prisma migrate dev` for `prisma migrate reset`. Harbor's hook fails open if it errors, and the post advises keeping branch protection and sandboxes in place and testing a banned command in a test repo via `harbor check \"git push --force\"` before relying on it; `npx harborloop init` is free for one teammate.", "body_md": "Blog\n\n# How to block AI coding agents from running rm -rf, force push and other banned commands\n\nPublished\n\nAn agent with shell access will eventually try a command you wish it hadn't. Use layers.\n\n## Layer 1: the server\n\nTurn on branch protection on GitHub or GitLab. Disable force pushes on main and release branches and require pull requests. This holds even if an agent tries.\n\n## Layer 2: each agent's own settings\n\n- **Claude Code:** deny rules in settings and PreToolUse hooks that inspect a command before it runs ([Claude Code hooks](https://gethrbr.com/blog/claude-code-hooks) ).\n- **Codex:** execution rules that forbid a command or require approval ([a forbidden Codex rule](https://gethrbr.com/blog/why-codex-ignores-agents-md) ).\n- **Cursor:** use the Allowlist run mode, so only the commands you list run without approval. Cursor's docs call the allowlist best-effort, not a security boundary. The Cursor CLI also takes deny rules.\n\nThe catch: these are set per tool and per machine. With a mixed team, the lists drift.\n\n## Layer 3: containment\n\nRun agents in a container, a disposable VM or a fresh clone. Keep backups. Containment limits damage when a rule is missed.\n\n## Where Harbor fits\n\nHarbor holds an agent to your rules at the moment it runs a command, and tells the agent what to do instead.\n\nExample: your team bans `prisma migrate reset` because it wipes every row. You turn on a guardrail for it and write the remedy on it: a migration made with `prisma migrate dev`. Harbor blocks the command and points the agent to the remedy. The banned command never runs.\n\nThat last part matters. A bare “denied” leaves the agent guessing, and it often retries a variant. A block that names the alternative gets the task done.\n\nYou also do not start the list from a blank page. Harbor suggests guardrails from what your team already wrote: a rule that names the command, a deny entry in a repo's `.claude/settings.json`, or a package script that runs it. A person turns each one on, and it reaches Claude Code, Codex, Cursor and GitHub Copilot on every teammate's machine ([guardrails](https://gethrbr.com/docs/guardrails)).\n\n## Caveats\n\n- Harbor does not replace server-side branch protection or sandboxes. Keep both for the worst case. Harbor's hook fails open: if it errors, the call runs.\n- Check your own setup by trying a banned command in a test repo before you rely on it. `harbor check \"git push --force\"` prints which guardrail stops a command and what the agent will read.\n\n## Try it\n\nRun `npx harborloop init`. It is free for you and one teammate, no card.\n\n## Questions\n\n### How do I stop an AI coding agent from running rm -rf or git push --force?\n\nUse layers. Turn on branch protection so force pushes to main fail on the server. Set each agent's own controls: deny rules and PreToolUse hooks in Claude Code, forbidden execution rules in Codex, the Allowlist run mode in Cursor. Run agents in a container, a disposable VM or a fresh clone. Harbor adds one guardrail that refuses the command in Claude Code, Codex, Cursor and Copilot and tells the agent what to run instead.\n\n### Does Cursor have a deny list for terminal commands?\n\nNot in the IDE, by its current docs. The run modes are Auto-review, Allowlist and Run Everything, and the docs call the allowlist best-effort, not a security boundary. The Cursor CLI takes deny rules in its permissions config.\n\n### Why tell the agent what to run instead of only denying the command?\n\nA bare denial leaves the agent guessing, and it often retries a variant of the same command. A refusal that names the sanctioned route, such as a migration made with prisma migrate dev instead of prisma migrate reset, gets the task done.", "url": "https://wpnews.pro/news/how-to-block-ai-coding-agents-from-running-rm-rf-force-push-and-other-banned", "canonical_source": "https://gethrbr.com/blog/block-ai-coding-agents-banned-commands", "published_at": "2026-11-21 00:00:00+00:00", "updated_at": "2026-11-21 12:45:19.516572+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "ai-safety"], "entities": ["Harbor", "Claude Code", "Codex", "Cursor", "GitHub Copilot", "GitHub", "GitLab", "Prisma"], "also_reported_by": [], "takeaway": "Layer server-side branch protection, per-agent deny rules and hooks, and container containment, and pair each blocked command with a named sanctioned alternative, because a bare denial leads agents to retry variants.", "recommendation": {"advice": "Block destructive commands at the server, in each agent's settings and in a sandbox, and attach the sanctioned alternative to every denial so the agent does not retry a variant.", "playbook": "agent-security", "playbook_url": "https://wpnews.pro/playbooks/agent-security"}, "alternates": {"html": "https://wpnews.pro/news/how-to-block-ai-coding-agents-from-running-rm-rf-force-push-and-other-banned", "markdown": "https://wpnews.pro/news/how-to-block-ai-coding-agents-from-running-rm-rf-force-push-and-other-banned.md", "text": "https://wpnews.pro/news/how-to-block-ai-coding-agents-from-running-rm-rf-force-push-and-other-banned.txt", "jsonld": "https://wpnews.pro/news/how-to-block-ai-coding-agents-from-running-rm-rf-force-push-and-other-banned.jsonld"}}