OpenAI’s Codex sandbox runs model-generated commands inside a user’s existing environment while applying filesystem and network restrictions that the user or administrator defines. Positioned as a compromise between executing code in isolated containers and running commands without constraint on the host, the Codex sandbox aims to preserve developer workflows—editing code, building apps, and running tools—while reducing opportunities for unintended access or data exfiltration.
OpenAI ships conservative default permission profiles intended to support common developer tasks without exposing sensitive files or direct network access. The built-in :workspace profile, for example, permits write access within a repository while keeping key directories such as .git and .codex read-only. It also allows broad filesystem reads so compilers and build tools outside the repository can function, and it disables network access by default to prevent direct uploads or downloads. These defaults reduce many risks but do not remove all possible harmful actions, which is why OpenAI frames sandboxing as one layer in a defense-in-depth strategy alongside training, alignment, and user controls.
The Codex harness exposes a common API across macOS, Linux and Windows that accepts a command and a permission profile. When the harness executes tool calls such as the shell exec_command, it replaces normal subprocess launches with spawn_command_under_sandbox(), supplying the chosen profile and, when required, addresses for a network proxy. Child processes inherit sandbox restrictions so constraints propagate down the process tree rather than stopping at a single process boundary. The harness also evaluates model requests for expanded permissions on a per-command basis: a turn can request defaults, additional permissions, or privileged execution outside the sandbox, and the harness will consult user preferences or an auto-review flow before granting such requests.
Permission profiles are defined in config.toml and referenced by name. Filesystem rules within those profiles grant read, write, or deny access to explicit paths and support workspace-relative rules that apply to each configured workspace root. Administrators and teams can layer configuration files and supply managed requirements that restrict which profiles users may select, giving organizations centralized control over permissible sandbox behaviors.
Network policy in the Codex sandbox has three primary modes. The default :workspace profile sets network disabled, preventing direct network traffic from sandboxed processes. A :danger-full-access profile enables full direct access. The intermediate option uses a network proxy: Codex starts a proxy that enforces domain allow/deny rules and can suspend requests pending user or auto-review approval. The proxy checks domain rules before resolving hostnames to reduce DNS-based information leakage, and it injects standard environment variables such as HTTP_PROXY, HTTPS_PROXY and ALL_PROXY into sandboxed processes so proxied connections route through the enforcement layer.
OpenAI implements the sandbox with OS-native mechanisms on each platform. On macOS, Codex leverages Apple’s Seatbelt sandboxing via /usr/bin/sandbox-exec. The harness composes SBPL policy strings from a base profile plus profile-specific amendments and passes them to sandbox-exec with -D parameters. On Linux, Codex uses bubblewrap (bwrap) to create tailored filesystem views and applies seccomp-bpf for syscall filtering. A helper binary coordinates launching bwrap and then applies dynamic seccomp filters produced by the seccompiler crate. For network-proxied sandboxes, Codex creates an isolated network namespace and relays connections from a listener inside that namespace to a proxy process outside it. On Windows, OpenAI has transitioned from an earlier custom sandbox toward Microsoft’s MXC (Microsoft eXecution Container). Codex constructs MXC JSON execution requests via the MXC SDK, translating permission-profile filesystem and network rules into MXC settings and using the shared network proxy for domain enforcement; OpenAI notes benefits such as reduced need for elevated setup and fewer persistent host-side artifacts.
The harness design recognizes residual risks even with conservative defaults. OpenAI highlights scenarios like a model modifying a locally installed package in node_modules; such changes might escape version control and later execute outside the sandbox when the user runs their editor or other tools. That example underlines why OpenAI treats sandboxing as one part of layered defenses rather than a single silver bullet.
To aid testing and integration, Codex provides a sandbox CLI command that runs an arbitrary command under a named permission profile. OpenAI gives examples such as wrapping an MCP server startup with codex sandbox and pre-populating caches so the server can run with network disabled and writes restricted to specified directories. The CLI is intended to help developers embed sandboxed execution into workflows and validate how profiles behave in real development scenarios.
By combining platform-native sandbox primitives, a network proxy, and layered configuration, OpenAI positions the Codex sandbox as a reusable primitive for balancing capability and control. The approach aims to let agentic tools operate in users’ real development environments while limiting direct avenues for data leakage or host compromise. Sandboxing, user review flows, and administrative policy together form the company’s stated strategy for safer model-driven automation.
In short, the Codex sandbox is designed to enable useful model-driven developer workflows inside live environments while applying multilevel restrictions and review mechanisms to manage risk. It is one engineered layer in a broader safety posture rather than a standalone solution.
Source: Read the original source

Leave a Reply