You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Rules: Extend it to configure sandbox_policy #12283
I want some commands to always run outside codex sandbox since inside the sandbox, they sometimes fail. If we can extend the rules to be able to configure that part, it would be great.
Currently, one way to work around is to use some other shell MCP server, but using that for just one CLI and not others seem like an overkill.
Additional information
bazel is an example tool that starts server and many a times, it fails in sandbox with failed to bind to socket or failing to write to /var/tmp directory (I guess this would be another type of issue).
Reacted by Daniel.L (Byoungchan) Lee and sky jiang
You should be able to do this with the existing rules engine. Specify "allow" for the decision field. This tells the engine to run the command outside of the sandbox. For details, refer to this documentation.
Oh, that's interesting! Thanks @etraut-openai, we already had configured allow for some of the bazel commands and they would still occasionally fail. I will investigate more on our side.
Does running outside sandbox would also give bazel by default access to write to /var/tmp?
prefix_rule(
pattern = ["bazel", ["build", "test", "query"]],
decision = "allow",
justification = "Common build/test/query commands can run without a prompt.",
)
codex failed with:
Blocked on Bazel sandbox permissions before query/build could run.
Error:
FATAL: Output base directory '/var/tmp/_bazel_<user>/48efaac00c301a60ea8698353cd83f7d' must be readable and writable.
Please restart Codex with:
--add-dir=/var/tmp
Is there anything that I can share, so it can be reproed on your side?
To add I think sometimes codex chose to run commands that are composed (or extra SHELL script constructs) and not just direct bazel build. In that case, maybe it will run the full command in sandbox and run into this issue?
Since we have rules configured, a subset of bazel command runs outside sandbox. This means many-a-times, it will just work without any issues.
As soon as codex try running small shell snippets invloving bazel, codex would treat them as bash scripts and run them inside sandbox where it won't be able to discover bazel server running outside the sandbox.
It will prompt you to run that command in the elevated mode, so it can start an instance of bazel server inside sandbox or it will try to skip the sandbox.
As I continue with the session, sometimes I think the sandbox gets recreated and it needs to start bazel server again. I don't know yet why this might occur unless bazel is getting switched on/off sandbox.
Since I see codex is itself trying to migrate to bazel's build system, are you running into the issue? I can run codex with --sandbox=danger-full-access, but that would disable sandbox for all the tools and not just bazel. Is there no way to selectively disable sandboxing or allow network just for bazel in sandbox whenever it is invoked from any script?
No, there's unfortunately no way to selectively run bazel in a sandbox when it's invoked from an arbitrary script. The script is either running in the sandbox or it's not.
I did consider that, but IIUC bazel MCP server will only be used for native bazel commands and if there is a little involved shell snippet, it would still run outside sandbox. If I use some shell MCP directly, that would basically be same as sandbox_mode = danger-full-access.
Also, MCP output might end up polluting the context, which running CLIs natively might help avoid.
I think that subagents work under the same sandbox settings as the parent agent.
In the doc, it was suggesting that sandbox_mode can be overridden to read-only, so I was assuming you can give full access to one of the subagent too. Maybe not.
Thanks, Eric! Appreciate the discussion with me to find solution to this issue 😄. I will update this thread if I find some solution to my problem and will also be tracking the release notes.
Activity
github-actions commentedon Feb 20, 2026
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
.git/gitdir#12280Powered by Codex Action
etraut-openai commentedon Feb 20, 2026
You should be able to do this with the existing rules engine. Specify "allow" for the decision field. This tells the engine to run the command outside of the sandbox. For details, refer to this documentation.
amit-mittal commentedon Feb 20, 2026
Oh, that's interesting! Thanks @etraut-openai, we already had configured
allowfor some of thebazelcommands and they would still occasionally fail. I will investigate more on our side.Does running outside sandbox would also give
bazelby default access to write to/var/tmp?etraut-openai commentedon Feb 20, 2026
When you run outside the sandbox, your normal user permission checks should apply, so yes, it should have access to
/var/tmp.amit-mittal commentedon Feb 20, 2026
Even though I have below rules:
codexfailed with:Is there anything that I can share, so it can be reproed on your side?
amit-mittal commentedon Feb 20, 2026
To add I think sometimes codex chose to run commands that are composed (or extra SHELL script constructs) and not just direct
bazel build. In that case, maybe it will run the full command in sandbox and run into this issue?etraut-openai commentedon Feb 20, 2026
If you want to do some additional diagnosis, you could clone the codex repo and ask codex to diagnose the issue.
amit-mittal commentedon Feb 21, 2026
@etraut-openai I think I know what's happening now:
rulesconfigured, a subset ofbazelcommand runs outside sandbox. This means many-a-times, it will just work without any issues.codextry running small shell snippets invlovingbazel, codex would treat them as bash scripts and run them inside sandbox where it won't be able to discoverbazelserver running outside the sandbox.bazelserver insidesandboxor it will try to skip the sandbox.bazelserver again. I don't know yet why this might occur unlessbazelis getting switched on/off sandbox.Since I see
codexis itself trying to migrate tobazel's build system, are you running into the issue? I can runcodexwith--sandbox=danger-full-access, but that would disable sandbox for all the tools and not justbazel. Is there no way to selectively disable sandboxing or allow network just forbazelin sandbox whenever it is invoked from any script?etraut-openai commentedon Feb 21, 2026
Yeah, your diagnosis sounds quite plausible.
No, there's unfortunately no way to selectively run
bazelin a sandbox when it's invoked from an arbitrary script. The script is either running in the sandbox or it's not.amit-mittal commentedon Feb 21, 2026
Is there a way to use new multi-agent workflow to have a subagent just do
bazeloperations outside sandbox?etraut-openai commentedon Feb 21, 2026
I think that subagents work under the same sandbox settings as the parent agent.
Here's an idea... you could encapsulate it as an MCP server. MCP servers run outside of the sandbox.
amit-mittal commentedon Feb 21, 2026
I did consider that, but IIUC
bazelMCP server will only be used for nativebazelcommands and if there is a little involved shell snippet, it would still run outside sandbox. If I use some shell MCP directly, that would basically be same assandbox_mode = danger-full-access.Also, MCP output might end up polluting the context, which running CLIs natively might help avoid.
In the doc, it was suggesting that sandbox_mode can be overridden to read-only, so I was assuming you can give full access to one of the subagent too. Maybe not.
etraut-openai commentedon Feb 21, 2026
That feature is still evolving, and I haven't been watching it that closely this past week. You may be right.
amit-mittal commentedon Feb 21, 2026
Thanks, Eric! Appreciate the discussion with me to find solution to this issue 😄. I will update this thread if I find some solution to my problem and will also be tracking the release notes.