Safety

AI-generated text

OpenAI details how Codex limits command access

OpenAI has described the filesystem and network safeguards Codex applies when it runs commands on a user's machine.

OpenAI details how Codex limits command access

OpenAI has explained how its Codex agent system restricts filesystem and network access when it runs commands on a user's computer. Michael Bolin, a member of OpenAI's technical staff, says the sandbox is part of a defense-in-depth approach that supplements model training and alignment: commands run in the user's existing environment, but within configured permission limits.

Permission profiles define filesystem and network rules for a Codex session. For a photo-organizing task, a user might allow reading and modifying ~/Pictures while disabling the network to prevent uploads. For code review, source files could instead be read-only while online documentation remains accessible.

Default settings and their limits

The built-in :workspace profile permits writes within the workspace but makes directories including .git and .codex read-only. Codex can therefore edit source code without requesting approval for every change, while being unable to modify Git hooks or .codex/config.toml directly.

The profile allows broad filesystem reads within the user's existing operating-system permissions. That access supports compilers, runtimes and build tools that depend on libraries and configuration outside the project. The tradeoff is that sensitive files elsewhere, such as configuration files containing API keys, may also remain readable. Network access is disabled by default, preventing direct external uploads but also requiring additional access for legitimate operations such as downloading dependencies.

The sandbox does not eliminate every risk. Bolin gives the example of an agent inserting malicious code into a locally installed package, such as node_modules/prettier, that Git often ignores. If an editor runs that copy on save, the code could execute outside the Codex sandbox. OpenAI says access restrictions must therefore be combined with model training and alignment.

Profiles and permission requests

Rather than place Codex commands in a virtual machine or container, OpenAI restricts them using each operating system's own safeguards. This allows the existing development environment to be used: an iOS project on a Mac, for example, can rely on native build tools and the iPhone simulator, which are harder to access under container isolation.

The Codex harness passes a command and permission profile to the platform-specific sandbox through a common interface. Restrictions are inherited by child processes, including descendants that outlive the original process. The model can request expanded access or execution outside the sandbox for individual commands, but the harness decides whether to authorize the request under the user's settings, potentially seeking approval from the user or an automated review process.

Users can define reusable profiles in config.toml, specifying writable, read-only or denied paths. In OpenAI's example, a dev profile extends :workspace to allow writes to ~/build-cache while making .vscode directories under workspace roots read-only.

Networking can be disabled entirely, enabled for direct access, or restricted to a proxy. The proxy applies rules for exact domains and wildcard patterns, with explicit denials taking precedence over allowances. Requests not covered by a rule may await approval or be rejected.

Configuration can be layered: higher-priority values win conflicts, tables merge recursively, and arrays are replaced as a whole. Enterprise administrators can use requirements.toml or cloud-provided policy to constrain choices such as the profiles users may select. Users can then customize settings within those limits.

Standalone commands and MCP servers

The codex sandbox command can apply configured profiles to arbitrary commands outside an agent session. Developers can use it to test rules and incorporate the platform-specific protections into their own tools.

By default, Codex does not sandbox the startup commands for configured MCP servers that communicate over standard input and output, because it cannot reliably determine which files and network services they need. OpenAI's example shows that a memory server's startup command can instead be wrapped with codex sandbox and a dedicated profile. By caching the package in advance, the server can start without network access, with writes limited to its data directory and npm cache.

How network protection works

When a profile permits limited network access, Codex starts a proxy and blocks direct external connections. The proxy forwards or rejects requests according to domain rules. By default it starts both HTTP and SOCKS5 proxies, passing their addresses to processes through environment variables including HTTP_PROXY, HTTPS_PROXY and ALL_PROXY. The operating-system sandbox blocks direct external connections from programs that ignore those variables.

The proxy resolves a destination hostname only after an authorization decision, because even a DNS lookup can leak data encoded in the name. Broad wildcard rules or access to DNS services can nevertheless permit DNS-based exfiltration.

Implementation on macOS, Linux and Windows

On macOS, Codex uses Apple's kernel-enforced Seatbelt sandbox through /usr/bin/sandbox-exec. The generated policy denies access by default and opens only explicitly permitted access, including local proxy ports when needed. Although Apple marks sandbox-exec as deprecated and does not document its policy language for third-party developers, OpenAI plans to continue using Seatbelt for the foreseeable future.

On Linux, Codex combines bubblewrap with seccomp-bpf, which filters system calls. Bubblewrap creates a filesystem view matching the profile and, when needed, a separate network namespace; seccomp applies further restrictions inherited by child processes. Deny patterns are expanded into concrete paths before launch, so newly created matches are not automatically added to a running command's restrictions. When a proxy is used, a local listener inside the isolated namespace and a relay outside it forward connections to the proxy.

On Windows, OpenAI is transitioning from its existing sandbox to Microsoft eXecution Container (MXC), released by Microsoft, on compatible devices. The company says the change addresses limitations including the need for administrator access during setup, slow permission checks and persistent setup state on the host. Codex supplies MXC with the command, working directory, environment and permissions for files, networking and Windows resources.

The MXC-based implementation permits registry reads and desktop access needed for PowerShell startup, while disabling controls including clipboard access and input injection. For filesystem rules, more-specific paths override broader ones; where different path spellings or links refer to the same location, the stricter permission applies. Deny patterns must again be resolved before launch. The shared Codex proxy enforces domain rules while MXC blocks direct external connections, although other local services remain reachable.

OpenAI says its aim is to let agents work in users' existing environments while keeping their access controllable. The company identifies easier permission configuration and the adoption of improved operating-system protections as next steps.