Codex approval_policy vs sandbox_mode: which pairs are safe (on-request + workspace-write, never + read-only)

Codex Published: Updated:

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.

Verified on Sep 22, 2026 These tools change quickly. Please also check the latest official documentation. How articles are researched and verified
Contents
  1. Two settings, two jobs
  2. Approval policies
  3. Sandbox modes
  4. What --full-auto expands to
  5. Recommended combinations
  6. Pinning them in config.toml
  7. Switching mid-session
  8. How this compares with Claude Code
  9. Summary

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-auto expands to
  • Recommended settings for research, daily development and CI, and how to pin them in config.toml

Two settings, two jobs

SettingDecidesEnforced by
approvalWhether to ask you before an actionCodex's conversation flow
sandboxWhat a running command may do at the OS levelOS 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.

ValueMeaning
untrustedPrompt for everything except commands judged safe and read-only. Most conservative
on-requestPrompt only when Codex decides it needs to (close to the default)
on-failureRun inside the sandbox; ask only when a command fails, whether to retry outside the sandbox
neverNever 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.

ValueRead filesWrite filesNetwork
read-onlyYesNoNo
workspace-writeYesOnly inside the workspace (current directory) and temp dirsOff by default (configurable)
danger-full-accessYesAnywhereYes

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.

JobapprovalsandboxNotes
Exploring or asking about codeon-requestread-onlyNothing can be changed by accident
Daily developmenton-requestworkspace-writeClose to the defaults; side effects get confirmed
Long autonomous tasks (local)on-failureworkspace-writeYou decide only on failures
CI or containersneverworkspace-write or danger-full-accessAssumes 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-auto is workspace-write with fewer prompts; outside writes and network stay blocked
  • danger-full-access with never is 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?

Answer by the editorsSource: GitHub openai/codex Issue #51509

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:

FieldWhat true means
sandbox_approvalSandbox escalation approval prompts are allowed to surface
rulesApprovals triggered by execpolicy prompt rules are allowed to surface
mcp_elicitationsMCP elicitation prompts surface instead of being auto-rejected
request_permissionsPrompts from the request_permissions tool are allowed to surface
skill_approvalSkill-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?

Answer by the editorsSource: GitHub openai/codex Issue #51161

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:

ValueBehavior
on-requestFor interactive runs. Prompts when approval is needed
neverFor non-interactive runs. Never prompts
{ granular = { ... } }Decides per category of prompt whether it surfaces or is auto-rejected

The documentation puts it plainly:

untrusted is unsupported, and on-failure is deprecated; use on-request for interactive runs or never for 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?

Answer by the editorsFrequently searched question

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.