techlist.io
OpenAI2026-11-176 min read

Curated summary

Inside the Codex sandbox

Read original(opens in new tab)

The Codex sandbox constrains the commands Codex runs on your machine using OS-native mechanisms, so the agent can work in your existing environment within filesystem and network limits you control. OpenAI treats it as one layer of defense in depth, alongside training and alignment. The design favors conservative defaults that still allow real development work, and it exposes the same restrictions through configurable permission profiles that individuals and enterprises can tailor.

Choosing the Sandbox Boundaries

  • The built-in :workspace profile allows writes within the workspace root but keeps .git, .codex, and similar directories read-only. This prevents direct edits to .codex/config.toml or .git/hooks.
  • Filesystem reads are broad, subject to the user's existing OS permissions, because compilers and build tools depend on SDKs and configuration outside the repository. The tradeoff is that secrets such as API keys in other files may remain readable.
  • Network access is disabled by default, which blocks direct exfiltration but also prevents legitimate tasks like installing dependencies.
  • The sandbox doesn't stop every harmful action. For example, an agent could modify a file in node_modules that an editor later executes on save. Such changes may not show up in git status.

Designing the Sandbox

  • Instead of isolating work in containers or VMs, Codex applies each platform's native sandboxing to commands running in the user's real environment.
  • Containers struggle with workflows like iOS development on a Mac, where the build toolchain and simulator require native macOS execution. Delegating those operations back to the host would reintroduce the same risk outside the container.
  • A common API spans macOS, Linux, and Windows. The function spawn_command_under_sandbox() takes a command, a working directory, environment variables, a permission profile, and an optional network proxy, and returns a child process handle.
  • Child processes inherit their parent's sandbox constraints, so restrictions apply to the entire process tree, including descendants that outlive the original command.

How the Harness Uses the Sandbox

  • The harness executes model-generated tool calls. The main one is exec_command, which runs shell commands.
  • To sandbox a call, the harness replaces the plain subprocess launch with the sandboxed spawn function and supplies the active permission profile and, when needed, a network proxy.
  • The model can request a per-command override through sandbox_permissions:
    • use_default applies the turn's default sandbox.
    • with_additional_permissions requests expanded filesystem or network access within the sandbox.
    • require_escalated requests execution outside the sandbox entirely.
  • The harness decides whether to grant these requests based on user preferences. It may prompt the user directly or route the decision to an auto-review process.
  • The same sandboxing infrastructure is reused for operations like reading and modifying local files.

Configuring the Sandbox

  • Permission profiles are defined under [permissions] in config.toml. A profile can extend a built-in one, such as :workspace, and set a default with default_permissions.
  • Filesystem entries are read, write, or deny. The :workspace_roots table applies rules relative to each workspace root, so a single .vscode = "read" entry makes that directory read-only in every root.
  • Profiles inherit protections from :workspace, including read-only .git, .codex, .agents, and .aws.
  • Network access can be configured in three ways:
    • Fully disabled (the default for :workspace).
    • Fully enabled direct access (the default for :danger-full-access).
    • Routed through a network proxy with domain allow and deny rules. Explicit denies take precedence, and wildcards are supported.
  • Configuration layers merge recursively, so a team can override individual entries while inheriting the rest of an organization's base configuration. Arrays are replaced as a whole.
  • Enterprises can use requirements.toml, from system files or cloud policy, with allowed_permission_profiles to restrict which profiles users may select. Profiles that are false or absent in the final merged configuration are unavailable.

Using the codex sandbox Command

  • codex sandbox --permission-profile <name> -- <command> runs an arbitrary command under a configured profile, independent of an agent session. This is useful for testing that a profile blocks what it should.
  • In the example, writing a malicious .vscode/settings.json fails with "Operation not permitted" under the dev profile, because .vscode is read-only.
  • The same mechanism can constrain tools outside Codex. For example, the harness doesn't sandbox stdio MCP servers by default because it can't infer their needs. Users can wrap them with codex sandbox and a restrictive profile, such as one that disables network access and limits writes to a data directory. Installing the package first and then launching with npx --offline lets the server run without network access.

Sandbox Implementation

Network Proxy

  • When network restrictions apply, the harness starts codex-network-proxy, which serves both HTTP and SOCKS5 endpoints. Proxy addresses are passed to sandboxed processes through environment variables such as HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, and PIP_PROXY.
  • Each request is checked against the profile's domain rules. Unmatched requests can be held while the harness asks for approval, then allowed or rejected.
  • The proxy resolves a hostname only after the request is approved, because even a DNS lookup can leak information. Broad wildcards or open DNS access can still permit DNS-based exfiltration.

macOS

  • Codex uses Seatbelt through /usr/bin/sandbox-exec, with policies written in Sandbox Profile Language (SBPL).
  • The base policy starts with (deny default), and rules are added for permitted paths. When the proxy is active, outbound connections are allowed only to the local proxy ports.
  • Placeholders such as (param "WRITABLE_ROOT_0") are populated with -D arguments, which keeps the policy generic.
  • Apple does not document SBPL for third-party use, and sandbox-exec is marked deprecated. Codex plans to keep using it because macOS still ships Seatbelt profiles and projects like Chromium depend on it.

Linux

  • Codex combines bubblewrap (bwrap) for filesystem and namespace isolation with seccomp-bpf for system call filtering. An internal helper, codex-linux-sandbox, coordinates them.
  • Codex vendors its own bwrap but prefers a compatible system installation, since some distributions restrict unprivileged user namespaces.
  • Filesystem views are built with --bind, --ro-bind, and deny patterns that mask paths with tmpfs or /dev/null. Deny globs are expanded to concrete paths when each command starts, so newly created matches aren't covered automatically.
  • --unshare-net, --unshare-ipc, and --unshare-pid isolate networking, IPC, and process visibility.
  • Seccomp filters are compiled with the seccompiler crate and applied to a launcher process. With networking disabled, calls like connect(2) and bind(2) are blocked. With the proxy enabled, IP sockets are allowed, but standalone Unix domain sockets are blocked to prevent access to host resources.
  • no_new_privs is set so sandboxed processes can't gain privileges through setuid binaries, and this works without elevated privileges.
  • Because the sandbox runs in its own network namespace, a bridge process outside the sandbox relays connections from a loopback listener inside the namespace to the shared proxy on the host.

Continue with another curated summary.