`exec command rejected
Open 💬 18 comments Opened Oct 12, 2025 by josephrocca
💡 Likely answer: A maintainer (etraut-openai, contributor)
responded on this thread — see the highlighted reply below.
What version of Codex is running?
0.46.0
What steps can reproduce the bug?
Agent is trying to delete folders in /root like rm -rf /root/foo/bar but is blocked, despite adding --ask-for-approval never --sandbox danger-full-access. I've confirmed in the interactive /approvals menu that 'Full Access' is activated.
What is the expected behavior?
Agent should never be blocked when adding both --ask-for-approval never --sandbox danger-full-access. Unless there's a "higher" approval/sandbox level that I'm not aware of.
What do you see instead?
exec command rejected: dangerous command detected; rejected by user approval settings
18 Comments
I disagree, this is too dangerous, at least letting it do so without approval. I do keep these options on, since otherwise daily use is just very cumbersome, but I definitely want to disallow any dangerous actions like messing up git or randomly doing rm -rf. While I do keep everything containerized, so in general it's not a catastrophe if it does _rm -rf something_, that would still be annoying if it was the wrong folder and could potentially delete uncommited edits.
It's in the name:
--ask-for-approval never --sandbox danger-full-access.It sounds like you're asking for
--ask-for-approval sometimes(with a better name)Either way, I don't really care about the name, I just need some way to actually give it full access, with no need for approval. I don't think you disagree that this should be technically possible (without editing the Codex source code).
Yeah, it would be great to have both. I can see the use for absolutely no user interaction and no commands rejected, as long as there is a
--ask-for-approval sometimesavailable too.I agree.
codex --dangerously-bypass-approvals-and-sandboxshould just allow all commands - you've already been warned, if you're not using a sandbox like Docker it's your own problem.The way it's working now it only makes Codex work around it, just like in the example above ^. Pure waste of tokens.
Closing old bugs.
Closing? Why? The issue still persists. Three months later and Codex still wastes tokens on writing Python scripts to remove files.
This is absurd. And yes, it's being run with
--dangerously-bypass-approvals-and-sandbox.@xymb-endcrystalme, that's not the same issue described in this bug report. If you'd like to report a different issue, please open a new bug report.
How so? The only difference I see is that @josephrocca is using
--ask-for-approval never --sandbox danger-full-accessand I'm using--dangerously-bypass-approvals-and-sandboxwhich are supposed to do the same exact thing.In both cases agent is forbidden from executing the
rmcommand and seeks workarounds.How is it in any way a different issue?
OK, I see the similarity. I thought you were focusing on the fact that the agent was using a Python script, but I get what you're saying. I'll reopen the issue.
The block that is currently in place for certain dangerous forms of
rmis very much by design, so I don't think we'd consider this a bug. I understand the argument that no blocks should be in place in "yolo" mode. "Yolo" mode is intended for situations where there is some external sandbox in place (like a docker container or VM), but we find that many Codex users are reaching for "yolo" in cases where it really isn't safe. These blocks are in place as a protection.I think the real fix here is to continue to invest in improvements to our sandboxing and approval mechanisms so users don't feel the need to reach for "yolo" in most cases. We've made some good headway over the past couple of months with the introduction of the experimental sandbox on Windows, exec policy rules, and many other smaller improvements, but we still have more work to do.
My point was that the agent _succeeds_ in removing the file regardless of the "block". 😉 If an agent decides to wipe your home directory it will just do it with PowerShell/Bash/Python/etc. So the block in YOLO mode makes zero sense - it doesn't prevent anything in practice, it just wastes tool calls.
If someone runs an agent in YOLO mode and they don't sandbox it's their problem. Let's not treat people like children.
If someone has the same problem:
command_might_be_dangerous()inis_dangerous_command.rsto always returnfalsecodex-rsdocargo build --releasecodex-rs/target/release/codexI agree @xymb-endcrystalme, and this issue is especially annoying because it blocks all sorts of legitimate commands. I directly asked the agent to perform
git reset --hardbecause we went down a pointless path, and I didn't want to keep anything.This is under
--dangerously-bypass-approvals-and-sandbox.Later, it encountered an
rmblock and worked around it:So, the block _was_ pointless: it did not protect me from the ability of the agent to do what it wanted. (In this case, I'm happy the agent found a workaround... that
rmblock was not appropriate.)Yep, the string matcher literally only looks for
git rm,git resetandrm -f. Extremely half-assed filter.Maybe the solution is to tell GPT to use
unlinkinstead? 🤣This change is causing interruption to autonomous agent flows where the agent is already isolated in a container for the purpose of allowing it to run all commands with
--dangerously-bypass-approvals-and-sandbox. The agent will try to run a command, be denied, and stop working.Commit that introduced the “blocked by policy” behavior for dangerous commands under
AskForApproval::Never:This commit added
render_decision_for_unmatched_command()incodex-rs/core/src/exec_policy.rsand changedexecpolicyto:--dangerously-bypass-approvals-and-sandbox(since it sets approval policy to Never), socommands like
rm -rf /tmp/foonow get “blocked by policy.”I encountered the same problem in the --yolo environment. Are there any solutions?
---
The work is going well.
ok so there are many problems with this and plenty discussed, entertaining or with tears.
The main problem this causes is litter. you can create a tmp file (not even /tmp like a gitignore directory like build), but you cannot clean it up even in yolo mode. for example you can nohup a command and no ability to clean up the corresponding log file you used without trickery.
and the agent will use trickery and we know it does. unlink, running python etc.
this makes codex unable to do runbooks or verify developer instructions that include rm even if it is housed to a project. even though it can and will succeed, it is cleverly altering instructions rather than executing what it is told.
a combination of policies like this makes it seem this is targeted as a non-developer product. basically if you have to compile your own agent, or resort to tokens lost on workarounds, in order to delete your temporary files.. 🤷 should the branding of this agent change?
#10258 made things worse by adding more perfectly valid commands to the list.
Saying “this is not a bug” because it is “by design” is simply hiding behind words. Bug in design still is a bug. Breaking changes are breaking changes.
People who do not need yolo do run yolo because the alternative is to babysit codex in the sandbox. But breaking yolo is not a solution either.
Fixing this whole yolo vs babysitting situation some day in the future would be great. But while we are waiting, please at least add an option to turn this blacklist of commands off.
Nvm, add this to ``
~/.codex/rules/default.rules``:This effectively is a setting I was looking for. You can whitelist rm in the same way.
Not that bad for a workaround.