Starts Nov 23Live Cohort 3 of Vibe Coding & AI Agents: 3 weeks, 9 live hands-on sessionsCohort 3 (Nov 23) →
ReleaseCode / SDK · ActionableOpenAI Blog→ original

OpenAI shows how the Codex sandbox restricts agent commands on your computer

An agent that runs commands on your laptop needs boundaries, and OpenAI has shown how the Codex sandbox sets them. Instead of Docker, it uses the built-in sandboxing tools of macOS, Linux and Windows, so the agent works in your familiar environment. By default, writes are allowed only in the working folder, and the network is off. So it makes sense to create a separate permissions profile for each task rather than hand out full access.

AI-processed from OpenAI Blog; edited by Hamidun News
OpenAI shows how the Codex sandbox restricts agent commands on your computer
Source: OpenAI Blog. Collage: Hamidun News.
Listen to article
Article Fact Sheet & Key Figures
ParameterDetails
Primary sourceOpenAI Blog ↗
Editor-in-Chief
Permission profiles in config.tomlread, write or deny for each path
Key metric #2Admins pin the allowed profiles through requirements.toml
Key metric #3The codex sandbox command runs any process under the same profile

The riskiest thing a coding agent does is run commands on your computer. One bad rm or a quiet upload of files to someone else's server, and you feel the consequences immediately. OpenAI engineer Michael Bolin has broken down how the Codex sandbox works. It limits what the agent's commands can access, and it does so without virtual machines.

Why not Docker

The usual way to isolate a program is a container or a virtual machine. OpenAI took a different path: Codex uses the operating system's own sandboxing tools and restricts commands within your normal environment.

The team's argument is practical. A developer's laptop is a collection of personal settings and tools, and reproducing it in Docker is not easy. The article gives an example: you are writing an iOS app on a Mac.

Inside a container, Codex cannot run a native build or the iPhone simulator. You can hand those operations to the host, but then they run outside the sandbox and need their own restrictions. So OpenAI is investing in system-level isolation for each platform.

macOS, Linux and Windows share a single programming interface: you pass it a command and a permissions profile, and, if restricted network access is allowed, a network proxy as well. All child processes inherit the parent's restrictions, even those that outlive the original command.

What is allowed by default

The built-in :workspace profile picks cautious defaults that still let the agent do its job:

  • Writing is allowed only in the project's working folder. The .git and .codex directories stay read-only, so the agent cannot tamper with Git hooks or the Codex config.
  • Reading is allowed almost everywhere, within normal OS permissions. Compilers and build tools need libraries outside the repository. The article is upfront about the downside: files with API keys in other locations may also end up readable.
  • The network is off. This blocks direct data exfiltration, but it also prevents downloading dependencies.

OpenAI openly admits that the protection is incomplete. In theory, an agent could slip malicious code into a local package, such as node_modules/prettier. Git usually ignores such folders, and if your editor runs that Prettier when you save a file, the code executes outside the sandbox. That is why the company calls its approach "defense in depth": the sandbox limits access, while model training and alignment govern how the model uses it.

How to configure profiles

Permissions are defined in config.toml as named profiles. Each path gets read, write or deny, and a profile can inherit from a built-in one. In the example, the dev profile extends :workspace: it grants write access to ~/build-cache, makes .vscode and .devcontainer read-only, and fully blocks .env files and the secrets folder.

The network has three options: off entirely (the default), fully open (the :danger-full-access profile), or traffic routed through a proxy with per-domain rules. The rules support exact names and wildcards, and an explicit deny takes precedence over allow. Requests to all other domains are either blocked or require confirmation.

Companies get layered configuration. Tables from different config.toml files are merged recursively, while arrays are replaced wholesale. Through requirements.toml, an administrator sets a list of permitted profiles, for example allowing :read-only and forbidding :danger-full-access. Cloud requirements take priority over the local /etc/codex/requirements.toml file, and users cannot bypass the ban.

The model can also ask for more permissions for an individual command: expanded access inside the sandbox, or running outside it. The model does not make that call; the harness does. It will either ask the user or send the request to automatic review.

A sandbox for your own tools

The codex sandbox command is useful in its own right. It runs any process under a profile from the Codex config, and it is a handy way to test your own rules. In the example, an attempt to write a malicious .vscode/settings.json under the dev profile on macOS fails with "Operation not permitted".

The second idea is to isolate MCP servers. Codex does not try to restrict them itself: it does not know which files and networks a server needs. As a result, a server launched through npx runs with the user's full permissions. OpenAI suggests wrapping the command in codex sandbox with a memory-mcp profile: write access only to ~/mcp-data and ~/.npm, no network, the package pinned to a version and launched through npx --offline. The data directory and the npm cache must be prepared in advance.

The takeaway for teams: don't leave the agent with full access. Create a profile for each task, lock down secrets with deny, and test the rules against known-bad commands. If this setup seems like overkill, remember Prettier: the sandbox reduces the risk, but does not eliminate it entirely.

Story

Key Questions Answered

Why not Docker?

The usual way to isolate a program is a container or a virtual machine. OpenAI took a different path: Codex uses the operating system's own sandboxing tools and restricts commands within your normal environment. The team's argument is practical. A developer's laptop is a collection of personal settings and tools, and reproducing it in Docker is not easy. The article gives an example: you are writing an iOS app on a Mac. Inside a container, Codex cannot run a native build or the iPhone simulator.

What is allowed by default?

The built-in :workspace profile picks cautious defaults that still let the agent do its job: Writing is allowed only in the project's working folder. The .git and .codex directories stay read-only, so the agent cannot tamper with Git hooks or the Codex config. Reading is allowed almost everywhere, within normal OS permissions. Compilers and build tools need libraries outside the repository. The article is upfront about the downside: files with API keys in other locations may also end up readable.

How to configure profiles?

Permissions are defined in config.toml as named profiles. Each path gets read, write or deny, and a profile can inherit from a built-in one. In the example, the dev profile extends :workspace: it grants write access to ~/build-cache, makes .vscode and .devcontainer read-only, and fully blocks .env files and the secrets folder. The network has three options: off entirely (the default), fully open (the :danger-full-access profile), or traffic routed through a proxy with per-domain rules.

ZK
Zhemal Khamidun — CPO at Alpina Digital, product manager of AlpinaGPT. Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Hands-On AI Engineering · Hamidun Academy

Build & Ship Production AI Agents Without Boilerplate Code

Start your free 72-hour trial at Hamidun Academy (academy.hamidun.com) — interactive lessons on Claude Code & Cursor, live Tech Radar, and production agent templates.

Start 72h Free Trial →Vibe-Coding Intensive
What do you think?
Loading comments…