Table of Contents
- What the Codex sandbox actually is
- The three Codex sandbox modes
- How Codex enforces it on macOS, Linux, and Windows
- What the Codex sandbox does not protect
- When the sandbox blocks real work
- The honest escalation ladder: config, container, VM
- Running a Codex sandbox 24/7
- FAQ
- Is Codex sandboxed by default?
- How do I let Codex use the network inside the sandbox?
- How do I turn the Codex sandbox off safely?
- Does the Codex sandbox work on Windows?
- Has the Codex sandbox ever been bypassed?
What the Codex sandbox actually is
--sandbox flag or sandbox_mode in ~/.codex/config.toml.The three Codex sandbox modes
- read-only. The agent can inspect files but cannot edit anything or run state-changing commands without approval. This is the default for
codex execand for folders that are not version-controlled.
- workspace-write. The agent can read files, edit inside the workspace, and run routine commands there. Version-controlled folders get the Auto preset recommended at launch, which is workspace-write plus on-request approvals (depending on setup, Codex may start in read-only until you explicitly trust the working directory). The workspace means your current directory plus temp directories like
/tmp.
- danger-full-access. No filesystem or network boundary at all. The docs say to use it only when you want the agent acting with full access.
on-request (the agent asks before crossing the boundary) and never. If your config still says approval_policy = "untrusted", current builds refuse to start; that policy was retired, and on-failure is deprecated. There is also a new middle setting, --approve-for-me (alias --not-so-yolo), which routes approval prompts through an automatic reviewer instead of you.--yolo is real. It is the short alias for --dangerously-bypass-approvals-and-sandbox, which turns everything off. The flags documentation says to avoid it unless you are inside a dedicated sandbox VM. Hold that thought for later.# ~/.codex/config.toml
sandbox_mode = "workspace-write"
[sandbox_workspace_write]
network_access = trueHow Codex enforces it on macOS, Linux, and Windows
- macOS uses Apple's Seatbelt framework: commands run through
sandbox-execwith a profile matching the mode you selected. It works out of the box.
- Linux uses
bwrap(bubblewrap) plus seccomp, the default since version 0.115 in March 2026; the older Landlock path is now legacy. Ifbwrapis missing, Codex falls back to a bundled helper that needs unprivileged user namespaces, and it warns at startup when neither works.
- Windows no longer requires WSL. On up-to-date Windows 11 builds (24H2 build 26100.9278 or 25H2 build 26200.9278 and later, where Microsoft has rolled out the MXC capabilities), Codex can use native MXC process isolation (Microsoft Execution Containers): the desktop app prefers it automatically where supported, CLI users opt in with
prefer_mxc = true, andelevatedandunelevatedremain the legacy fallbacks. Run it inside WSL2 and you get the Linux sandbox instead; WSL1 cannot create the user namespacesbwrapneeds, so since April 2026 (the 0.121 era) Codex rejects sandboxed commands on WSL1 outright.
What the Codex sandbox does not protect
- Reads are open. workspace-write restricts where the agent can write, not what it can read. Your SSH keys, browser profiles, and dotfiles are readable by default. OpenAI's answer is the beta permission profiles system, which can deny reads outside the workspace and block patterns like
**/*.env, but it is opt-in and separate from the classicsandbox_modesetting.
- Environment variables pass through. Spawned commands inherit your environment by default, and variables with KEY, SECRET, or TOKEN in the name are kept unless you change
ignore_default_excludesor add explicit filters.
- MCP servers live outside the sandbox. They run as their own processes with their own network access. The sandbox policy does not contain them, and the new egress proxy explicitly does not filter MCP connections, web search, or cloud tasks.
- Prompt injection is contained, not solved. The docs warn that enabling network access or web search lets injected instructions reach the agent, and the worked example in OpenAI's Codex cloud internet-access docs is a GitHub issue that tricks the agent into piping
git show HEADto an outside URL. The same mechanics apply the moment you turn on network access locally. Web search now defaults to a cached index partly for this reason, and switches back to live results when you run with full access.
- .git is protected, your repo is not. Inside writable roots,
.git,.codex,.agents, and.awsare kept read-only. Everything else in the workspace is fair game, which is both the point and the risk.
cs scan). It has nothing to do with sandboxing.When the sandbox blocks real work
Symptom | What is happening | The fix |
npm, curl, or builds hang or time out | Network is off by default in workspace-write | Set network_access = true under [sandbox_workspace_write] |
"command failed; retry without sandbox?" | A sandboxed command failed, often because the policy denies a path it needs | Approve the escalation, or widen access with --add-dir or writable_roots |
Network enabled but macOS still blocks | A long-standing Seatbelt issue (openai/codex #10390) reports network_access = true being ignored | Most reports end at a container or full access |
Sandbox errors inside Docker | The container blocks the namespaces or seccomp operations bwrap needs | Let Docker be the boundary (next section) |
Windows "setup refresh failed" | Native sandbox setup failures on some builds | On a supported build, opt in to MXC ( prefer_mxc = true); otherwise retry the elevated setup or switch to WSL2 |
[features.network_proxy] config (off by default; set enabled = true) adds an allowlist-first egress proxy with per-domain rules on top of network_access = true, so you can permit registry.npmjs.org without opening the whole internet.The honest escalation ladder: config, container, VM
writable_roots, network_access = true, and proxy allowlists cover most real projects.--sandbox danger-full-access inside it so Codex does not try to create a second sandbox layer. OpenAI publishes a reference base image, ghcr.io/openai/codex-universal, and documents the same pattern for devcontainers, with a sharp warning attached: a malicious repo can still exfiltrate anything available inside the container, including your Codex credentials. Our Codex Docker guide walks through the whole setup.openai/codex-action wraps codex exec with an API key, recommends the :workspace permission profile (no network access; leave it unset and you get the legacy workspace-write sandbox instead), and defaults to a drop-sudo safety strategy, because a read-only filesystem plus sudo can still leak your key.--yolo work, the docs' own words point at a dedicated sandbox VM: a machine where the blast radius is the whole point.Running a Codex sandbox 24/7
agent37-codex template is Codex preinstalled on an always-on, gVisor-isolated instance with its own API, sessions, files, and URL. You connect your own OpenAI account, either by running codex login --device-auth in the instance terminal and approving with your ChatGPT plan, or by passing OPENAI_API_KEY as instance env (it also honors OPENAI_BASE_URL for any Responses-compatible endpoint). The image is lean, no browser and no desktop, and there is no managed-model option: model usage bills your OpenAI account, the sandbox bills Agent37's metered rate.--yolo isolation, VM instances run a whole Linux machine with its own kernel and KVM at 2.5x the compute rate, $11.36 per month for the same entry shape. The pricing page compares more than 30 providers at their published rates, claims 94% lower cost than most sandbox providers, and backs it with a refund-the-difference guarantee. New accounts get a $5 starter credit after adding a card, enough to run the entry sandbox for over a month.FAQ
Is Codex sandboxed by default?
codex exec defaults to a read-only sandbox. Unlike some agent tools, it fails closed when the OS cannot enforce the policy.How do I let Codex use the network inside the sandbox?
network_access = true under [sandbox_workspace_write] in ~/.codex/config.toml, or scope it tighter with the newer egress proxy's domain allowlist. Be aware of the macOS reports that the toggle is ignored under Seatbelt (issue #10390).How do I turn the Codex sandbox off safely?
--sandbox danger-full-access inside a Docker container or devcontainer that provides the isolation, an isolated CI runner, or a dedicated VM. Running --yolo on your bare laptop means one injected instruction can touch anything you can.Does the Codex sandbox work on Windows?
elevated or unelevated sandboxes elsewhere, and the Linux bwrap sandbox under WSL2.