Get the free coreGet core

Codex sandbox: how Codex CLI isolates commands on macOS

Updated 6 min readSection 02 / Sandboxing
SHORT ANSWER

By default Codex runs with network access off, inside an operating-system sandbox that limits what it can touch, plus an approval policy that decides when it must ask you. On macOS the sandbox uses Seatbelt, a built-in feature of the system. There are three modes: read-only, workspace-write and danger-full-access. To turn the Codex sandbox off, use --sandbox danger-full-access, and do that only inside a controlled environment such as an isolated container.

This page covers the Codex sandbox on a Mac: what each mode allows, how approvals sit next to it, and what happens when you remove it.

01Sandbox and approvals are two separate controls

A sandbox is a fenced area. A command inside it can touch only what the fence allows. Codex gives you two separate dials, and people often mix them up.

The sandbox is the fence. Locally it is enforced by the operating system and limits what Codex can touch, typically to the current workspace. The approval policy is the question. It controls when Codex must stop and ask you before acting.

The fence also covers helpers. When the agent runs tools like git, package managers or test runners, those commands inherit the same boundaries. On a Mac you install nothing extra, because sandboxing works out of the box.

02The three Codex sandbox modes

In plain words: look only, write in your folder, or everything.

ModeWhat Codex can doNetwork
read-onlyInspect files. It cannot edit files or run commands without approvalOff by default
workspace-writeRead files, edit within the workspace, run routine local commands inside that boundary. The default low-friction mode for local workOff unless you enable it in your configuration
danger-full-accessRuns without sandbox restrictions. Removes the filesystem and network boundariesNetwork open

The workspace is the folder you started Codex in. In workspace-write mode, some paths inside it stay read-only. .git is read-only whether it appears as a directory or a file, and so is a .codex directory when it exists. Git hooks and Codex settings live there, so a command cannot rewrite them.

03Approval policies: when Codex asks

Two policies matter most.

Put the two together and you get presets. The Auto preset, for example --sandbox workspace-write --ask-for-approval on-request, lets Codex read files, make edits and run commands in the working directory automatically. It asks for approval to edit files outside the workspace or to run commands that need network access. The CLI reference gives the same pair of flags for low-friction local work.

For unattended runs there is a read-only preset: --sandbox read-only --ask-for-approval never. Here the approval policy changes the picture: Codex never stops to ask, so it reads files and runs only the commands that fit inside the read-only fence. Anything that would need your approval simply does not happen.

04Is the Codex sandbox safe?

It is a real wall for the commands Codex runs, and it is on by default, but it is narrow. Three things to keep in mind.

First, it only protects what you leave on. The default network is off, and OpenAI's docs say to use caution when enabling network access or web search. A network connection gives a prompt-injected command somewhere to send data. Prompt injection means text hidden in something the agent reads, such as a README or a web page, that tells it to do something you did not ask for.

Second, Codex is not the only thing that can start processes. Project-defined MCP servers can run commands outside the sandbox. An MCP server is a helper program that gives the agent extra tools, and a project you open can define one.

Third, a fence limits what a command can touch but does not report what ran. See the last section.

05How to use Codex without the sandbox

Two flags do this, and they are not the same.

--sandbox danger-full-access removes the walls: Codex runs without sandbox restrictions, with no file or network boundary. The approval questions are a separate dial, so add --ask-for-approval never if you want no prompts. OpenAI's docs list this flag for work with network access and no approval prompts, and say to use caution.

--dangerously-bypass-approvals-and-sandbox, with the alias --yolo, does both at once: no sandbox and no approvals. OpenAI's docs say to avoid it unless you are inside a dedicated sandbox VM. With --yolo or another full-access setting, web search defaults to live results.

Where should these flags live? In an isolated place. The docs say to use danger-full-access only in a controlled environment, for example an isolated build runner or a container. A VM is a whole separate computer simulated inside yours, and a container is a lighter isolated environment. Codex's docs describe a Docker pattern too, and the container setup is on Claude Code in Docker. The same thinking applies to Codex.

06How to fix a Codex sandbox error

An error from the sandbox means a command reached past the fence: a file outside the project, or a host on the network. You have three choices, from narrow to wide.

  1. Let Codex ask. With the on-request policy it works inside the sandbox and asks when it needs to go beyond that boundary. You approve the single step.
  2. Open only what the task needs. workspace-write keeps the network off unless you enable it in your configuration. Turn it on for the task, with the caution that comes with it.
  3. Go to full access, in isolation. danger-full-access removes the boundaries. Do that in a VM or container.

Do not jump to step three first. First ask what the command was trying to reach. Then decide if the task really needs it, and check that you trust the repository that asked for it.

07One flag that changed

If you used the --full-auto flag in scripts, note that it is no longer supported in codex exec. Update scripts to use --sandbox workspace-write instead. The background on that flag is on Codex full auto.

08How Codex compares with the other agents

Codex sets its wall in the operating system and pairs it with an approval policy. Claude Code's sandbox covers shell commands only, and its file tools, MCP servers and hooks run outside it. In Cursor, a command that fails in the sandbox can be rerun outside it. The details are on Claude Code sandbox and Cursor sandbox. All four agents sit in one table on sandbox for an AI agent.

09Should you rely on the Codex sandbox?

Use workspace-write mode with on-request approvals as your everyday setup. It is the default low-friction mode. Keep the network off unless a task needs it. Keep danger-full-access and --yolo for a VM or container. The dev container route is on Claude Code devcontainer.

A sandbox limits what a command can touch; it doesn't show what already ran. Codex's sandbox decides what a command may touch; Artificial Immunity's free, open-source core watches Codex sessions and program starts on your Mac and reports what it finds.

FAQ

Is the Codex sandbox safe?

It is a real wall for the commands Codex runs, with network access off by default, but a narrow one. Anything you switch off, such as the network or the sandbox itself, widens what a prompt-injected command can do.

How do I turn off the Codex sandbox?

Run Codex with --sandbox danger-full-access, or with --dangerously-bypass-approvals-and-sandbox. OpenAI's docs say to use caution, and to avoid the second flag unless you are inside a dedicated sandbox VM.

How do I use Codex without a sandbox?

The same two flags. The first removes the file and network walls, the second also removes approval prompts. Use them inside an isolated VM or container.

How do I fix a Codex sandbox error?

A command that hits the boundary needs either your approval or a wider mode. With the on-request policy Codex asks when it must go beyond the boundary. If the task needs the network, turn it on in your configuration for that task, and go to full access only inside a VM or container.

What is the difference between the sandbox and approvals in Codex?

The sandbox decides what a command is technically able to touch. The approval policy decides when Codex must stop and ask you before acting.

Does the Codex sandbox cover git and npm?

Yes. Tools such as git, package managers and test runners that Codex starts inherit the same boundaries.

Sources

  1. OpenAI Codex docs: sandboxing
  2. OpenAI Codex docs: approvals and security
  3. OpenAI Codex docs: CLI reference
  4. OpenAI Codex docs: non-interactive mode
  5. Artificial Immunity
Codex with wide access? Artificial Immunity watches the Mac where your agents work.Get the free core