31 tools· updated nov 2026

Codex sandbox: read-only, workspace-write, danger-full-access, and what each one blocked in my test

Marek.

  • codex
  • coding-agents
  • agent-security

The Codex sandbox is the OS-level boundary around every shell command Codex runs. It has three modes. read-only lets commands read files. workspace-write adds writes inside the working directory and /tmp. danger-full-access removes the boundary. You pick one with -s or sandbox_mode in config.toml. By default, workspace-write has no network access. On codex-cli 0.166.0 I watched read-only refuse a one-line file and workspace-write write it. In workspace-write, curl failed until I enabled network_access with -c.

codex -s read-only
codex -s workspace-write
codex -s danger-full-access
sandbox_mode = "workspace-write"

[sandbox_workspace_write]
network_access = true
  • Three modes. read-only, workspace-write, danger-full-access. The help for -s lists no others.
  • What a denial looks like. Under the :read-only profile, touch died with touch: s1.txt: Operation not permitted.
  • Offline by default. Under workspace-write, curl returned Could not resolve host. With network_access enabled the same call got HTTP 200.
  • Where to look. The codex exec header prints the sandbox. In the TUI, /status lists the writable roots.
  • Windows is its own story. Three native implementations, plus WSL2 with the Linux sandbox.

The flags that turn the sandbox off are in my Codex dangerously skip permissions post. The Claude Code equivalent is in Claude Code sandbox.

What is sandbox_mode in Codex and which modes exist?

sandbox_mode is the config key that picks the Codex sandbox. The config reference defines it as the "sandbox policy for filesystem and network access during command execution". Its values are read-only, workspace-write and danger-full-access. The -s flag sets it for one launch. The file itself, with its layers and profiles, is in Codex config.toml.

The sandbox is not the approval policy. The approvals and security page calls them two layers, what Codex can do and when Codex must ask. In a git repo Codex recommends workspace-write with on-request approvals. Elsewhere it recommends read-only. DeepSeek Harness uses the same names workspace-write and danger-full-access for presets that set both layers in one switch, see my DeepSeek Harness post.

workspace-write is wider than the name suggests. Per the docs, the workspace "includes the current directory and temporary directories like /tmp". My run headers said the same, workspace-write [workdir, /tmp, $TMPDIR]. Inside a writable root, the docs keep .git, .agents, .codex and .aws read-only.

Why does Codex say "operation not permitted"?

The sandbox refused a write. On 31 October 2026 I ran codex exec -s read-only in an empty folder and asked for t.txt with the word ok. Codex reported that the workspace is read-only. The folder stayed empty. A second run with --json logged only the model's message. It quoted zsh:1: operation not permitted: t.txt. That is the model's report. The raw version came from the codex sandbox helper under the :read-only profile:

touch: s1.txt: Operation not permitted

The same prompt under -s workspace-write wrote the file through apply_patch. The whole run took eight seconds.

Codex has no single "sandbox failed" message for model-run commands. The model sees a failed command and explains it. In the source at tag rust-v0.166.0, sandboxing/src/denial.rs guesses whether a failure came from the sandbox. It first looks for seven keywords, such as operation not permitted and read-only file system. If none match, exit codes 2, 126 and 127 count as not a sandbox problem. The file comment calls the check conservative.

On macOS the enforcement is Seatbelt through sandbox-exec, per the docs. On Linux and WSL2 it is bwrap plus seccomp.

Why is the Codex sandbox offline?

Codex ships with the network off. The approvals page says "by default, the agent runs with network access turned off." Under workspace-write my curl -I https://example.com failed with curl: (6) Could not resolve host: example.com. I think DNS was blocked inside the sandbox. The machine itself was online.

The switch is one key. I added -c sandbox_workspace_write.network_access=true to the same codex exec call. The header gained (network access enabled). The same curl returned HTTP/2 200.

One catch. In the codex sandbox helper, -P :workspace plus that same override still failed. Only -P :danger-full-access reached the host. I think the profile wins. The helper tests a profile, not your sandbox_mode setting. The config reference says not to combine default_permissions with [sandbox_workspace_write].

How do I check which sandbox mode a Codex session runs in?

Check the header that codex exec prints before the work starts. Mine read approval: never and sandbox: read-only, or sandbox: workspace-write [workdir, /tmp, $TMPDIR]. That line is the truth for that run. In codex exec a resumed session named the wrong sandbox.

In the TUI, type /status. Per the CLI reference it shows the approval policy and the writable roots. /debug-config prints the config layers.

To test one command without a model, use codex sandbox. The docs show codex sandbox macos. The 0.166.0 help on my Mac lists no macos subcommand. I passed -P in every run, with my normal config loaded. This gave the touch error above:

codex sandbox -P :read-only --log-denials -- touch s1.txt

The --log-denials section said None found.

How does the Codex sandbox work on Windows?

The Codex sandbox runs natively on Windows. The Windows sandbox page lists three implementations. mxc is the recommended one on compatible Windows 11 builds, with no admin setup. elevated is the legacy fallback. It needs an administrator-approved setup and creates dedicated lower-privilege sandbox users plus firewall rules. unelevated uses a restricted token with weaker network isolation.

Those sandbox users are where setup fails, per the docs: a declined UAC prompt, blocked user creation or blocked firewall changes. Windows error 1385 means the sandbox user exists but policy denies it the logon type.

Under WSL2 Codex uses the Linux sandbox. WSL1 support ended in 0.115. This section is the docs, not my test.

How does the Codex sandbox differ from the Claude Code sandbox?

Codex has three modes and a native Windows sandbox. Claude Code has one switch, sandbox.enabled, off by default, plus allow and deny lists for paths and domains. The Claude Code column is from the Claude Code sandboxing docs, not a test. Gemini CLI picks Seatbelt or Docker per backend, see Gemini CLI sandbox.

Codex CLI 0.166.0Claude Code
Setting-s or sandbox_modesandbox.enabled in settings
Modesread-only, workspace-write, danger-full-accessOne switch, with allowWrite, denyRead and domain lists
Network defaultOff in workspace-writeNo direct route, a proxy checks allowedDomains, which start empty
macOSSeatbelt via sandbox-execSeatbelt
Native Windowsmxc, elevated, unelevatedCommands run unsandboxed, WSL2 only
Test one commandcodex sandbox -P :workspace -- cmd, which tests a profileAsk Claude to run it with the sandbox on

Frequently asked questions

Does codex exec have an --ask-for-approval flag?

No. On 0.166.0 it fails with unexpected argument '-a' found. Every exec run reports approval: never. Unless an allow rule matches, the sandbox is what stops a command. The approval side is in Codex dangerously skip permissions.

Is /tmp writable in workspace-write?

Per the docs and the run header, yes. To remove /tmp and $TMPDIR, the config reference has exclude_slash_tmp and exclude_tmpdir_env_var under [sandbox_workspace_write].

What does "sandbox failed" mean in Codex?

Per the docs, usually a failed legacy elevated setup on Windows. The only literal match in the source I downloaded is windows sandbox failed: {err}, printed by the Windows path of the codex sandbox helper in debug_sandbox.rs. I did not run it.

Did you test this?

Yes, on macOS with codex-cli 0.166.0 on 31 October 2026. Six codex exec runs and five codex sandbox runs in empty folders, each logged. I did not test Windows or Linux.

The verdict

I use Codex every day as a worker next to Claude Code. read-only refused a three-byte file. workspace-write kept curl from resolving a host. Open the network in [sandbox_workspace_write], not with danger-full-access. Read the header before you trust a run. For a filter that sees a command before the sandbox does, see Codex hooks.

Sources, read on 31 October 2026: the Codex approvals and security page, the Windows sandbox page, the config reference, the CLI reference, the Claude Code sandboxing page and local help output for codex-cli 0.166.0. Code references are from openai/codex at tag rust-v0.166.0, mainly codex-rs/sandboxing/src/denial.rs. The eleven test runs are my own.