Your Coding Agent Runs Shell Commands on Your Laptop — Here's the Sandbox That Keeps It Honest
OpenAI just published the clearest explanation yet of how Codex keeps a coding agent from wrecking your machine. In "Inside the Codex sandbox" (November 18, by Michael Bolin), the team walks through the layer that decide
OpenAI just published the clearest explanation yet of how Codex keeps a coding agent from wrecking your machine. In "Inside the Codex sandbox" (November 18, by Michael Bolin), the team walks through the layer that decides what a model-generated shell command is allowed to touch — and the design is more interesting, and more honest about its limits, than most agent-safety writing.
The problem: your agent runs commands on your laptop
A coding agent's most common — and most dangerous — job is running commands on your computer. A model that can rm -rf the wrong directory, rewrite your Git hooks, or upload your .env file is not a theoretical risk. It is the default failure mode of giving a language model a shell.
Codex answers that with a sandbox. But not the kind you might expect.
No containers. Your OS does the sandboxing.
The usual answer to "run untrusted code safely" is a virtual machine or a Docker container. Codex deliberately does neither. Instead, it constrains commands using each platform's own sandboxing facilities, so the agent works inside the environment you already have.
The reason is practical. Your laptop is a bespoke dev environment: reproducing it in a container takes work, and some workflows only run on the host at all. OpenAI's example is iOS development on a Mac — inside Docker, Codex could not run the native Mac build toolchain or launch the iPhone simulator. Delegating those steps back to the host would put them outside the container's sandbox anyway. So Codex invested in OS-native enforcement instead, and exposed it through one common API: give it a command and a permission profile, and the harness runs the command under those limits.
Permission profiles: the config language
Everything is driven by permission profiles — named rules that say which paths a command may read, write, or never touch, and which network traffic it may send. You define them in config.toml under [permissions].
The built-in :workspace profile, used when a Git repository is the workspace root, shows the philosophy: conservative defaults that still let real work happen.
-
Writes are allowed inside the workspace, but
.gitand.codexstay read-only. Codex can edit your source freely, but it cannot rewrite.codex/config.tomlor drop a hook into.git/hooks. - Reads are broad, on purpose. Compilers, runtimes, and build tools depend on SDKs and config outside the repo. Restricting reads to the workspace would break ordinary workflows — the tradeoff is that sensitive files elsewhere on the machine, like config files holding API keys, may also remain readable.
- Network access is off by default. That blocks data exfiltration, including attempts to upload files the command was allowed to read. It also blocks legitimate work like downloading dependencies, which needs an explicit grant.
The post's worked example, a dev profile, extends :workspace: it adds write access to ~/build-cache, makes .vscode and .devcontainer read-only, and denies **/*.env and secrets outright.
Network: three options, and a proxy that checks first
For networking, a profile picks one of three modes: no access, full direct access, or access through a proxy that enforces domain rules. The proxy is the interesting one. It injects the usual HTTP_PROXY / HTTPS_PROXY / ALL_PROXY variables plus app-specific ones like PIP_PROXY, then checks each request against the profile's rules — explicit denials beat allowances, and anything unlisted can be held for approval.
One detail worth stealing for your own tools: the proxy resolves the hostname only after deciding the request is allowed, because even a DNS lookup can leak information encoded in the hostname. And direct connections are blocked at the OS level, so a program that ignores the proxy variables still cannot reach the outside world.
Three operating systems, three mechanisms
The same profile is enforced differently on each platform:
-
macOS — Seatbelt. Codex builds a policy in Apple's Sandbox Profile Language and invokes it through
/usr/bin/sandbox-exec. The base profile starts with(deny default), so outbound connections stay blocked unless explicitly allowed. Apple has markedsandbox-execdeprecated and never documented the profile language for third-party use — but macOS still ships Seatbelt profiles, and Chrome and Chromium rely on it, so OpenAI plans to keep using it. -
Linux — bubblewrap plus seccomp-bpf.
bwrapbuilds a filesystem view in a separate mount namespace (--bindfor writable paths,--ro-bindfor read-only,--perms 000tricks for denied paths), and seccomp filters the system calls — blockingconnect()andbind()when networking is off. The launcher setsno_new_privsso child processes cannot escalate via setuid binaries. Codex even vendors its own copy ofbwrapin case the user has not installed one. - Windows — MXC. Microsoft's newer execution-container library is replacing OpenAI's earlier Windows sandbox, which needed admin access to set up, did slow ACL operations, and left persistent state on the host (ACLs, firewall rules, sandbox users, control-plane files). MXC gives native process isolation with a JSON configuration schema, and Codex translates the profile's filesystem and network rules into it — more-specific paths override ancestor grants, and when aliases point at the same path, the stricter permission wins.
You can use the sandbox without the agent
The codex sandbox command exposes the same mechanism outside an agent session: codex sandbox --permission-profile dev -- <command> runs any command under a profile. OpenAI's own example is testing that a malicious VS Code auto-formatter cannot write to .vscode. The same trick locks down MCP servers — wrap the npx launch command so a memory server can only write to its own data directory and the npm cache, with no network at all.
The honest part: what it does not stop
OpenAI does not oversell this. The post concedes that "harmful actions are still possible." Its example: the agent could plant malicious code in a locally installed package like node_modules/prettier. That change would not even show up in git status, since node_modules is usually ignored — and the next time your editor runs Prettier on save, the code executes outside the sandbox entirely.
An independent check of the released CLI (0.170.0) reproduced nearly everything the post claims, and found two more gaps the post does not mention. On Windows, the built-in protection for .git, .codex, .agents, and .aws only covers folders that already exist — in a fresh workspace without them, the sandboxed command created all four. And hard links created before a run keep their own permissions, letting a sandboxed command modify a file inside .git or outside the workspace through a pre-existing link.
None of that makes the sandbox useless. It makes the design philosophy clear: the sandbox limits what commands can access, while training and alignment are supposed to make the model use that access as intended. Defense in depth, not a single wall.
What to do with this
-
Test your profile before trusting it. Run
codex sandboxagainst the exact profile you use, and try the operations you want blocked — writing to.git/hooks, reading**/*.env, reaching an unlisted domain. -
Deny secrets explicitly. Broad reads are the default tradeoff, so add deny rules for
.envfiles and credential directories rather than assuming the workspace boundary protects them. - Treat the sandbox as one layer. Keep the approval policy on for anything outside the workspace, and remember that anything your editor or toolchain runs later is outside the sandbox's reach.
The most useful thing about OpenAI's post is not that Codex has a sandbox — every serious agent does. It is that the team published the mechanism, the tradeoffs, and the failure modes in enough detail for someone else to check. The independent check found real gaps, and that is exactly the point: a sandbox you can verify is worth more than a sandbox you have to take on trust.
Source: Michael Bolin, "Inside the Codex sandbox", OpenAI, November 18, 2026.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.