---
title: "Codex Sandbox: Profiles & OS Security Check"
description: "Audit Codex sandbox profiles in config.toml and MCP rules before running AI coding agents on production repos."
canonical: "https://buildwithjit.com/articles/codex-sandbox-permission-profiles-security-check"
date: "Nov 27, 2026"
updated: "2026-12-03T12:09:15.209374"
category: "AI Coding Agents"
tags: [codex sandbox, AI coding agents, config.toml, agent security, bubblewrap, MCP]
---

# Codex Sandbox: Profiles & OS Security Check

When an AI coding agent runs shell commands directly on your laptop, approval prompts alone do not keep your machine safe. After clicking "Approve" twenty times in a row, developers stop reading the diff, and one bad command can overwrite `.git/hooks`, modify agent config files, or exfiltrate local API keys. The **Codex sandbox** solves this by replacing trust-based prompting with OS-level technical enforcement.

On **November 18, 2026**, OpenAI published a deep architectural breakdown (*Inside the Codex sandbox*) detailing how Codex isolates spawned commands across macOS, Linux/WSL2, and Windows, how custom `config.toml` permission profiles work, and how you can reuse the standalone `codex sandbox` CLI to lock down third-party tools like local MCP servers. Here is what the default `:workspace` boundary actually protects, where its tradeoffs sit, and a practical hardening check you can apply to your own developer machine today.

## How the Codex sandbox works with approval policies

A common mistake when configuring coding agents is confusing **sandboxing** with **approval policies**. OpenAI's architecture treats them as two distinct layers that work together:

* **The sandbox defines the hard technical boundary:** Every command the agent spawns, `git`, `npm`, `pytest`, `python`, or custom build scripts, inherits OS-level filesystem and network restrictions, not just built-in file-editing tools.
* **The approval policy defines when the agent must stop and ask:** As long as an action stays inside the active sandbox boundary, the agent works autonomously without nagging you. When a task requires crossing the boundary (for example, fetching a package from the internet or editing a file outside your workspace), the approval policy (`on-request` with manual approval or `auto_review`) decides whether to pause or allow it.

That separation is what cuts down approval fatigue without turning your coding agent into a root shell.

---

## Inside the default `:workspace` profile (and the hidden read tradeoff)

If you run Codex CLI or the IDE extension on a Git repository without writing custom rules, the built-in `:workspace` permission profile applies three core rules:

1. **Workspace-only writes with protected control folders:** The agent can create and edit source files inside your repository root, while sensitive control directories, specifically **`.git`** (including `.git/hooks`), **`.codex`** (including `.codex/config.toml`), and **`.agents`**, stay **read-only**. This stops a compromised prompt from rewriting your sandbox config or planting malicious Git hooks.
2. **Network access disabled by default:** Outbound internet connections are blocked. Even if an agent reads sensitive local text, it cannot upload that data to an external server without explicit network permissions or approval.
3. **Broad filesystem reads (the critical tradeoff):** Compilers, language runtimes, SDKs, and package caches live outside your repository. Locking reads strictly to the repo would break normal builds, so `:workspace` permits broad reads governed by your normal OS user permissions. **The tradeoff:** sensitive files elsewhere on your machine, or `.env` and `.pem` files sitting inside your workspace, remain readable unless you explicitly deny them.

Understanding that third point is why every developer working with real API keys or production credentials should customize `config.toml` instead of stopping at the defaults.

---

## How the Codex sandbox enforces limits on macOS, Linux, and Windows

Rather than spinning up a heavy Docker container for every local shell command, OpenAI's harness exposes a single internal API (`spawn_command_under_sandbox()`) backed by native kernel and OS primitives on each operating system:

| Platform | Native Enforcement Engine | How Network & Writes Are Enforced | Setup Requirement |
|:--- |:--- |:--- |:--- |
| **macOS** | **Seatbelt** (`sandbox-exec` / Sandbox Profile Language) | Generates OS-enforced Seatbelt profiles restricting writes to workspace roots and blocking direct network calls | Works out of the box |
| **Linux & WSL2** | **Bubblewrap (`bwrap`)** namespaces + read-only rootfs + **seccomp** *(Landlock fallback)* | Isolates mount/network namespaces, keeps root read-only, and filters syscalls via seccomp | Install `bubblewrap` via your Linux package manager first |
| **Windows (PowerShell)** | **4-layer native architecture** (`codex.exe`, setup helper, `codex-command-runner.exe`, child process) | Runs child commands as a dedicated `CodexSandboxOffline` user with Windows Firewall outbound blocks, DPAPI-encrypted creds, synthetic `sandbox-write` SID ACLs (denying `.git`/`.codex`/`.agents`), and `CreateRestrictedToken` | One-time elevated setup via `codex-windows-sandbox-setup.exe` *(WSL2 uses Linux backend)* |

When a permission profile allows limited network access instead of full offline mode, Codex routes outbound traffic through a **shared network proxy**. The request-handling and policy logic is shared across macOS, Linux, and Windows, while proxy wiring into each sandbox stays OS-specific.

> **Local OS sandbox vs. cloud microVM:** Native OS sandboxes are built for fast, low-friction local coding on a single developer machine. If you are running multi-tenant or fully untrusted autonomous agents in production cloud infrastructure, pair this approach with our breakdown of [AI agent sandbox isolation (microVM vs. container)](/articles/ai-agent-sandbox-microvm-vs-container-check).

---

## Locking down Codex sandbox permissions in `config.toml`

You can inspect or switch profiles interactively inside the CLI using `/permissions`, or define reusable least-privilege profiles under `[permissions]` in your `config.toml`.

Start from `:read-only` when you only want code reviews or audits, and extend `:workspace` when the agent needs to write code. Crucially, add explicit `"deny"` rules for `.env*` files, private keys, and credentials inside `:workspace_roots`:

```toml
# ~/.codex/config.toml (or project-scoped config)
approval_policy = "on-request"
approvals_reviewer = "auto_review"
default_permissions = "dev-hardened"

[features]
network_proxy = true

[permissions.dev-hardened]
description = "Allow workspace edits while blocking secret files and direct network egress."
extends = ":workspace"

[permissions.dev-hardened.filesystem]
glob_scan_max_depth = 3

[permissions.dev-hardened.filesystem.":workspace_roots"]
"**/.env*" = "deny"
"**/*.pem" = "deny"
"**/*.key" = "deny"
"**/service-account*.json" = "deny"

[permissions.dev-hardened.network]
enabled = false
```

### What this profile prevents immediately

* **Secret leakage inside the repo:** Even if a malicious dependency or prompt injection tells the agent to inspect your project config, `.env`, `.pem`, `.key`, and service-account JSON files are blocked at the sandbox layer.
* **Silent exfiltration:** With `network.enabled = false`, spawned scripts cannot phone home to arbitrary domains. When you do need temporary registry access (like `npm` or `pip`), enable network access only through the network proxy inside a scoped profile rather than switching to `Full access`.
* **Config tampering:** Because `:workspace` keeps `.codex`, `.git`, and `.agents` read-only, the agent cannot edit `config.toml` to loosen its own permissions.

---

## Bonus power feature: sandboxing local MCP servers with `codex sandbox`

One of the most useful details in OpenAI's November 18 release is that the sandbox engine is exposed independently through the **`codex sandbox`** CLI command. You can wrap *any* local script, linter, or third-party **Model Context Protocol (MCP)** server with the exact same `config.toml` permission profiles, even outside a Codex chat session.

Local `npx` MCP servers routinely run with full access to your home directory and internet connection. Using `codex sandbox`, you can pre-install the package once, grant write access to a single data directory, and strip away network access at runtime:

```bash
# 1. Create the exact folder the MCP server is allowed to write to
# (The sandbox can write inside this folder, but cannot create parent folders)
mkdir -p ~/mcp-data

# 2. Pre-install the MCP server package while online
npx -y --package=@modelcontextprotocol/server-memory@1.0.0 -c true

# 3. Launch the MCP server inside an offline, path-restricted Codex sandbox
codex sandbox --permission-profile memory-mcp -- \
  npx --no-install @modelcontextprotocol/server-memory@1.0.0
```

You can also test whether a profile blocks protected files before trusting it in automation:

```bash
# Quick boundary smoke test: trying to overwrite a protected editor config
codex sandbox --permission-profile dev-hardened -- \
  bash -c 'echo "{}" > .vscode/settings.json'
```

If your team builds or consumes MCP tooling across both local developer machines and remote servers, combine this local wrapping pattern with our [MCP stateless spec and server session audit](/articles/mcp-stateless-spec-session-check-your-server).

---

## 5-point Codex sandbox check before running autonomous loops

Run through this checklist on every workstation or CI runner where Codex CLI executes code:

| # | Check | What to Verify | Safe State |
|:--- |:--- |:--- |:--- |
| **1** | **Active OS backend** | On Linux/WSL2, verify `which bwrap` returns a path; on Windows PowerShell, confirm the elevated sandbox setup completed | Native enforcement active (never silently running unsandboxed) |
| **2** | **Default permission mode** | Run `/permissions` in CLI or inspect `default_permissions` in `config.toml` | `:read-only` or a hardened custom profile extending `:workspace`, never `Full access` |
| **3** | **Secret file exclusions** | Check `[permissions.<name>.filesystem.":workspace_roots"]` | Explicit `"deny"` rules for `**/.env*`, `**/*.pem`, `**/*.key`, and cloud credential JSONs |
| **4** | **Network & localhost rules** | Check `[permissions.<name>.network]` and `[features] network_proxy` | Network disabled by default; `allow_local_binding` left off unless an explicit local server needs it |
| **5** | **Third-party MCP wrappers** | Audit `npx` / `uvx` local MCP server commands in your client configs | Wrapped with `codex sandbox --permission-profile ...` with dedicated data folders and zero unneeded egress |

If you also run automated agent pipelines across multiple LLM providers, remember to keep your underlying model strings up to date alongside your security config, see our [AI model deprecation dates tracker for Anthropic, OpenAI, and Google](/articles/ai-model-deprecations-check-your-model-ids) and our [n8n Schedule Trigger durable scheduler check](/articles/n8n-schedule-trigger-durable-scheduler-check).

---

## Frequently asked questions

### Does the Codex sandbox block the agent from reading my `.env` file by default?
No, not automatically. The built-in `:workspace` profile restricts **writes** to the workspace (keeping `.git` and `.codex` read-only) and disables **network** access, but it allows broad filesystem **reads** so compilers and SDKs keep working. To block `.env` or `.pem` reads, extend `:workspace` in `config.toml` and explicitly set `"**/.env*" = "deny"` and `"**/*.pem" = "deny"`.

### Why do Linux and WSL2 users need to install `bubblewrap`?
On macOS, Codex uses Apple's built-in Seatbelt framework, which is preinstalled. On Linux and WSL2, Codex relies on `bubblewrap` (`bwrap`) namespaces alongside a read-only root filesystem and `seccomp` filters (with Landlock fallback) to enforce isolation, so installing `bubblewrap` from your distro's package manager ensures full sandbox enforcement.

### How does Codex sandbox commands on native Windows PowerShell?
OpenAI built a four-layer native Windows sandbox: an elevated setup helper (`codex-windows-sandbox-setup.exe`) configures a dedicated `CodexSandboxOffline` user with Windows Firewall rules blocking outbound traffic and synthetic `sandbox-write` SID ACLs (denying `.git`, `.codex`, and `.agents`), while `codex-command-runner.exe` mints a restricted token (`CreateRestrictedToken`) to spawn child commands safely. If you run Codex inside WSL2 on Windows, it uses the Linux sandbox instead.

### Can I use `codex sandbox` to isolate tools that aren't Codex?
Yes. The `codex sandbox --permission-profile <name> -- <command>` CLI command lets you run arbitrary scripts, build tools, or local `npx` MCP servers under the exact same OS-level filesystem and network limits defined in your `config.toml`.

---

## Conclusion

Safe AI coding agents are built on **enforced boundaries, not hopeful prompts**. OpenAI's November 2026 Codex sandbox design proves you do not need to trade developer speed for security: native Seatbelt, bubblewrap/seccomp, and Windows restricted-token isolation let agents edit code and run tests freely inside your workspace while keeping `.git`, `.codex`, and outbound network egress locked down.

Before your next autonomous coding session, verify that your OS backend is active (`bwrap` on Linux/WSL2 or native sandbox setup on Windows), add a hardened `config.toml` profile that explicitly denies `.env` and `.pem` files, and wrap any local third-party MCP servers with `codex sandbox`. If you want help securing AI coding workflows, sandboxing production agents, or hardening self-hosted automation infrastructure, explore our [AI engineering and automation services](/services) or look up core terms in our [AI Engineering Glossary](/glossary).

**Sources verified on Nov 27, 2026:** [OpenAI, Inside the Codex sandbox](https://openai.com/index/inside-the-codex-sandbox/), [OpenAI, Building a safe, effective sandbox to enable Codex on Windows](https://openai.com/index/building-codex-windows-sandbox/), and [OpenAI Docs, Sandboxing across ChatGPT and Codex](https://learn.chatgpt.com/docs/sandboxing).
