How do you stop a coding agent from deleting files or running risky commands?
To stop a coding agent from deleting files or running risky commands, layer four controls: approval prompts before shell commands, deny rules for destructive ones, an operating system sandbox that limits where commands can write and connect, and a clean git commit before each session. Rules in AGENTS.md help, but the tools treat them as advice, not enforcement.
Cite
CodeLifter Forum, "How do you stop a coding agent from deleting files or running risky commands?", https://codelifter.com/forum/posts/how-do-you-stop-a-coding-agent-from-deleting-files-or-running-risky/, accessed 2026-11-20.- CodeLifter editorsStaffStaff, CodeLifter ·
Why can a coding agent delete files at all?
A coding agent is an AI assistant that can run tools on your machine: read and edit files, and run shell commands. A shell command runs with your user account's rights, so
rm -rf build/andrm -rf ~/are the same kind of action to the operating system. The model decides what to run; the agent's harness (the program around the model) decides whether it may.That distinction matters. Anthropic's Claude Code permissions page says: "Permission rules are enforced by Claude Code, not by the model. Instructions in your prompt or
CLAUDE.mdshape what Claude tries to do, but they don't change what Claude Code allows." Its security page adds that the working directory boundary "is a permission prompt, so a Bash command you approve can still write anywhere your user account can."Which controls stop what?
Control What it stops Where it falls short Approval prompts Any command you have not approved Prompt fatigue: after many approvals you stop reading Deny rules, such as Bash(rm *)Commands that match the pattern as written /bin/rm,sh -c "rm ..."orfind . -deletemay not matchOS sandbox Writes outside the project and network access, whatever the command Covers shell commands only, not every tool Container or virtual machine Everything outside the container Setup work; secrets inside it are still exposed Git commit before the session Permanent loss of tracked files Untracked and ignored files, such as .envNo single row is enough. The Claude Code permissions page says Bash patterns "that try to constrain command arguments are fragile" and recommends the sandbox "when the restriction must hold". It also describes the two as layers: "sandbox restrictions still apply even if a prompt injection bypasses Claude's decision-making."
How do you lock down Claude Code?
As of the docs read on 16 October 2026:
- Pick the mode deliberately. Claude Code's best practices page says that from v2.1.283, auto mode is the starting mode for interactive sessions, with "a separate classifier model" reviewing actions instead of you. Manual mode (
default) asks before edits and shell commands. SetdefaultModein your settings file, or switch withShift+Tab. Be careful withacceptEdits: the security page listsrmamong the filesystem commands it auto-approves for paths in the working directory. - Add deny rules in
.claude/settings.jsonat the project root, so they apply to everyone who clones it:
Deny rules are checked first ("deny, then ask, then allow"), and "An allow rule can't carve an exception out of a deny rule."{ "permissions": { "deny": [ "Bash(rm *)", "Bash(git push *)", "Read(./.env)" ], "disableBypassPermissionsMode": "disable" }, "sandbox": { "enabled": true } }disableBypassPermissionsModestops anyone starting the session in the mode that skips prompts. - Turn on the sandbox with
/sandbox, orsandbox.enabledas above. The sandboxing page says it is off by default, limits writes to "the working directory, a per-user temp directory, and directories you've added", and sends network connections through a proxy that checks each host against your allowed domains, which "start empty". It runs on macOS, Linux and WSL2; on native Windows commands run unsandboxed. - Commit before you start, so
git statusshows exactly what changed. The best practices page warns that its checkpoints "only track changes made through Claude's file editing tools. Changes made through Bash commands or external processes are not captured. This isn't a replacement for git."
If you have not installed it yet, the Claude Code setup thread covers where settings files live.
How do you lock down Codex?
OpenAI's Codex approvals and security page (read 16 October 2026) combines a sandbox mode with an approval policy:
codex --sandbox read-only --ask-for-approval on-requestlets it read and plan; anything else needs approval.codex --sandbox workspace-write --ask-for-approval on-requestis theAutopreset: it can edit and run commands in the working directory, and "asks for approval to edit files outside the workspace or to run commands that require network access."- In
workspace-write,.git,.codex,.agentsand.awsinside the workspace stay read-only, so the agent cannot rewrite your history. --sandbox danger-full-accessand--dangerously-bypass-approvals-and-sandboxremove the limits. The page says "Use caution before doing so."
The same settings go in
~/.codex/config.tomlassandbox_modeandapproval_policy. How the agents compare more broadly is in the coding agents thread.What about MCP servers and rules files?
The Claude Code sandbox page lists what runs outside it: built-in file and web tools, hooks and local MCP servers "run with your full access". An MCP server with a delete tool needs its own limits; the Filesystem server sandbox thread shows how for one server.
Rules files are still worth a line or two ("Never run
rm -rf; ask before deleting any file"), because they reduce how often the agent tries. Treat them as the first layer, not the lock. CodeLifter's agents directory lists each agent's rules file, MCP support and licence, with links to its own docs, which is where its permission settings live.Short version
- The model proposes; the harness enforces. Prompts and
AGENTS.mddo not enforce anything. - Use approval prompts plus deny rules, and turn on the OS sandbox so the limit holds for any command.
- In Codex, stay on
workspace-writewithon-requestapprovals; avoiddanger-full-accessoutside a container. - Commit first: checkpoints miss shell changes, and git is your undo.
- Pick the mode deliberately. Claude Code's best practices page says that from v2.1.283, auto mode is the starting mode for interactive sessions, with "a separate classifier model" reviewing actions instead of you. Manual mode (
Write something first.
Give people something to work with: at least 30 words on what happened and what you tried.
That is too long. Keep it under 6,000 characters.
Write the question as the title, 15 to 140 characters, no links.
Pick a category.
Add a name (2 to 40 characters, no links).
That email address does not look right.
That was quick. Read the thread, then try again.
The form expired. Reload the page and post again.
Something went wrong with the form. Reload and try again.
Please complete the check and post again.
Limit reached for now. Try again later.
This thread is closed to new replies.
This thread no longer accepts replies.
Something went wrong with the form. Reload and try again.
Post a reply or question first (name and email), then this browser can vote, edit and accept answers.
You cannot vote on your own post.
Only the author (within 30 days) or the forum team can do that.
That email already has an account. Use your sign-in link instead.
New accounts are paused for the moment. Try again later.
That was already posted.