Codex CLI · As of 2026-11-25

Codex Sandbox and Approval Modes: read-only, workspace-write, on-request and never

As of 2026-11-25, Codex's safety model is two independent controls. The sandbox mode (sandbox_mode: read-only, workspace-write, danger-full-access) decides what the commands Codex runs can technically do. The approval policy (approval_policy: on-request, never, plus a fine-grained granular option) decides when Codex stops to ask you. The old untrusted policy is retired, and --full-auto, --suggest, --auto-edit and --approval-mode are gone from the current flag list. The short recommendation: workspace-write with on-request for local development, read-only with never for CI analysis, and when you truly need everything open, a disposable container or VM rather than --yolo on your host.

QCode is an independent third-party API service and is not affiliated with OpenAI. Mode names and semantics here were checked against OpenAI's Codex docs (Agent approvals & security, Sample Configuration and Permissions pages) on 2026-11-25.

Updated 2026-11-26

Key facts

  • Three sandboxes: read-only reads only; workspace-write reads, edits and runs commands in the working directory, asking before writing outside it or using the network; danger-full-access has no limits and is flagged as elevated risk.
  • Approval policies: on-request (default; commands the sandbox allows just run, and Codex asks when it needs to leave the sandbox), never (never prompts but still stays inside the sandbox), and granular (keeps chosen categories interactive and auto-rejects the rest). untrusted is no longer supported and can stop Codex from starting.
  • In workspace-write, network is off by default. Turn it on with [sandbox_workspace_write] network_access = true, or for a single run with -c.
  • Even in workspace-write, .git, .agents, .codex and .aws stay read-only as protected paths.
  • --dangerously-bypass-approvals-and-sandbox (alias --yolo) removes both sandbox and approvals; OpenAI says it's not recommended. Inside Docker or similar containers where the inner sandbox can't run, the docs suggest --sandbox danger-full-access within the container.
  • Codex runs in native Windows PowerShell with an MXC sandbox or the legacy elevated / unelevated fallbacks; WSL2 uses the Linux sandbox, and WSL1 has been unsupported since 0.115.

Two controls: the sandbox says "can", approvals say "ask"

People often blur the two. The sandbox is an OS-level restriction: macOS uses its built-in sandbox, Linux and WSL2 use bubblewrap and seccomp, and Windows uses MXC or a legacy fallback. Approvals are Codex's own interaction flow: when a command needs to go beyond the sandbox, does Codex ask you or simply refuse?

Sandbox modes

Mode Read Write Run commands Network Good for
read-only Yes No Yes, inside a read-only sandbox None by default Reviewing unfamiliar repos, CI analysis, summaries
workspace-write Yes Working directory and temp dirs Yes Off by default, configurable Everyday development
danger-full-access Yes Anywhere Yes Yes Disposable containers / VMs only

Approval policies

Policy Behaviour Good for
on-request Commands the sandbox allows run without asking; Codex asks to leave the sandbox, use network and similar Local interactive use (default)
never Never prompts; out-of-bounds actions fail, still inside the sandbox CI, scripts, read-only analysis
granular Keeps chosen categories interactive and auto-rejects the rest; the official sample lists the available categories Teams that need fine control
untrusted Retired Move to on-request + read-only, or a project trust_level

On the command line:

codex --sandbox workspace-write --ask-for-approval on-request
codex --sandbox read-only --ask-for-approval on-request

In config:

# ~/.codex/config.toml
approval_policy = "on-request"
sandbox_mode = "workspace-write"

[sandbox_workspace_write]
network_access = false
writable_roots = []

Defaults: trust sets the starting point

  • In version-controlled folders, Codex recommends Auto, which is workspace-write with on-request.
  • In folders without version control, it recommends read-only.
  • Before a directory is trusted, Codex may start in read-only until you trust it during onboarding or via /permissions.
  • codex exec defaults to a read-only sandbox, and since 0.169.0 it skips project config and project MCP servers in untrusted directories (see codex exec in CI).

In the TUI, /permissions switches permissions and /status shows the current sandbox and workspace roots. To keep stricter command approval for a directory, the docs say to leave approval_policy unset and add:

[projects."/path/to/project"]
trust_level = "untrusted"

Network access

Network off by default in workspace-write is your first barrier against data leaving the machine. When a task needs the network (an npm install, say), there are three options, in order of preference:

  1. Install dependencies before Codex starts. In CI, put the install step before the Codex step.
  2. Open it for one run: codex -c 'sandbox_workspace_write.network_access=true'.
  3. Open it permanently: [sandbox_workspace_write] network_access = true in config.

Also worth knowing:

  • Web search is a separate switch. web_search takes disabled, cached (default), indexed or live; --search equals live. With --yolo or another full-access sandbox the default becomes live.
  • Domain allow lists. Beta permission profiles combined with features.network_proxy = true can allow traffic per domain. Without an active proxy, turning network on means direct, unrestricted access.
  • Local and private-network destinations are blocked by default unless you allow them explicitly or set allow_local_binding = true. Options whose names start with dangerously_ widen the trust boundary and belong only in tightly controlled environments.
  • MCP servers are not covered by the sandbox's network rules; they use their own settings. Read the MCP security and sandboxing guide before adding third-party servers.

Protected paths and writable roots

In workspace-write, these paths stay read-only even inside writable roots, recursively:

  • <writable_root>/.git, whether it's a directory or a file; if it's a gitdir: pointer file, the resolved Git directory is protected too
  • <writable_root>/.agents, <writable_root>/.codex and <writable_root>/.aws when they exist as directories

So Codex can't rewrite your Git history or its own config. When you need extra writable directories, prefer --add-dir or writable_roots in config; exclude_slash_tmp and exclude_tmpdir_env_var remove /tmp and $TMPDIR from the writable set.

Auto-review: another agent presses "approve"

If constant approval prompts break your flow but never feels too loose, turn on auto-review:

approval_policy = "on-request"
approvals_reviewer = "auto_review"

Eligible approval requests go to a reviewer agent first. Per OpenAI's docs, the reviewer denies critical-risk actions; prompt-build, review-session and parse failures fail closed; and auto-review makes extra model calls that count toward usage. The non-interactive docs list an --approve-for-me option for codex exec; check codex exec --help for your installed version.

Permission profiles (beta)

Permission profiles bundle filesystem and network rules into a named policy. As of 2026-11-25 they're beta and OpenAI warns they may change. Three are built in: :read-only, :workspace and :danger-full-access. A custom example:

default_permissions = "my-edit"

[features]
network_proxy = true

[permissions.my-edit.filesystem]
":minimal" = "read"

[permissions.my-edit.filesystem.":workspace_roots"]
"." = "write"
"**/*.env" = "deny"

[permissions.my-edit.network]
enabled = true

[permissions.my-edit.network.domains]
"api.openai.com" = "allow"

Permission profiles and the older sandbox_mode / [sandbox_workspace_write] settings don't combine. If any loaded config file contains sandbox_mode, you pass --sandbox, or the selected profile sets sandbox_mode, Codex uses the older settings and ignores default_permissions. If you call QCode, the domain to allow under network.domains is the endpoint you actually use.

Safe defaults by scenario

Scenario Sandbox Approvals Network Notes
Everyday local development workspace-write on-request Off The default recommendation
Reviewing an unfamiliar or open-source repo read-only on-request Off Read first, grant later
Shared machine or jump host read-only on-request Off Avoid touching others' files
CI review or summary read-only never Off Pair with --ephemeral
CI auto-fix workspace-write never Off Split patch and push into two jobs
Disposable container / VM danger-full-access on-request or never As needed Mount the project directory only

Turn the combinations you use into profile files such as ~/.codex/review.config.toml and switch with codex --profile review; see the Codex config.toml deep dive.

The dangerous bypass: what --yolo really risks

--dangerously-bypass-approvals-and-sandbox (alias --yolo) removes the sandbox and approvals together. It's not a "faster mode"; it hands the model every permission your user account has. The main risks:

  • Prompt injection. A README, an issue body, a web search result or an MCP tool's output can carry instructions that steer the model into running commands.
  • Deleting or editing outside the repo. Commands can touch any file, your home directory included.
  • Credential leaks. ~/.ssh, cloud credentials, browser data and keys in environment variables can be read and sent over the network.
  • Pushing as you. Your local Git credentials can push code or change remote repositories.
  • Persistence. Anything written to places such as shell startup files runs later, outside any sandbox.

If you truly need unattended, fully open execution, put it in a disposable, isolated environment:

# Mount only this project, keep Codex config in its own directory, delete the container afterwards
docker run --rm -it \
  -v "$PWD":/work -w /work \
  -v "$HOME/.codex-container":/codex \
  -e CODEX_HOME=/codex \
  -e QCODE_API_KEY \
  node:22 bash -lc 'npm install -g @openai/codex@0.172.0 && codex --sandbox danger-full-access'

Here ~/.codex-container/config.toml uses the env_key = "QCODE_API_KEY" provider form, and the container has none of your SSH keys or cloud credentials. Add a dedicated low-quota sub-key and any damage has a ceiling. For long-running cloud setups see running Codex CLI on a cloud server.

Windows, WSL and macOS notes

  • Native Windows. Codex runs in PowerShell on Windows 10 and 11 (CMD doesn't recognize the irm install command). MXC is the preferred sandbox: set prefer_mxc = true under [features] and keep a permitted legacy implementation (elevated or unelevated) in [windows] sandbox as a fallback.
  • Non-admin sandbox. Choosing the non-admin sandbox on first launch avoids an admin prompt. It carries higher risk if prompt injection occurs, so be extra careful with untrusted repositories.
  • WSL2 uses the Linux sandbox (bubblewrap and seccomp). WSL1 was supported through 0.114 and has been unsupported since 0.115.
  • IDE extension. "chatgpt.runCodexInWindowsSubsystemForLinux": true keeps the agent in WSL2 when it's available.
  • macOS. If the system sandbox can't enforce a command's policy, Codex refuses to run it rather than letting it through.
  • Self-test. The codex sandbox subcommand offers sandbox test entry points for macOS, Linux and Windows; check codex sandbox --help for usage.

Migrating old flags

Old Now
--full-auto --sandbox workspace-write (with on-request interactively); --approve-for-me in codex exec
--suggest, --auto-edit, --approval-mode Gone from the flag list; use --sandbox and --ask-for-approval
approval_policy = "untrusted" on-request + read-only, or a project trust_level = "untrusted"

FAQ

What's the difference between workspace-write and danger-full-access?

workspace-write writes only inside the working directory and temp directories, keeps network off by default and protects paths like .git. danger-full-access has no sandbox limits at all: it can read and write anywhere and use the network. Keep the latter for disposable containers or VMs.

Is approval_policy = "never" safe?

never only stops the prompts; Codex still runs inside the sandbox and out-of-bounds actions fail. With read-only or workspace-write it's reasonable for CI. Combined with danger-full-access, you have no protection left.

Why does untrusted in my config stop Codex from starting?

approval_policy = "untrusted" is retired. Switch to on-request with read-only, or set trust_level = "untrusted" under [projects."<path>"].

npm install fails with a network error inside Codex. What should I do?

workspace-write keeps network off by default. Install dependencies outside the sandbox first, or open the network for one run with -c 'sandbox_workspace_write.network_access=true'.

Can I use --yolo inside Docker?

OpenAI suggests --sandbox danger-full-access inside Docker or similar containers where the inner sandbox can't run, rather than bypassing approvals as well. What matters is isolating the container: mount only the project, keep production credentials out, and delete it afterwards.

Which sandbox should I use on Windows?

Enable MXC first ([features] prefer_mxc = true) and keep elevated or unelevated as the fallback. Alternatively, run Codex in WSL2 to get the Linux sandbox; WSL1 is no longer supported.

Does auto_review cost extra?

Yes. OpenAI says auto-review makes extra model calls that count toward usage. In return it cuts manual prompts while still denying critical-risk actions.

Sources: OpenAI Codex docs (Agent approvals & security, Sample Configuration, Permissions, Non-interactive mode), the Codex changelog and QCode's Codex docs, all read 2026-11-25.

Recommended plan: Daily 35

Once sandbox and approvals are set sensibly, Codex can work for long stretches without supervision. QCode's Daily 35 plan gives you $35 of usage per day (reset at 00:00 Beijing time) for $53.57 per 30 days; Claude and GPT models are billed at the official API price ×1.0, and one key works in both Codex CLI and Claude Code. See /pricing.

Recommended plan: Daily 35

One key for both the Anthropic Messages API and OpenAI-compatible APIs. Claude and GPT are billed at the official price ×1.0; live rates are on /models.

Not sure where to start?

Try it for a week

Small Pack: $4 for $30 of quota, valid 7 days

Use it every day

Starter: $9.00/month with $5 of quota every day — just $0.060 per $1 of quota, vs about $0.113 for the Medium Pack