Inside the Codex Sandbox: Architecture and Security Implementation

Overview

OpenAI has detailed the technical architecture of the Codex sandbox, a security harness designed to provide defense-in-depth for AI agents. By implementing filesystem and network restrictions directly within the user's existing environment—rather than relying solely on containerization—the sandbox allows agents to perform tasks while maintaining granular control over sensitive resources.

Sandbox Design Philosophy

Codex avoids the overhead and compatibility issues of virtual machines or Docker containers by leveraging native operating system sandboxing facilities. This approach ensures that agents can interact with the user's local toolchain (e.g., native build tools or simulators) while remaining constrained by a common API across macOS, Linux, and Windows.

Conservative Defaults

Codex employs a :workspace permission profile as a default, which balances utility with security:

  • Filesystem: Allows writes within the workspace root but restricts access to sensitive directories like .git and .codex. It permits broad read access to system libraries and SDKs to ensure build tools function correctly.
  • Network: Disables all network access by default to prevent data exfiltration.
  • Defense-in-Depth: OpenAI acknowledges that sandboxing is not a silver bullet; it is paired with model training and alignment to ensure agents respect user intent, as malicious code injection remains a theoretical risk if an agent modifies local dependencies.

Enforcement Mechanisms

Codex uses platform-specific technologies to enforce these constraints, managed by a unified harness that handles command execution.

macOS (Seatbelt)

Codex utilizes Apple’s Seatbelt (via sandbox-exec), a kernel-enforced mechanism. Despite its deprecated status in documentation, it remains the standard for macOS sandboxing. Codex dynamically generates Sandbox Profile Language (SBPL) policies based on the user's permission profile to restrict system calls and file access.

Linux (Bubblewrap and Seccomp)

On Linux, the sandbox uses bubblewrap (bwrap) to create isolated mount namespaces and seccomp-bpf to filter system calls.

  • Network Isolation: To handle network requests, Codex launches a network proxy outside the sandbox. Inside the sandbox, a loopback TCP listener is created; a bridge process then relays traffic from this listener through the proxy, ensuring the agent cannot bypass restrictions by accessing the host's network namespace directly.

Windows (MXC)

OpenAI is transitioning its Windows implementation to the Microsoft eXecution Container (MXC) library. This move addresses previous limitations, such as the requirement for administrative privileges and slow ACL management. MXC allows Codex to translate permission profiles into a JSON-based configuration that restricts filesystem, network, and system-level resource access.

Configuration and Extensibility

Users and enterprises can define custom permission profiles in config.toml. These profiles support:

  • Layered Configuration: Settings are merged recursively, allowing organizations to enforce global security policies via requirements.toml while permitting individual users to tailor local settings.
  • Tool Reuse: The codex sandbox CLI command allows developers to apply these same security policies to their own tools, such as wrapping an MCP (Model Context Protocol) server to restrict its access to specific data directories and disabling its network capabilities.

Implications for Agent Security

By providing a standardized way to constrain agentic tools, the Codex sandbox allows for more complex agent behavior without sacrificing host security. The system is designed to be extensible, with OpenAI planning to continue adopting newer OS-level primitives as they become available to further refine the boundaries of agentic execution.

Sources