Codex sandbox: read-only, workspace-write and --yolo explained
Codex CLI's three sandbox modes and two approval policies, the -s, -a and --yolo flags, config.toml keys, codex sandbox, and running it unattended on a server.
Codex CLI has two separate controls. The sandbox mode decides what the commands it runs can do: read-only (no writes), workspace-write (writes in the working directory and the temp folders, no network), or danger-full-access (no sandbox). The approval policy decides when it stops to ask: on-request or never. Set them with --sandbox (-s) and --ask-for-approval (-a), or sandbox_mode and approval_policy in ~/.codex/config.toml. --yolo is an alias of --dangerously-bypass-approvals-and-sandbox, which turns both off and which Codex’s own help text marks as intended only for environments that are already sandboxed from outside. --full-auto no longer exists; as of Codex 0.172.0 (November 2026) use --sandbox workspace-write.
The three sandbox modes
The sandbox applies to the shell commands Codex runs for the model: git, package managers, test runners, scripts. The values are the same on the command line and in the config file.
| Mode | Can write | Network |
|---|---|---|
read-only | Nothing | Off |
workspace-write | The working directory, /tmp, $TMPDIR and any extra roots you add, minus the protected folders below | Off unless network_access = true |
danger-full-access | Anything your user can write | On |
The three modes don’t limit reads. On Linux the sandbox mounts the whole filesystem read-only (--ro-bind / / in the Linux sandbox’s README) and then binds the writable roots on top, so a command in workspace-write can still read ~/.ssh or a cloud credentials file. The sandbox stops it changing them, and with the network off it has no direct way to send them anywhere.
OpenAI’s own source describes danger-full-access as “No restrictions whatsoever. Use with caution.” It is the mode to choose when something else (a container, a VM) is the boundary.
The approval policies
In Codex 0.172.0, --ask-for-approval takes two values:
on-request, the default: “The model decides when to ask the user for approval.” Codex works inside the sandbox and asks when a command needs to go beyond it, such as writing outside the workspace or reaching the network.never: “Never ask for user approval. Execution failures are immediately returned to the model.” The sandbox still holds, so a blocked command fails and the model has to work around it.
In config.toml there is a third form, granular, a table of switches (sandbox_approval, rules, mcp_elicitations, request_permissions, skill_approval). A category set to true still prompts; one set to false is rejected automatically instead of being shown to you.
Older tutorials list untrusted and on-failure. The config reference now says “untrusted is unsupported, and on-failure is deprecated”. In the source, on-failure is read as on-request. An approval_policy = "untrusted" left in a config is another matter: OpenAI’s security docs say the retired setting can prevent Codex from starting, so take it out. The stricter ask-before-every-command behaviour now comes from marking a project untrusted, which the guide on untrusted project configuration covers.
approvals_reviewer = "auto_review" sends the prompts that on-request would show you to a reviewer agent instead. It does not widen the sandbox: it only answers the requests to cross it.
The flags, and what happened to --full-auto
| Flag | What it sets |
|---|---|
-s, --sandbox <mode> | The sandbox mode for this run |
-a, --ask-for-approval <policy> | on-request or never (interactive codex only) |
--add-dir <dir> | An extra writable directory beside the workspace |
-C, --cd <dir> | The working root, which is what workspace-write opens |
--approve-for-me (alias --not-so-yolo) | workspace-write, on-request, and the auto-review reviewer |
--dangerously-bypass-approvals-and-sandbox (alias --yolo) | No sandbox and no prompts |
--approve-for-me can’t be combined with --sandbox or the bypass flag, and the interactive CLI refuses -a alongside either of them. The bypass flag’s help text reads:
Skip all confirmation prompts and execute commands without sandboxing. EXTREMELY DANGEROUS. Intended solely for running in environments that are externally sandboxed.CopiedMany scripts and tutorials still use --full-auto. OpenAI’s non-interactive docs now say “--full-auto is no longer supported,” and the 0.172.0 source defines no such flag, so a script that still passes it fails on an unexpected argument. Replace it with --sandbox workspace-write, or with --approve-for-me if you want approval requests routed through automatic review instead of to you.
Inside a session, /permissions switches between presets such as Auto and Read Only.
What you get when you pass nothing
OpenAI’s security docs put the defaults by folder: “Version-controlled folders: Auto (workspace write + on-request approvals)” and “Non-version-controlled folders: read-only”. The 0.172.0 source decides it by whether the folder (or the repository it sits in) has a trust decision, trusted or untrusted:
- Sandbox: with no
--sandboxand nosandbox_mode, the config code’s comment reads “If no sandbox_mode is set but this directory has a trust decision, default to workspace-write”. Otherwise the mode is the enum’s default,read-only. On Windows with the sandbox disabled,workspace-writedrops toread-only. - Approvals in interactive
codex: a trusted folder getson-request, a folder marked untrusted gets the internaluntrustedpolicy (“Commands require approval unless an explicit exec policy rule allows them”), and a folder with no decision gets the default,on-request. codex exec: approvals are set toneverin the code (“Default to never ask for approvals in headless mode”), since there is nobody to ask, unless the reviewer resolves toauto_review(as with--approve-for-me), in which case the configured policy applies.codex exechas no-aflag. For the sandbox, the non-interactive docs say “By default,codex execruns in a read-only sandbox,” but the 0.172.0 source has no read-only default of its own forexec: it passes no mode on, and the shared rule above applies, so a trusted project can getworkspace-write. Since the two disagree, pass--sandboxexplicitly in scripts.
codex exec also refuses to start outside a git repository unless you add --skip-git-repo-check (the bypass flag skips that check too), and prints:
Not inside a trusted directory and --skip-git-repo-check was not specified.CopiedThe config.toml keys
The same choices, kept in ~/.codex/config.toml. This is a sandboxed setup that never asks, with the network open and one extra writable folder:
sandbox_mode = "workspace-write"
approval_policy = "never"
[sandbox_workspace_write]
writable_roots = ["/home/me/.cache/pip"]
network_access = true
# exclude_slash_tmp = true # take /tmp out of the writable roots
# exclude_tmpdir_env_var = true # take $TMPDIR out tooCopiednetwork_access = true opens outbound access fully, to any host, for every command in the sandbox. Since reads are not limited, that is also the setting that lets a command which read a secret send it somewhere. Leave it off unless the work needs installs or downloads, and if it does, keep credentials the agent shouldn’t have off that machine. A domain allowlist exists (a network proxy under [features.network_proxy]), but the reference marks it experimental and off by default. The [sandbox_workspace_write] table only applies when the mode is workspace-write.
In 0.172.0 a profile is a separate file, ~/.codex/<name>.config.toml, laid over your main config with --profile <name>. A file named unattended.config.toml holding the lines above gives you codex --profile unattended while your everyday sessions keep the defaults. How the layers stack, and how to check which value won, is in the Codex config.toml guide.
Newer releases also have named permission profiles ([permissions.<name>] tables chosen with default_permissions), which set filesystem and network rules path by path. The reference says not to combine them with sandbox_mode or [sandbox_workspace_write]: pick one system per config.
Folders that stay read-only
Even in workspace-write, Codex keeps these read-only, including everything under them: .git (and the directory a .git pointer file leads to, as in a worktree), .agents, .codex and .aws, the last three only when they exist as directories. So a command in the sandbox can edit your code but cannot write to the repository’s history, rewrite the project’s Codex config, or change AWS credentials kept in the workspace.
How each system enforces it
| System | Mechanism | Setup |
|---|---|---|
macOS | Seatbelt: commands run through sandbox-exec with a profile matching the mode | None, built in |
Linux, WSL2 | bubblewrap (bwrap) for the filesystem view and network namespace, plus seccomp | Install bubblewrap; Ubuntu 24.04 may also need an AppArmor profile |
Windows (PowerShell) | MXC, with the older elevated and unelevated sandboxes as fallbacks | Elevated needs setup approved by an administrator |
WSL1 | Not supported since Codex 0.115 | Move to WSL2 |
On Linux, Codex uses a bwrap on your PATH (outside the current folder) and otherwise falls back to a copy it bundles. Either way bubblewrap needs to create user namespaces, and Codex warns at startup when it can’t. The old Landlock implementation is still in the code but is no longer the default. Install the system package so you are not relying on the fallback:
sudo apt install bubblewrap # Debian, Ubuntu
sudo dnf install bubblewrap # Fedora, RHELCopiedIf Codex still warns at startup that it can’t create a user namespace, or a command fails with a bwrap: error, the bubblewrap errors guide goes through each message and the AppArmor fix. The Windows modes, and the [windows] sandbox key that picks one, are in Codex on Windows.
Test it with codex sandbox
codex sandbox runs one command under the same sandbox Codex uses, on whatever system you are on, so you can see what is blocked without involving the model. With no options, and a config that doesn’t use permission profiles, it applies read-only, not the mode in your config; pass a mode with -c to test another:
codex sandbox -- touch probe.txt # read-only: the write fails
codex -c sandbox_mode='"workspace-write"' sandbox -- touch probe.txt
codex sandbox -- curl -sI https://example.com # network off: fails to resolve or connectCopiedOn macOS, --log-denials collects the Seatbelt denials while the command runs and prints them after it exits, which is the quickest way to find the path a build tool wanted. On Windows, codex sandbox uninstall removes the legacy sandbox’s machine-wide accounts and network rules (run it as administrator; it keeps your Codex home and its files). The second line above deletes nothing, but it does create probe.txt in the current folder.
OpenAI’s security docs show this command with a platform word, codex sandbox linux [COMMAND]... (or macos, windows), and say it is also available as codex debug. The 0.172.0 source defines neither: codex sandbox takes the command directly on every system, its only subcommand is uninstall, and codex debug holds other tools. If the docs’ form fails on your version, drop the platform word.
On a server or in a container, unattended
There is nobody to answer a prompt on a server, so the choice is between keeping the sandbox with approvals off and dropping it because the machine is the boundary.
Keep the sandbox. On a VPS or a VM where bwrap works, this is the safer default. Interactive sessions: codex -s workspace-write -a never. Scripts and cron jobs:
codex exec --sandbox workspace-write -C /srv/app "run the tests and fix what fails"CopiedExpect the sandbox to get in the way of some projects: tests that open local sockets, start child processes or need to download dependencies can fail inside it, and with never the model only sees the failure. Add the folders they need with --add-dir or writable_roots, turn on network_access if installs are part of the job, and read the failures before widening anything further.
Make the container the boundary. Inside Docker the Linux sandbox often can’t start at all, because the container blocks the namespace, setuid bwrap or seccomp calls it needs. OpenAI’s docs give two options: keep the Linux sandbox if the container grants what bwrap needs, or, where the container is meant to be the boundary, run Codex inside it with --sandbox danger-full-access or the bypass flag, which is the case its help text describes: “Intended solely for running in environments that are externally sandboxed.” That gives the agent everything in the container, its own Codex sign-in included, and OpenAI’s own warning about dev containers is that “a malicious project can exfiltrate anything available inside the devcontainer.” So mount only the project, pass in only the credentials the job needs, and don’t give the container the Docker socket or your home folder.
The same reasoning covers --yolo on a whole machine: the machine itself has to be the outside sandbox the help text asks for, which a server holding nothing but the project, the tools and the agent’s own login can be, and a laptop with your SSH keys on it is not. How Codex’s options line up against Claude Code’s for running without prompts is in running Claude Code and Codex without permission prompts, and Claude Code’s own Bash sandbox in the Claude Code sandbox guide.