Codex approval_policy vs sandbox_mode: which pairs are safe (on-request + workspace-write, never + read-only)
What approval_policy and sandbox_mode each control in Codex CLI, what --full-auto really sets, and which combination to pin in config.toml for research, daily work and CI.
Contents
Codex CLI's safety comes from two independent settings: the approval policy and the sandbox. Mixing them up leads to confusion such as "I turned off prompts but the command still fails" or "it asked me, yet the file was already changed".
This article explains each option, what happens when they combine, and which pair to use for which job.
KEY POINT
What you will learn
- The distinct roles of approvals and the sandbox
- Every option, and what
--full-autoexpands to - Recommended settings for research, daily development and CI, and how to pin them in config.toml
Two settings, two jobs
| Setting | Decides | Enforced by |
|---|---|---|
| approval | Whether to ask you before an action | Codex's conversation flow |
| sandbox | What a running command may do at the OS level | OS mechanisms: Seatbelt on macOS, Landlock/seccomp on Linux |
Approval is "do we ask"; sandbox is "is it possible". Skip every prompt and a read-only sandbox still prevents writes. Open the sandbox completely and per-action prompts still let you stop things.
Approval policies
Set with --ask-for-approval (short -a) or approval_policy in config.toml.
| Value | Meaning |
|---|---|
untrusted | Prompt for everything except commands judged safe and read-only. Most conservative |
on-request | Prompt only when Codex decides it needs to (close to the default) |
on-failure | Run inside the sandbox; ask only when a command fails, whether to retry outside the sandbox |
never | Never prompt; carry on even after failures. For CI |
用語解説
Retrying outside the sandbox: With on-failure, when a command fails because of sandbox limits (no network, for example), Codex asks whether to rerun it without those limits. npm install failing on network access is the typical case.
Sandbox modes
Set with --sandbox or sandbox_mode in config.toml.
| Value | Read files | Write files | Network |
|---|---|---|---|
read-only | Yes | No | No |
workspace-write | Yes | Only inside the workspace (current directory) and temp dirs | Off by default (configurable) |
danger-full-access | Yes | Anywhere | Yes |
Even in workspace-write, direct writes to .git may be restricted. Git operations run as normal commands, so this rarely matters.
What --full-auto expands to
--full-auto is shorthand for workspace-write plus reduced prompting. Writes outside the workspace and network access remain blocked, so think of it as "do what you like inside the workspace".
codex --full-auto "Refactor until the tests pass"
danger-full-access belongs in isolated environments only
--sandbox danger-full-access with -a never runs anything without asking. Use it only in disposable containers or CI runners, never on your host machine. The same applies to --dangerously-bypass-approvals-and-sandbox.
Recommended combinations
| Job | approval | sandbox | Notes |
|---|---|---|---|
| Exploring or asking about code | on-request | read-only | Nothing can be changed by accident |
| Daily development | on-request | workspace-write | Close to the defaults; side effects get confirmed |
| Long autonomous tasks (local) | on-failure | workspace-write | You decide only on failures |
| CI or containers | never | workspace-write or danger-full-access | Assumes a throwaway environment |
Pinning them in config.toml
approval_policy = "on-request"
sandbox_mode = "workspace-write"
[sandbox_workspace_write]
# set to true when npm install and similar need the network
network_access = false
Profiles let you switch per task with --profile:
[profiles.readonly]
approval_policy = "on-request"
sandbox_mode = "read-only"
[profiles.auto]
approval_policy = "on-failure"
sandbox_mode = "workspace-write"
codex --profile readonly "Find every caller of this function"
codex --profile auto "Fix all the lint errors"
Profiles are covered in depth in Switching models and profiles in Codex's config.toml.
Switching mid-session
The /approvals command changes the approval mode during a session, handy when a research session turns into implementation.
How this compares with Claude Code
Claude Code has no OS-level sandbox; it uses per-tool rules (allow / deny / ask). Both aim to stop dangerous commands, but Codex enforces limits physically through the OS while Claude Code controls them through rules.
Summary
- Approval is "do we ask"; sandbox is "what can the OS allow". They are independent
- Daily work:
on-request+workspace-write; research:read-only; CI:never --full-autoisworkspace-writewith fewer prompts; outside writes and network stay blockeddanger-full-accesswithneveris for isolated environments only
FAQ
- What is the difference between approval and sandbox?
- Approval decides whether to ask you before acting. The sandbox decides what the OS lets the command do. With approval set to never but a read-only sandbox, files still cannot be changed.
- Is --full-auto dangerous?
- --full-auto allows writes inside the workspace and reduces prompts, but the sandbox still blocks writes outside the workspace and network access, so it is far safer than danger-full-access.
- Can commands use the network inside the sandbox?
- Not by default in workspace-write. Enable it with sandbox_workspace_write.network_access in config.toml.
Questions & answers
Q. Codex stops with "approval required by policy, but AskForApproval::Granular.sandbox_approval is false". The UI is set to "Ask for approval" and my config.toml has no approval_policy. What do I set?
That error text means a granular approval policy is in effect, whatever the UI shows. approval_policy takes one of three forms — on-request, never, or { granular = { ... } } — and the granular form decides, per category of prompt, whether it surfaces or is auto-rejected. The configuration reference documents five fields:
| Field | What true means |
|---|---|
sandbox_approval | Sandbox escalation approval prompts are allowed to surface |
rules | Approvals triggered by execpolicy prompt rules are allowed to surface |
mcp_elicitations | MCP elicitation prompts surface instead of being auto-rejected |
request_permissions | Prompts from the request_permissions tool are allowed to surface |
skill_approval | Skill-script approval prompts are allowed to surface |
With sandbox_approval set to false, a sandbox escalation approval is rejected without prompting you — which is exactly what the error states. To get the prompt instead, put one of these in ~/.codex/config.toml:
# Surface every approval prompt (the documented choice for interactive runs)
approval_policy = "on-request"
# Pick which categories surface
[approval_policy.granular]
sandbox_approval = true
rules = true
mcp_elicitations = true
request_permissions = true
skill_approval = true
The docs also note that untrusted is unsupported and on-failure is deprecated, and to use on-request for interactive runs.
If your own config.toml sets no approval_policy and you still see this, the value is arriving from somewhere else. The reference documents managed requirements, where an administrator sets "Allowed approval policies" in the Agent Security UI — an admin control, not a user setting. One more related key is approvals_reviewer, which decides "who reviews eligible approval prompts under on-request or granular approval policies" and defaults to user; it does not change sandboxing or actions already allowed inside the sandbox.
注意
How the desktop app's "Ask for approval" setting maps onto these approval_policy keys could not be confirmed in the official documentation. When the UI and the policy actually in force disagree, writing the value explicitly in config.toml is the reliable route.
More detail: Codex approval policy and sandbox settings.
Q. Codex says "requires approval, but approval policy is never" and won't run the task. What do I change?
The message describes a deadlock: the action needs approval, but your approval policy is never, so there is no one to ask. With no way to prompt, it is rejected.
As of October 6, 2026, the configuration reference lists three forms for approval_policy:
| Value | Behavior |
|---|---|
on-request | For interactive runs. Prompts when approval is needed |
never | For non-interactive runs. Never prompts |
{ granular = { ... } } | Decides per category of prompt whether it surfaces or is auto-rejected |
The documentation puts it plainly:
untrustedis unsupported, andon-failureis deprecated; useon-requestfor interactive runs orneverfor non-interactive runs.
If you are sitting at the keyboard driving it, on-request is the intended value, not never:
approval_policy = "on-request"
To surface only some prompts, use granular. Categories set to true surface; categories set to false are auto-rejected.
[approval_policy.granular]
sandbox_approval = true # sandbox escalation prompts
rules = true # prompts from execpolicy rules
mcp_elicitations = true # MCP elicitations
request_permissions = true # prompts from the request_permissions tool
skill_approval = true # skill-script approval prompts
If what's failing is an action against an external service, mcp_elicitations is the relevant one: under never, an MCP server's request for confirmation is auto-rejected, so anything that needs a sign-in or a grant can't proceed.
注意
A category set to false under granular does not mean "runs without asking" — it means auto-rejected. To actually restrict what runs, narrow sandbox_mode and the permissions instead of the approval policy.
One caveat about the report this came from: it describes the same action succeeding on the web and failing in the desktop app, and it carries a bug label. Why the effective approval policy differs between platforms could not be confirmed in the official documentation. If fixing the setting doesn't resolve it, follow that report.
For how approval policies and the sandbox combine, see Codex approval modes and sandbox.
Q. npm install fails inside Codex. Is the sandbox blocking it?
Yes. The workspace-write sandbox blocks network access by default, so package downloads fail. With the on-failure approval policy Codex asks whether to rerun the command outside the sandbox; approve it and the install goes through. To stop being asked, allow the network in ~/.codex/config.toml:
sandbox_mode = "workspace-write"
[sandbox_workspace_write]
network_access = true
Allowing the network also allows data to leave the machine, so enable it only for repositories you trust. Research-only sessions can stay in read-only.
Primary sources
This article was drafted by AI from official documentation and reviewed by the site operator before publishing. Found a mistake? Let us know via the contact page.