aiagentsecurity.devKeeping AI agents in bounds

Codex sandbox: the 3 modes, and what each lets the agent do

The Codex sandbox limits the commands Codex runs in the CLI, IDE extension and desktop app, and it is on by default. In workspace-write mode, Codex edits files and runs commands inside your workspace with no network, and asks before going further. read-only stops edits; danger-full-access, or --yolo, removes the sandbox and approvals. Pick one with --sandbox or sandbox_mode in config.toml.

Published December 1, 2026 · Updated December 2, 2026. Read from Codex's documentation on December 1 and 2, 2026.

What do the Codex sandbox modes allow?

Each mode sets what commands can touch; the approval policy sets when Codex stops and asks. The sandbox covers the commands Codex spawns, such as git, package managers and test runners, not only its own file edits.

ModeEdit filesRun commandsNetwork
read-onlyNonot without approvalNonot without approvalNooff
workspace-writeYesinside the workspaceYesroutine ones, inside the workspaceNooff unless you turn it on
danger-full-accessYesanywhereYesanythingYeson

The workspace is the current directory plus temporary directories such as /tmp; /status lists them. From Codex's sandboxing docs, read December 1, 2026.

On launch, Codex recommends workspace-write with on-request approvals (the Auto preset) in a version-controlled folder, and read-only in one that isn't. It may start read-only until you trust the folder. Claude Code works the other way round: what the Claude Code sandbox blocks, once you turn it on.

How do approvals work with the sandbox?

approval_policy takes on-request, where Codex works inside the sandbox and asks to go beyond it; never, where it never stops to ask; or a granular table that auto-rejects some kinds of prompt and keeps others. untrusted is unsupported and on-failure is deprecated. approvals_reviewer decides who answers: user by default, or auto_review, a reviewer agent.

IntentFlagsEffect
Auto (preset)--sandbox workspace-write --ask-for-approval on-requestEdits and runs in the workspace; asks for outside edits or network
Read-only browsing--sandbox read-only --ask-for-approval on-requestReads and runs read-only; asks for the rest
CI, read-only--sandbox read-only --ask-for-approval neverNever asks
Full access--dangerously-bypass-approvals-and-sandbox (--yolo)No sandbox, no approvals

For non-interactive runs, Codex's docs use codex exec --sandbox workspace-write. Read December 1, 2026.

Tool calls from apps and MCP servers that advertise a destructive annotation always need approval. A sandbox limits files and hosts, not what the agent does with an allowed one, which is why the five agent security controls keep a person in front of high-impact actions. Many MCP servers also hold a static key of their own: how MCP servers ask for credentials.

How do you set the defaults in config.toml?

With sandbox_mode and approval_policy; writable_roots under [sandbox_workspace_write] adds folders without removing the sandbox.

approval_policy = "on-request"
sandbox_mode    = "workspace-write"

[sandbox_workspace_write]
network_access = true   # only if commands need it

Save presets as profile files, such as ~/.codex/full_auto.config.toml, and pick one with codex --profile. In a session, /permissions switches modes.

How do you limit network access to some hosts?

Turn on network_access, then the network_proxy feature, which holds traffic from commands and their subprocesses to your destination rules. Adding domain rules alone doesn't turn the proxy on, and an approved full sandbox escalation can bypass it.

Which paths stay read-only in workspace-write?

Inside every writable root: .git (and the real Git directory when .git is a pointer file), .agents, .codex and .aws, with everything under them. So Codex can edit your code but not rewrite Git internals or its own settings. Read-only isn't unreadable: commands can still read what those folders hold, so run the five-line credential audit to see what an agent could use.

How is the Codex sandbox enforced on each system?

  • macOS: Seatbelt, through sandbox-exec with a profile for the chosen mode. Works out of the box.
  • Linux: bwrap plus seccomp. Install bubblewrap (sudo apt install bubblewrap); on Ubuntu 24.04, load the bwrap-userns-restrict AppArmor profile if Codex warns.
  • Windows: the native Windows sandbox in PowerShell, the Linux one in WSL2. WSL1 was supported through Codex 0.114; from 0.115 the Linux sandbox uses bwrap, so WSL1 isn't supported.

The native Windows sandbox has three implementations, set with windows.sandbox: mxc, elevated or unelevated. Choosing mxc outright fails when MXC is unavailable or blocked by managed requirements. features.prefer_mxc = true instead prefers MXC when the machine and policy allow it and otherwise keeps your configured sandbox. It is off by default in the standalone CLI, the desktop app can turn it on through rollout configuration, and a command that fails under MXC doesn't fall back.

To see what a command does under the sandbox, run codex sandbox macos, codex sandbox linux or codex sandbox windows followed by the command; on macOS, --log-denials lists what was blocked.

Can Codex run inside Docker or a dev container?

Yes. If the container blocks what bwrap needs, make the container the boundary and run Codex there with --sandbox danger-full-access. Codex's docs warn that a malicious project can then take anything in the container, Codex's credentials included, so keep this for repositories you trust. Docker Sandboxes and E2B put a whole agent or its code in a box: agent sandboxes and security tools compared.

How was this page checked?

Every mode, flag and default was read from Codex's documentation on December 1, 2026. Errors: support@winding.ai.

  1. Sandbox (Codex docs): modes, approvals, approvals_reviewer, platforms, prerequisites
  2. Agent approvals and security (Codex docs): defaults, protected paths, network, combinations, config.toml, testing, OS enforcement, dev containers