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
Support per-command sandbox exclusion rule without bypass permission or review #20917
I would like Codex to support a per-command sandbox exclusion mechanism, similar to Claude Code's sandbox.exclude configuration field.
The desired behavior is that when the original command requested by the agent matches a configured pattern, Codex automatically runs that command outside the sandbox, even if the agent requested a normal sandboxed execution.
This is not the same as the existing exec policy allow decision. An exclusion rule should only decide sandbox placement. It must not grant permission, bypass review, or override any existing approval, deny, or prompt policy. If a matching command would otherwise require approval, it should still require approval. If another rule forbids it, it should still be forbidden.
In other words, this feature should separate "where the command runs" from "whether the command is allowed to run."
Use case: tools such as gh need access to normal user auth state, for example ~/.config/gh/hosts.yml, which may intentionally not be exposed inside the sandbox. I want gh to run outside the sandbox so it can access its normal credentials, but I do not want to allow gh automatically or remove the approval prompt. This is specifically about forcing the matching command out of the sandbox while preserving the existing permission and review model.
Additional information
No response
Reacted by Hudeyn23, sky jiang, Jon Parker, Travis Mortimer, Dan Lilienblum, fxmarty-amd, yasushi abe, Philipp Faster-Malkov and Cologler
I am already aware of the existing rules feature. As I understand it, rules control whether a tool call should be allowed, prompted/reviewed, or rejected. My request is about a separate dimension: where the command runs.
I also re-checked this behavior with Codex. A command matched by a prompt rule does not automatically run outside the sandbox after the auto review approves it. This is different from commands matched by allow, which can bypass the prompt and also behave as escalated/unsandboxed. So the current behavior does not provide a way to say: “run this command outside the sandbox, but still preserve the prompt/review policy.”
The distinction I want is:
Command A should always run outside the sandbox, regardless of whether the agent explicitly requested escalation, but each invocation should still follow the existing prompt/review policy.
Command B should be allowed without prompting, but only when it runs inside the sandbox.
With the current behavior, these two controls appear to be coupled. I can effectively “allow both” or “deny both”, but I cannot independently control sandbox placement and permission/review behavior.
This is also why I mentioned Claude Code’s sandbox exclusion setting in the issue body. In Claude Code, the sandbox exclusion mechanism is a sandbox setting, separate from the permission rules. That is the model I think Codex should learn from: sandbox policy decides where a command runs, and permission policy decides whether it may run without review, must be reviewed, or should be rejected.
Concretely, I am requesting a separate sandbox-placement rule, for example:
sandbox_exclude = [
["gh"],
["xcodebuild"],
]
or something integrated into the existing rule system:
The important part is that sandbox = "outside" should not imply allow, and allow should not imply sandbox = "outside".
I would also suggest changing the semantics of allow so that it only means “bypass the prompt/review,” while still keeping the command inside the sandbox unless the agent explicitly requests escalation or the user has configured a separate sandbox exclusion rule. If a user wants both behaviors — no prompt and always outside the sandbox — they should configure both allow and a sandbox exclusion rule.
Given this distinction, could you please reopen this issue? I do not think it is a duplicate of the existing rules feature. The existing rules feature controls permission/review decisions; this request is about independently controlling sandbox placement.
I’m running into this too, and having this separation would be very useful.
In my case, there are commands that do not work correctly inside the sandbox because they need access to normal host state, sockets, credentials, or daemon-managed resources. I still want Codex to ask me before running them, but once approved I want them to run outside the sandbox automatically.
Right now I can add a prompt rule, but that only controls approval; it doesn’t seem to control where the command runs. And using allow is not what I want, because I don’t want to skip the approval step.
So the distinction proposed here feels exactly right to me: one policy dimension for whether a command is allowed/prompted/forbidden, and another for whether it should run inside or outside the sandbox.
In my environment, Codex has repeatedly done the following:
pnpm installs: Runs inside the sandbox, encounters blocked registry access or package-store problems, then concludes that the pnpm/Node version is wrong or the network is broken. It may try switching versions or finding another network path.
SSH: Encounters sandbox-denied networking, then assumes the host or VPN route is unavailable. It may look for workarounds, suggest switching the VPN, or give up.
Next.js Turbopack builds: Turbopack fails under the sandbox, so Codex treats it as a build-system problem and tries switching to the legacy Webpack builder.
git add / git commit: In registered worktrees, these repeatedly fail to create .git/index.lock or other Git metadata. Codex wastes a tool round-trip reporting the expected sandbox failure before retrying outside it.
curl and other network checks: Sandbox-blocked access is interpreted as the endpoint or service being unavailable.
Local PostgreSQL restore/rehearsal: Sandbox-denied localhost access is interpreted as PostgreSQL being down. In one case, Codex started planning replacement local PostgreSQL infrastructure for a service that was already healthy.
Local development servers: Port binding fails with EPERM. Codex usually recognizes this case and retries outside the sandbox, but only after wasting the first attempt.
tsx tooling: IPC creation fails with EPERM.
Authenticated CLIs such as op and gh: Sandbox restrictions prevent access to desktop integration, credentials, or network resources. Codex then reports that the user appears logged out and asks them to authenticate again, even though the same CLI works normally outside the sandbox.
This is more than an inconvenience. Ambiguous sandbox failures make the model reason from false evidence. That produces slower execution, wasted tokens and tool calls, incorrect diagnoses, and sometimes unnecessary environment mutations that carry more risk than the original command.
AGENTS.md instructions help but are not enforcement: the model can still forget to request escalation. Existing prefix_rule decisions control what happens after Codex requests outside-sandbox execution; they do not guarantee that a matching command skips the initial sandbox attempt.
For some of these commands, I have created AGENTS.md rules, skills, and command-specific guidance explaining when and how Codex should request outside-sandbox execution. These workarounds add maintenance burden, consume context and tokens on every relevant task, and remain dependent on the model remembering and correctly applying natural-language instructions.
This behavior should not require prompt engineering or a separate skill for every affected command. Execution placement can be determined mechanically from the command prefix, making it deterministic, testable with codex execpolicy check, and independent of model reasoning.
What is needed is a declarative rule meaning:
For this command prefix, never attempt execution in the sandbox. Route the first attempt directly through the configured approval/reviewer policy, then execute it outside the sandbox if approved.
Activity
etraut-openai commentedon May 3, 2026
Codex already supports this feature! See this documentation details.
skyfackr commentedon May 4, 2026
@etraut-openai Thanks for the quick response.
I am already aware of the existing rules feature. As I understand it, rules control whether a tool call should be allowed, prompted/reviewed, or rejected. My request is about a separate dimension: where the command runs.
I also re-checked this behavior with Codex. A command matched by a
promptrule does not automatically run outside the sandbox after the auto review approves it. This is different from commands matched byallow, which can bypass the prompt and also behave as escalated/unsandboxed. So the current behavior does not provide a way to say: “run this command outside the sandbox, but still preserve the prompt/review policy.”The distinction I want is:
With the current behavior, these two controls appear to be coupled. I can effectively “allow both” or “deny both”, but I cannot independently control sandbox placement and permission/review behavior.
This is also why I mentioned Claude Code’s sandbox exclusion setting in the issue body. In Claude Code, the sandbox exclusion mechanism is a sandbox setting, separate from the permission rules. That is the model I think Codex should learn from: sandbox policy decides where a command runs, and permission policy decides whether it may run without review, must be reviewed, or should be rejected.
Concretely, I am requesting a separate sandbox-placement rule, for example:
or something integrated into the existing rule system:
The important part is that
sandbox = "outside"should not implyallow, andallowshould not implysandbox = "outside".I would also suggest changing the semantics of
allowso that it only means “bypass the prompt/review,” while still keeping the command inside the sandbox unless the agent explicitly requests escalation or the user has configured a separate sandbox exclusion rule. If a user wants both behaviors — no prompt and always outside the sandbox — they should configure bothallowand a sandbox exclusion rule.Given this distinction, could you please reopen this issue? I do not think it is a duplicate of the existing rules feature. The existing rules feature controls permission/review decisions; this request is about independently controlling sandbox placement.
axelcursive commentedon May 18, 2026
I’m running into this too, and having this separation would be very useful.
In my case, there are commands that do not work correctly inside the sandbox because they need access to normal host state, sockets, credentials, or daemon-managed resources. I still want Codex to ask me before running them, but once approved I want them to run outside the sandbox automatically.
Right now I can add a
promptrule, but that only controls approval; it doesn’t seem to control where the command runs. And usingallowis not what I want, because I don’t want to skip the approval step.So the distinction proposed here feels exactly right to me: one policy dimension for whether a command is allowed/prompted/forbidden, and another for whether it should run inside or outside the sandbox.
maybephilipp commentedon Aug 29, 2026
Exactly—this is the missing piece.
In my environment, Codex has repeatedly done the following:
pnpminstalls: Runs inside the sandbox, encounters blocked registry access or package-store problems, then concludes that the pnpm/Node version is wrong or the network is broken. It may try switching versions or finding another network path.git add/git commit: In registered worktrees, these repeatedly fail to create.git/index.lockor other Git metadata. Codex wastes a tool round-trip reporting the expected sandbox failure before retrying outside it.curland other network checks: Sandbox-blocked access is interpreted as the endpoint or service being unavailable.EPERM. Codex usually recognizes this case and retries outside the sandbox, but only after wasting the first attempt.tsxtooling: IPC creation fails withEPERM.opandgh: Sandbox restrictions prevent access to desktop integration, credentials, or network resources. Codex then reports that the user appears logged out and asks them to authenticate again, even though the same CLI works normally outside the sandbox.This is more than an inconvenience. Ambiguous sandbox failures make the model reason from false evidence. That produces slower execution, wasted tokens and tool calls, incorrect diagnoses, and sometimes unnecessary environment mutations that carry more risk than the original command.
AGENTS.mdinstructions help but are not enforcement: the model can still forget to request escalation. Existingprefix_ruledecisions control what happens after Codex requests outside-sandbox execution; they do not guarantee that a matching command skips the initial sandbox attempt.For some of these commands, I have created
AGENTS.mdrules, skills, and command-specific guidance explaining when and how Codex should request outside-sandbox execution. These workarounds add maintenance burden, consume context and tokens on every relevant task, and remain dependent on the model remembering and correctly applying natural-language instructions.This behavior should not require prompt engineering or a separate skill for every affected command. Execution placement can be determined mechanically from the command prefix, making it deterministic, testable with
codex execpolicy check, and independent of model reasoning.What is needed is a declarative rule meaning:
Conceptually: