Inside the Codex sandbox
See how Codex runs commands on your machine while enforcing the filesystem and network limits you control across macOS, Linux, and Windows.
November 18, 2026
How Codex runs commands on your machine with limits you control.
By Michael Bolin, Member of Technical Staff
- Choosing the sandbox boundaries
- Designing the sandbox
- How the harness leverages the sandbox
- Configuring the sandbox Network permissions
- Layering configuration and enforcing limits
- Using the codex sandbox command Example: sandboxing an MCP server
- Codex sandbox implementation Network proxy
- Building on the Codex sandbox
At OpenAI, we take a defense in depth (opens in a new window) approach when it comes to safeguarding agents. While our investments in training and alignment are fundamental to this effort, we also implement features in our agentic harness, Codex (opens in a new window) , to provide additional protections. Because one of the most common (and potentially risky) things Codex does is run commands on your computer, we built the Codex sandbox so Codex can work in your existing environment within filesystem and network limits you control.
A (opens in a new window) sandbox (opens in a new window) limits what a program can access while it runs. For a photo-organizing task, you might configure the Codex sandbox to let commands read and modify files in ~/Pictures while blocking network access to prevent uploads. For code review, you might allow access to online documentation while keeping source files read-only. Users configure the Codex sandbox through (opens in a new window) permission profiles (opens in a new window) , which define the filesystem and network restrictions for a Codex session.
In this article, we’ll start with the tradeoffs behind Codex’s sandbox defaults, then explain the sandbox’s design and how the harness uses it to run commands. We’ll show how end users and enterprises can tailor its permissions to their needs and how developers can reuse the sandbox in their own tools. Finally, we’ll examine how these restrictions are enforced on macOS, Linux, and Windows.
In Codex, our philosophy is to specify conservative defaults for the sandbox that still enable meaningful work. For example, with a Git repository as the workspace root, the built-in :workspace permission profile:
- Allows writes within the workspace, while keeping directories such as .git and .codex read-only. This lets Codex edit source code without seeking permission for every change, while preventing direct changes to .codex/config.toml or Git hooks under .git/hooks .
- Allows broad filesystem reads, subject to the user’s existing OS permissions. Compilers, runtimes, and build tools depend on SDKs, libraries, and configuration outside the repository. Restricting reads to the workspace would break many ordinary workflows. The tradeoff is that sensitive files elsewhere on the machine may also remain readable (such as config files containing API keys).
- Disables network access. This blocks direct uploads to external services, including attempts to exfiltrate data the command can read. It also prevents legitimate operations such as downloading dependencies, which require additional access.
These restrictions prevent a large class of bad behavior, but harmful actions are still possible. For example, the agent could inject malicious code into a locally installed package such as node_modules/prettier . Such a change might not appear in git status because node_modules is often ignored by Git. If the user’s editor runs that copy of Prettier on save, simply saving a file could execute the malicious code outside the Codex sandbox. This is why we take a defense in depth approach: the sandbox limits what commands can access, while training and alignment help the model use that access in accordance with the user’s intent.
For guidance on tailoring sandbox permissions and combining them with other protections in an enterprise environment, see the Codex security cookbook (opens in a new window) .
Designing the s andbox
Virtual machines and containers (opens in a new window) are two popular mechanisms used for sandboxing, but we take a different approach with the Codex sandbox. Instead of moving computation to a separate environment to provide isolation, Codex uses each platform’s sandboxing facilities to constrain commands running in the user’s existing environment. For many developers, their laptop serves as a bespoke dev environment that they can change on a whim. Reproducing that environment in a Docker container can take work, and some workflows still depend on tools that run on the host.
For example, consider using Codex to develop an iOS app on a Mac. If you decided to sandbox Codex by running it inside Docker, Codex would not be able to run the iOS build toolchain composed of native Mac executables, nor could it launch the iPhone simulator to run the code. A Docker-based workflow could delegate builds and simulator operations to the Mac host, but those operations would execute outside the container’s sandbox and would need their own restrictions. For Codex, we prefer to keep things simple by investing heavily in OS-specific sandboxing so Codex can run in the environment that is most appropriate to the task at hand.
The harness exposes these OS-specific sandboxing mechanisms through a common API across macOS, Windows, and Linux. This API takes a command and a permission profile. If the permission profile allows limited network access, the caller must supply a network proxy to enforce those limits:
This function starts the process in a sandbox and returns a Child handle the harness can use to wait for it to finish. Each child process inherits its parent’s sandbox constraints, so those restrictions apply throughout the process tree initiated by the command , even to descendants that outlive the original process.
The following diagram shows how these pieces fit together, from configuration to running a sandboxed command. The sections that follow explain each stage.

As explained in Unrolling the Codex Agent Loop , the Codex harness is responsible for executing tool calls generated by the model. For coding tasks, the most commonly used tool is a shell tool , which runs commands much as a user would in an interactive shell such as Bash. Here we’ll examine the one-shot (opens in a new window) exec_command (opens in a new window) shell tool (opens in a new window) to illustrate how the harness employs the sandbox to achieve the desired protections. This is a simplified version of how the exec_command tool call would be honored by the Codex harness without sandboxing :
To sandbox the command, the harness replaces the call to subprocess.Popen() with spawn_command_under_sandbox() . The harness supplies the permission profile and, when needed, the network proxy:
The exec_command tool also lets the model request different permissions for an individual command, but the harness decides whether to grant the request :
When use_default is specified, the harness uses the default sandbox config for the turn. with_additional_permissions requests expanded access within the sandbox, while require_escalated requests execution outside it. The harness evaluates the request based on the user’s preferences before executing the command. (For example, Codex may prompt the user directly, or it might route the request to auto-review (opens in a new window) .) If execution is authorized, Codex will pass the appropriate permission_profile and network_proxy to perform_exec_command_with_sandboxing() with the command arguments from the original ExecCommandToolCall .
The shell tool is the primary consumer of spawn_command_under_sandbox() , and the harness also reuses its sandboxing infrastructure for operations such as reading and modifying local files.
本文由 白泽自动聚合自 OpenAI Blog,发布时间:2026-11-18。内容与图片版权归原作者所有,本站仅作信息整理。