/en/articles/how-codex-locks-down-its-commands-openais-sandbox-on-macos-linux-and-windows-explained
How Codex Locks Down Its Commands: OpenAI's Sandbox on macOS, Linux and Windows, Explained

On November 18, 2026, OpenAI published "Inside the Codex sandbox", an engineering post by Michael Bolin that explains how its coding agent, Codex, runs commands on your computer without getting a blank check over your files or the network. It's not a launch: it's the explanation of a piece that's already in use and that can now be configured by hand with permission profiles. It matters for two reasons: anyone who lets an agent run npm install on their laptop should know what stops it and what doesn't, and OpenAI exposes that same sandbox as a command (codex sandbox) to lock down tools that have nothing to do with Codex.
The idea: lock the command in, don't move the machine
The usual way to isolate code is to move it into a virtual machine or a container. Codex does the opposite: it lets commands run in your real environment and uses each operating system's isolation mechanisms to put limits on them. OpenAI justifies this with a concrete example: if you're developing an iOS app on a Mac and you put Codex in Docker, the agent can no longer use the native build tools or open the iPhone simulator.
Everything goes through a single harness function, which receives the command, the directory, the environment variables, the permission profile and, if the profile limits the network, a proxy. Every child process inherits the restrictions, even the ones that outlive the original command. The model can ask for more permissions for a specific command (with_additional_permissions) or ask to run outside the sandbox (require_escalated), but the harness decides, based on your preferences: it asks you or hands it off to automatic review.
What comes by default (and its blind spot)
The built-in :workspace profile, with a Git repository as the root, makes three decisions:
- Writing only inside the workspace, with
.git,.codex,.agentsand.awsread-only. That way the agent edits code without asking permission for every change, but it can't touch your Git hooks or its own configuration. - Broad disk reading, limited only by your system permissions. OpenAI admits this bluntly: restricting reads would break compilers and SDKs, and the flip side is that sensitive files outside the repo, like configs with API keys, remain readable.
- Network off. That stops a command from uploading what it read to an external server, but it also blocks legitimate things like downloading dependencies.
The most honest part of the post is the example of what the sandbox does not stop. The agent could plant malicious code in node_modules/prettier, which is inside the workspace and therefore writable. git status doesn't show it, because node_modules is almost always ignored. And if your editor formats on save with that copy of Prettier, the tampered code runs outside the sandbox with your permissions. That's why OpenAI talks about defense in depth: the sandbox limits access and the model's training does the rest.

Configuring it: profiles in config.toml
Profiles are defined under [permissions] in config.toml. Each path gets read, write or deny, and a profile can inherit from another with extends. This is OpenAI's example, trimmed down:
default_permissions = "dev"
[permissions.dev]
extends = ":workspace"
[permissions.dev.filesystem]
"~/build-cache" = "write"
[permissions.dev.filesystem.":workspace_roots"]
".vscode" = "read"
"**/*.env" = "deny"
"secrets" = "deny"
For the network there are three modes: off (what :workspace does), full (what :danger-full-access does) or filtered through a proxy with per-domain rules, where an explicit deny beats an allow. One detail the official documentation underlines: network.enabled = true opens the network, but it does not turn on the proxy. Without features.network_proxy = true, your domain rules filter nothing. It's the kind of mistake that makes you think you're protected when you're not.
The documentation also warns that profiles are in beta and don't combine with the old configuration (sandbox_mode): if that key shows up in any loaded file, Codex ignores the profiles. In companies, the administrator can set in requirements.toml which profiles are allowed, and a profile that isn't on that list is forbidden.
The command you can reuse
codex sandbox --permission-profile <profile> -- <command> runs anything under a profile, with no agent involved. OpenAI uses it for two things. First, testing that a profile blocks what it should: their example tries to write a .vscode/settings.json that would activate a malicious formatter, and on macOS it fails with Operation not permitted. Second, and more useful for anyone building bots and agents: locking down MCP servers. Codex doesn't sandbox the command that starts an MCP server over stdio, because it can't guess what it needs. With an unrestricted npx, that server writes and browses with your permissions. OpenAI's recipe defines a profile with broad read access, write access only to ~/.npm and its own data folder, network off, and starts the server with npx --offline wrapped in codex sandbox, after pinning the package in the npm cache.
How it's applied on each system

- macOS: uses Seatbelt through
/usr/bin/sandbox-exec, with an SBPL profile that starts with(deny default)and only opens outbound traffic to the proxy's local ports. OpenAI acknowledges that Apple markssandbox-execas deprecated and that the language isn't documented for third parties, but it plans to keep using it because Chrome depends on it too. - Linux and WSL: combines bubblewrap, which builds the filesystem view with read, write or block mounts, and seccomp-bpf, which filters network calls like
connectandbind. When there's a proxy, the sandbox has its own network and a process outside relays the connections. Codex ships its own copy ofbwrap, but prefers the system one because some distributions only allow that one to use user namespaces. - Windows: OpenAI is replacing the sandbox it described earlier this year with one based on MXC, Microsoft's isolated execution library. The change eliminates the need for administrator permissions and the footprint the previous model left behind: sandbox users, firewall rules and ACLs.
The network proxy is the same on all three: it spins up an HTTP proxy and a SOCKS5 one, checks every domain and resolves DNS only after approving it, because a DNS query can leak data inside the hostname. OpenAI warns that very broad wildcards or direct access to DNS services still allow that leak.
What to keep in mind
denyrules with wildcards (**/*.env) are expanded into concrete paths at the start of each command on Linux, WSL and Windows. A.envcreated later by a long-running process isn't blocked.- Not all programs respect
HTTP_PROXY. The ones that try to connect directly don't get away with it: the operating system cuts their connection, but they don't work either. - The sandbox doesn't protect what you run afterward with files the agent modified (the Prettier case).
My take: this is useful infrastructure beyond Codex. If you already use third-party MCP servers with any agent, codex sandbox is a cheap way to strip their network and write access without setting up a container. I haven't tested it; everything above comes from OpenAI's post and its official documentation. The practical advice that follows from both: start with :workspace, explicitly deny your secrets folders and don't enable the network without turning on the proxy.