Codex CLI approval modes versus sandbox modes: safe combinations for autonomous runs

Codex Published:

What Codex CLI's approval policy and sandbox mode each control, what --full-auto really does, how to pin them in config.toml, and which pair fits research, daily work and CI.

Verified on Sep 7, 2026 These tools change quickly. Please also check the latest official documentation.
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. 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.