How OpenAI's Codex isolates AI commands without relying on containers

- Reading
- 7 min
OpenAI detailed how the Codex coding agent restricts files and network access using the native sandbox mechanisms of macOS, Linux, and Windows, instead of running everything inside a Docker container.
OpenAI published a technical breakdown on its blog of how Codex, its command-line coding agent, isolates the commands that AI executes on the developer's machine. The text, signed by the product's own engineering team, describes what the company calls a "defense in depth" approach: model training and alignment reduce the chance of a malicious command being generated, but the Codex harness also imposes technical execution limits in case the model errs or is manipulated by a prompt injection.
The central point of the material is that Codex does not run the agent's commands inside a VM or a separate Docker container, as many isolation solutions would. Instead, it triggers the sandboxing mechanisms already built into the operating system, Seatbelt on macOS, for example, to restrict what a process can read, write, or access over the network, even while running in the developer's actual environment.
Why Not Use Docker
OpenAI's justification for this choice is practical: reproducing a developer's development environment inside a container takes work, and some workflows simply don't function in isolation. The example the company gives is developing an iOS app: the native Mac build toolchain and the iPhone simulator don't run inside a Linux container.
If Codex forced everything into Docker, these operations would have to be delegated to the host anyway, and would then fall outside the sandbox, requiring their own separate restrictions. OpenAI chose to invest heavily in OS-specific sandboxing instead, to keep the agent running in the environment best suited to the task, without that split.
For those building their own agents, this is an architecture decision worth copying: containers solve process isolation, but not when the task depends on host tools. OS-level sandboxing tackles the problem without requiring the entire environment to be rebuilt.
Permission Profiles and the :workspace Default
In Codex, each session runs under a permission profile, which defines what the command can read, write, and access over the network. The default profile, called :workspace, follows three rules:
- It allows writing inside the project directory, but keeps
.gitand.codexread-only, so the agent can edit code freely without being able to touch Git hooks or Codex's own configuration. - It allows broad filesystem reading, because compilers and build tools depend on SDKs and libraries outside the repository. The trade-off, acknowledged by OpenAI, is that sensitive files elsewhere on the machine (like configs with API keys) also remain readable.
- It disables network access by default, blocking direct data uploads as well as dependency downloads, which require a separate permission.
OpenAI itself admits that this set of rules doesn't cover everything. The example they give is instructive: a sandboxed command could still inject malicious code into a locally installed package, such as node_modules/prettier. Since node_modules is usually in .gitignore, the change doesn't show up in git status. If the dev's editor runs that compromised Prettier when saving a file, the malicious code executes outside Codex's sandbox. It's this kind of gap that justifies defense in depth: the sandbox limits access, but doesn't replace model alignment.
How the Harness Triggers the Sandbox
The text details the internal mechanics: Codex exposes a common sandboxing API across the three platforms, which takes a command and a permission profile and returns a child process handle. The entire process tree originating from that command inherits the same restrictions, including descendants that outlive the original process.
Codex's shell tool (exec_command, described in the previous article of the series, Unrolling the Codex Agent Loop) is the main consumer of this API. Without a sandbox, the harness would call something equivalent to subprocess.Popen() directly. With the sandbox, that call is replaced by an internal function that takes the permission profile and, when needed, a network proxy.
The model can request different permissions for a specific command, using three modes: use_default (uses the session's default profile), with_additional_permissions (requests expanded access within the sandbox), and require_escalated (requests to run outside the sandbox). In any of these cases, it is the harness, not the model, that decides whether to authorize it, either asking the user directly or delegating the decision to an auto-review mechanism.
Layered Configuration and Custom Permission Profiles
Users and organizations can define their own profiles in config.toml, under the [permissions] key, extending the default :workspace. OpenAI describes, for example, a dev profile that adds write access to ~/build-cache and further restricts some workspace directories, such as making .vscode read-only.
For networking, there are three possible options in a profile: disable everything (the :workspace default), allow full and direct access (the default of a profile called :danger-full-access), or restrict access to a set of domains via proxy, with wildcard rules and explicit denials that take priority over permissions.
Companies can lock down these choices with a requirements.toml file, which defines which profiles a user can select through allowed_permission_profiles. These rules can come from multiple sources, including cloud policy, and a higher-precedence source can explicitly forbid the use of the :danger-full-access profile, for example, even if the user's local file says nothing about it.
The codex sandbox Command and the MCP Server Case
One of the most useful points in the material for those already building with Codex is the codex sandbox command, which applies a permission profile to any arbitrary command, outside of an agent session. OpenAI suggests using it to test whether a profile actually blocks the behavior it's supposed to block, before trusting it in production.
The practical example given in the article is sandboxing an stdio MCP server, such as @modelcontextprotocol/server-memory. By default, Codex doesn't try to sandbox the command that starts an MCP server, because it has no way to infer which files or network services that specific server needs, and applying a generic profile could simply break the integration.
The alternative described is to define a dedicated profile, called memory-mcp in the example, and wrap the server's original startup command with codex sandbox --permission-profile memory-mcp. This limits where the process can write and blocks network access, provided the package is already cached locally via npx --offline. It's a replicable pattern for any agent that needs to call external tools via MCP without inheriting the full permissions of the user running the parent process.
What Happens Under the Hood on macOS
The implementation section details the macOS case, which uses Seatbelt, Apple's kernel sandboxing mechanism, triggered via /usr/bin/sandbox-exec. The policies are written in SBPL (Sandbox Profile Language), a Scheme-based language, which OpenAI assembles starting from a base policy with (deny default), meaning everything is blocked unless explicitly allowed.
When the network proxy is enabled, the SBPL itself receives rules to allow connections only to the proxy's local ports, while direct connections to external hosts remain blocked by the kernel. OpenAI acknowledges in the text itself that generating correct SBPL is challenging because Apple doesn't document the language for third-party use, which requires careful reverse engineering.
For Linux and Windows, the material indicates that the team uses each platform's native facilities following the same common API, but the technical detail equivalent to the Seatbelt section was not available in the published portion of the source consulted for this report.
Why This Matters for Those Building Agents
The network proxy deserves separate mention: it solves the problem of granting granular network access without opening everything up. Because Codex resolves the hostname only after approving the request (not before), it prevents a DNS lookup from leaking data encoded in the hostname itself, an exfiltration technique that simple allow/deny lists wouldn't cover on their own.
For those developing their own agents, whether with Codex, another harness, or building something from scratch, the material works as a checklist of architecture decisions: named, reusable permission profiles, a filesystem with per-path read/write/deny granularity, network access via proxy with asynchronous approval instead of a binary block, and native OS sandboxing when the user's actual environment needs to be preserved. None of these points requires using Codex: they are design patterns that any local agent stack, including homegrown ones, can (and perhaps should) replicate before giving an AI the power to run commands on your machine.
Translated from the Brazilian Portuguese original · Read the original
Transformers runs 180-billion-parameter MoE model on a Mac with 32GB of RAM
A project published by Hugging Face teaches the Transformers library to fetch from disk only the pieces of an MoE model that each token actually needs, reaching 14 tokens per second on a Mac with 32GB of memory.





