Codex Sandboxes the Commands Its Model Runs. Your MCP Servers Run Outside the Fence.
OpenAI's own sandbox write-up admits the gap. Here is how to close it with one permission profile per server.
Coding agents have gotten careful about the commands they type. Codex, OpenAI's coding agent, runs the shell commands the model asks for inside a sandbox that, on its default profile, blocks the network and keeps your Git hooks (scripts Git runs automatically on commit) read-only. That care stops at a line most people never look at.
The tools you plug into the agent sit on the other side of it.
On November 18, OpenAI published Inside the Codex sandbox, a long engineering post on how Codex fences commands on macOS, Linux and Windows. Halfway down is a sentence worth reading twice. For a stdio MCP server configured in config.toml (a tool server Codex starts as a local program from its settings file), Codex "does not attempt to sandbox the command used to start the server." The reason is reasonable. Codex can't guess which files or network services a given server needs, so a default fence could break a working setup.
The result is less comfortable. Unless you wrapped it in something yourself, every stdio MCP server in your Codex config runs with your full user permissions. It can read your SSH keys, write anywhere you can write, and talk to any host on the internet.
Here's the shift, stated plainly. The sandbox protects you from the model. It does nothing about the plugins. And the fix OpenAI shows is short enough to apply this afternoon.
What the Codex sandbox actually does
A sandbox is a set of rules the operating system enforces on a running program: which folders it can read, which it can write, whether it can open a network connection. Think of it as a hotel key card. The card opens your room and the gym. It doesn't open the room next door, no matter how politely the guest asks.
Codex doesn't run commands in Docker or a virtual machine. It uses the sandbox each operating system already ships: Seatbelt on macOS, bubblewrap plus a system-call filter called seccomp on Linux, and, on Windows, a move to Microsoft's MXC library that the post says is in progress. The upside is practical. Codex can run your iOS build tools or your local database client directly, because it works on your real machine instead of a copy.
You control the rules through permission profiles, named sets of filesystem and network rules in Codex's config.toml. The built-in :workspace profile is the default most people use. Per the post, it:
- lets commands write inside your project, while keeping
.gitand.codexread-only, so the agent can't plant a Git hook or rewrite its own config - allows broad reads across the machine, because compilers and SDKs live outside your repo
- turns the network off, which blocks uploads and also blocks
npm install
That third rule does more than it looks like. A command that can read your API keys but can't reach the internet has nowhere to send them.
Every child process inherits the same limits, even ones that outlive the command that started them. So a script that spawns a background helper doesn't escape the fence by accident.
The gap: MCP servers start outside the fence
MCP, the Model Context Protocol, is the plug standard agents use for tools. A "stdio" MCP server is a small program the agent launches on your machine and talks to through standard input and output. The memory server, the filesystem server, the Postgres server you set up last month: most local MCP servers work this way. (Remote MCP servers that Codex reaches over the network are a different case; this article is about the ones it starts on your machine.)
Here's the standard way the post shows a memory server configured for Codex:
[mcp_servers.memory]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-memory@1.0.0"]
[mcp_servers.memory.env]
MEMORY_FILE_PATH = "~/mcp-data/memory.jsonl"
That npx command runs unsandboxed. In OpenAI's words, it "can write files and make network requests with the same permissions as the user running Codex, which is overly permissive."
Why does this matter more than it sounds? Two reasons.
First, npx -y downloads and runs whatever that package name resolves to. A pinned version helps. An unpinned name means you're trusting the registry and every future release, every time Codex starts.
Second, MCP servers take input that comes, one way or another, from the model, and the model reads web pages, issues and files you didn't write. A server with a bug in how it handles paths, or a dependency that turned malicious, is running with your keys within reach and an open network.
The sandbox post is honest about a smaller version of this problem too. Even inside the :workspace fence, an agent could tamper with a package in node_modules, a folder Git usually ignores, and your editor might run that tampered copy on save, outside any sandbox. The post's answer is "defense in depth": several layers, each covering for the others. MCP servers are a layer most setups simply don't have.
The fix: wrap the server in codex sandbox
The Codex CLI includes a codex sandbox command that runs any program under a permission profile. OpenAI built it so you can test profiles, and so you can use the same fence in your own tools. That second use is the one we want.
The pattern from the post has three pieces.
1. Write a profile for the server. Give it read access broadly (Node needs its runtime and config), write access only to its data folder and the npm cache, and no network:
[permissions.memory-mcp.filesystem]
":root" = "read"
"~/.npm" = "write"
"~/mcp-data" = "write"
[permissions.memory-mcp.network]
enabled = false
2. Change the launch command. Instead of starting npx directly, start codex and let it start npx inside the fence:
[mcp_servers.memory]
command = "codex"
args = [
"sandbox", "--permission-profile", "memory-mcp", "--",
"npx", "--offline", "@modelcontextprotocol/server-memory@1.0.0"
]
[mcp_servers.memory.env]
MEMORY_FILE_PATH = "~/mcp-data/memory.jsonl"
3. Prepare the server once, with the network on. The fenced server can't download anything, so cache it first and create its folder:
mkdir -p ~/mcp-data
npx -y --package=@modelcontextprotocol/server-memory@1.0.0 -c true
The --offline flag tells npx to use the cache instead of the registry. The mkdir matters because, as the post notes, the sandbox can write to that folder but cannot create it.
What do you get? The memory server can still do its job: read what Node needs, write its memory file. It can't phone home, can't touch your project, and can't write to your shell startup files.
Test the fence before you trust it
A profile you haven't tested is a guess. codex sandbox makes testing cheap, because you can run any one-off command under the same rules.
Try the things the server should never do:
# Should fail: writing outside the allowed folders
codex sandbox --permission-profile memory-mcp -- \
bash -c 'echo test > ~/should-not-exist.txt'
# Should fail: reaching the network
codex sandbox --permission-profile memory-mcp -- \
curl -sI https://example.com
OpenAI's post runs the same kind of test with a different profile, trying to write a malicious formatter setting into .vscode/settings.json, and on macOS the write fails with Operation not permitted. That's the result you want to see. If either command above succeeds, your profile is wider than you think.
Then run the allowed path once: start Codex, call the memory tool, and confirm the file in ~/mcp-data changes.
When a server needs the network
Plenty of MCP servers exist to talk to something remote: GitHub, a database, a search API. Turning the network off isn't an option for those, and turning it fully on puts you back where you started.
Codex has a middle setting. With the network proxy on, a profile can allow a list of domains and block the rest. The permissions docs spell out a trap here: setting network.enabled = true by itself grants direct, unrestricted access. Domain rules only take effect when you also set features.network_proxy = true:
[features]
network_proxy = true
[permissions.github-mcp.network]
enabled = true
[permissions.github-mcp.network.domains]
"api.github.com" = "allow"
Get this wrong and the config reads as locked down while the server can reach anything. Test it the same way: a curl to an unlisted host should fail.
The proxy has a further limit the post names directly: broad wildcard rules or access to DNS services can still allow data to leak out through DNS lookups. A tight allowlist of exact hostnames beats *.
Put this into practice
Here's the lowest-friction path, in order.
- List what you run. Open
~/.codex/config.tomland every project-level config, and write down each[mcp_servers.*]entry with acommand. Those are the processes running outside the fence. - Pin versions. Replace bare package names with exact versions you've looked at. The post pins
@modelcontextprotocol/server-memory@1.0.0; the npm registry lists newer releases (2.2.1 as of November 18), so pin whichever version you've actually reviewed. - Start with the server that needs the least. A memory or notes server that writes one file and never calls out is the easiest win. Copy the three-step pattern above.
- Run the failure tests. One write outside the allowed folders, one network call. Both should fail.
- Do network servers next, with the proxy on and exact domains.
- If you run a team, put the profiles in a shared config layer. Codex merges config files table by table, so a team can add entries without copying the whole profile, and admins can limit which profiles people may select through
requirements.toml.
Budget about fifteen minutes for the first server. Most of that is finding the folders it actually writes to.
Honest limitations
This isn't a finished security story, and it's worth being clear about where it stops.
- You can switch the fence off. The built-in
:danger-full-accessprofile removes local sandbox restrictions, so "Codex sandboxes its commands" holds only for the profiles that keep them. - Permission profiles are labeled beta in the docs, and they don't combine with the older
sandbox_modesettings. If any loaded config usessandbox_mode, Codex falls back to those instead. - Broad reads stay broad. The example profile reads from
:root. A server fenced this way can still read files it shouldn't need. You can adddenyrules for paths like~/.ssh, but you have to know to add them. - Glob denies are a snapshot. On Linux, WSL and Windows, deny rules written as patterns are expanded when each sandboxed process starts. A matching file created later stays readable to a server that's already running.
- This only covers Codex. Other agent tools that launch MCP servers have their own rules, and a profile in Codex's config does nothing for them.
- It doesn't judge trust. A sandbox limits what a server can touch. It can't tell you whether the server's answers are honest, or whether an allowed domain is safe.
None of that is a reason to skip it. A fence with known gaps beats no fence.
The question to ask about every tool
The interesting part of OpenAI's post isn't the Seatbelt profiles or the seccomp filters. It's the admission that the agent's careful boundary was drawn around the model's commands, and the tools sitting next to it were left outside on purpose.
That makes it your call. Open your config, count the servers, and pick one to fence today. Then ask the same question of every tool you add next: if this program went bad tomorrow, what could it reach?
Sources: OpenAI, Inside the Codex sandbox (November 18, 2026), Codex permissions documentation, npm registry, @modelcontextprotocol/server-memory.