November 18, 2026
EngineeringInside the Codex sandbox
How Codex runs commands on your machine with limits you control.
By Michael Bolin, Member of Technical Staff
At OpenAI, we take a defense in depth(opens in a new window) approach when it comes to safeguarding agents. While our investments in training and alignment are fundamental to this effort, we also implement features in our agentic harness, Codex(opens in a new window), to provide additional protections. Because one of the most common (and potentially risky) things Codex does is run commands on your computer, we built the Codex sandbox so Codex can work in your existing environment within filesystem and network limits you control.
A (opens in a new window)sandbox(opens in a new window) limits what a program can access while it runs. For a photo-organizing task, you might configure the Codex sandbox to let commands read and modify files in ~/Pictures while blocking network access to prevent uploads. For code review, you might allow access to online documentation while keeping source files read-only. Users configure the Codex sandbox through (opens in a new window)permission profiles(opens in a new window), which define the filesystem and network restrictions for a Codex session.
In this article, we’ll start with the tradeoffs behind Codex’s sandbox defaults, then explain the sandbox’s design and how the harness uses it to run commands. We’ll show how end users and enterprises can tailor its permissions to their needs and how developers can reuse the sandbox in their own tools. Finally, we’ll examine how these restrictions are enforced on macOS, Linux, and Windows.
Choosing the sandbox boundaries
In Codex, our philosophy is to specify conservative defaults for the sandbox that still enable meaningful work. For example, with a Git repository as the workspace root, the built-in :workspace permission profile:
Allows writes within the workspace, while keeping directories such as
.gitand.codexread-only. This lets Codex edit source code without seeking permission for every change, while preventing direct changes to.codex/config.tomlor Git hooks under.git/hooks.Allows broad filesystem reads, subject to the user’s existing OS permissions. Compilers, runtimes, and build tools depend on SDKs, libraries, and configuration outside the repository. Restricting reads to the workspace would break many ordinary workflows. The tradeoff is that sensitive files elsewhere on the machine may also remain readable (such as config files containing API keys).
Disables network access. This blocks direct uploads to external services, including attempts to exfiltrate data the command can read. It also prevents legitimate operations such as downloading dependencies, which require additional access.
These restrictions prevent a large class of bad behavior, but harmful actions are still possible. For example, the agent could inject malicious code into a locally installed package such as node_modules/prettier. Such a change might not appear in git status because node_modules is often ignored by Git. If the user’s editor runs that copy of Prettier on save, simply saving a file could execute the malicious code outside the Codex sandbox. This is why we take a defense in depth approach: the sandbox limits what commands can access, while training and alignment help the model use that access in accordance with the user’s intent.
For guidance on tailoring sandbox permissions and combining them with other protections in an enterprise environment, see the Codex security cookbook(opens in a new window).
Designing the sandbox
Virtual machines and containers(opens in a new window) are two popular mechanisms used for sandboxing, but we take a different approach with the Codex sandbox. Instead of moving computation to a separate environment to provide isolation, Codex uses each platform’s sandboxing facilities to constrain commands running in the user’s existing environment.
For many developers, their laptop serves as a bespoke dev environment that they can change on a whim. Reproducing that environment in a Docker container can take work, and some workflows still depend on tools that run on the host.
For example, consider using Codex to develop an iOS app on a Mac. If you decided to sandbox Codex by running it inside Docker, Codex would not be able to run the iOS build toolchain composed of native Mac executables, nor could it launch the iPhone simulator to run the code. A Docker-based workflow could delegate builds and simulator operations to the Mac host, but those operations would execute outside the container’s sandbox and would need their own restrictions. For Codex, we prefer to keep things simple by investing heavily in OS-specific sandboxing so Codex can run in the environment that is most appropriate to the task at hand.
The harness exposes these OS-specific sandboxing mechanisms through a common API across macOS, Windows, and Linux. This API takes a command and a permission profile. If the permission profile allows limited network access, the caller must supply a network proxy to enforce those limits:
Python
12def spawn_command_under_sandbox(3 program_and_args: list[str],4 cwd: Path,5 env: dict[str, str],6 permission_profile: PermissionProfile,7 network_proxy: NetworkProxy | None,8) -> Child:
This function starts the process in a sandbox and returns a Child handle the harness can use to wait for it to finish. Each child process inherits its parent’s sandbox constraints, so those restrictions apply throughout the process tree initiated by the command, even to descendants that outlive the original process.
The following diagram shows how these pieces fit together, from configuration to running a sandboxed command. The sections that follow explain each stage.

How the harness leverages the sandbox
As explained in Unrolling the Codex Agent Loop, the Codex harness is responsible for executing tool calls generated by the model. For coding tasks, the most commonly used tool is a shell tool, which runs commands much as a user would in an interactive shell such as Bash. Here we’ll examine the one-shot (opens in a new window)exec_command(opens in a new window) shell tool(opens in a new window) to illustrate how the harness employs the sandbox to achieve the desired protections.
This is a simplified version of how the exec_command tool call would be honored by the Codex harness without sandboxing:
Python
12
3class ExecCommandToolCall:4 cmd: str5 workdir: str | None = None6 shell: str | None = None7 login: bool = True8 timeout_ms: int = 10_0009
10
11def perform_exec_command(tool_call: ExecCommandToolCall):12 program_and_args = [13 tool_call.shell or os.environ.get("SHELL") or "/bin/sh",14 "-lc" if tool_call.login else "-c",15 tool_call.cmd,16 ]17 child = subprocess.Popen(18 program_and_args,19 20 cwd=Path(tool_call.workdir or ".").absolute(),21 stdout=subprocess.PIPE,22 stderr=subprocess.STDOUT,23 )24 output, exit_code = collect_output(child, timeout_ms=tool_call.timeout_ms)25 return {"output": output, "exit_code": exit_code}
To sandbox the command, the harness replaces the call to subprocess.Popen() with spawn_command_under_sandbox(). The harness supplies the permission profile and, when needed, the network proxy:
Python
12
3def perform_exec_command_with_sandboxing(4 tool_call: ExecCommandToolCall,5 permission_profile: PermissionProfile,6 network_proxy: NetworkProxy | None,7):8 9 child = spawn_command_under_sandbox(10 program_and_args=program_and_args,11 cwd=Path(tool_call.workdir or ".").absolute(),12 env=os.environ.copy(),13 permission_profile=permission_profile,14 network_proxy=network_proxy,15 )16 output, exit_code = collect_output(child, timeout_ms=tool_call.timeout_ms)17 return {"output": output, "exit_code": exit_code}
The exec_command tool also lets the model request different permissions for an individual command, but the harness decides whether to grant the request:
Python
1class ExecCommandToolCall:2 3
4 5 sandbox_permissions: Literal[6 "use_default",7 "with_additional_permissions",8 "require_escalated",9 ] = "use_default"10
11 12 justification: str | None = None13
14 15 16 additional_permissions: AdditionalPermissions | None = None
When use_default is specified, the harness uses the default sandbox config for the turn. with_additional_permissions requests expanded access within the sandbox, while require_escalated requests execution outside it. The harness evaluates the request based on the user’s preferences before executing the command. (For example, Codex may prompt the user directly, or it might route the request to auto-review(opens in a new window).) If execution is authorized, Codex will pass the appropriate permission_profile and network_proxy to perform_exec_command_with_sandboxing() with the command arguments from the original ExecCommandToolCall.
The shell tool is the primary consumer of spawn_command_under_sandbox(), and the harness also reuses its sandboxing infrastructure for operations such as reading and modifying local files. This reuse extends beyond the harness: the codex sandbox command lets you incorporate sandboxed command execution into your own tools, as we’ll see later. Next, we’ll look at how permission profiles are defined.
Configuring the sandbox
A named permission profile lets you reuse the same filesystem and network restrictions across projects. You can define your own profiles under [permissions] in config.toml. For example, the following defines a profile named dev that extends(opens in a new window) the built-in :workspace profile:
TOML
12default_permissions = "dev"3
4[permissions.dev]56description = "Development with extra read-only protections."7
8910extends = ":workspace"11
12[permissions.dev.filesystem]13"~/build-cache" = "write"14
15[permissions.dev.filesystem.":workspace_roots"]16".devcontainer" = "read"17".vscode" = "read"18"**/*.env" = "deny"19"secrets" = "deny"
The dev profile adds write access to ~/build-cache and places additional restrictions on files in the workspace. Filesystem entries can grant read-only access (read), grant read and write access (write), or block access entirely (deny).
The :workspace_roots table lets you define rules for paths relative to a project’s workspace roots. By default, the Codex CLI uses its working directory as its sole workspace root, while the ChatGPT desktop app uses the project’s source folders. Codex applies each rule to every root, so the .vscode entry in dev makes the .vscode directory read-only under each root.
In addition to its own rules, dev inherits the following protections from :workspace:
TOML
1[permissions.":workspace".filesystem.":workspace_roots"]2".agents" = "read"3".aws" = "read"4".codex" = "read"5".git" = "read"
Network permissions
When it comes to configuring the network for the sandbox in Codex, there are roughly three options:
Disable all network access (default for the
:workspaceprofile)Enable full, direct network access (default for the
:danger-full-accessprofile)Restrict network access to a proxy, which decides what to let through based on the permission profile
To give dev direct network access, set permissions.dev.network.enabled = true at the top level of config.toml. This grants full network access when the network proxy is disabled.
To restrict dev to a set of domains, enable the network proxy and configure its domain rules:
TOML
1[permissions.dev.network]2enabled = true3
4[permissions.dev.network.domains]5"*.openai.com" = "allow"67"localhost" = "allow"8"127.0.0.1" = "allow"9"::1" = "allow"10"evil.example" = "deny"11
12[features]131415network_proxy = true
Domain rules support exact names and wildcard patterns, with explicit deny rules taking precedence over allow rules. Requests to other domains require approval or are blocked, as described in Network proxy below.
Layering configuration and enforcing limits
Individual users can configure defaults that apply across projects and override them for a particular trusted project. Enterprise administrators may also want to configure defaults for their users and constrain which settings those users can change. Codex supports both through layered configuration and managed requirements.
As described in Configuration precedence,(opens in a new window) Codex merges settings from multiple config.toml files. Tables are merged recursively, with the higher-precedence source winning when values conflict. Arrays are replaced as a whole.
This is why permission profiles use tables for filesystem paths and network domains. A team can add or override individual entries in its own configuration and automatically inherit changes to all other entries in the organization’s base configuration:
TOML
1[permissions.dev.filesystem.":workspace_roots"]2".idea" = "read"3
4[permissions.dev.network.domains]5"example.com" = "allow"
Administrators can also supply managed requirements(opens in a new window) through requirements.toml to constrain users’ configuration choices. These requirements can come from multiple sources, including system files and cloud-provided policy. A common use case is to specify allowed_permission_profiles to constrain the set of permission profiles an enterprise user can select. For example, an administrator could specify these cloud requirements:
TOML
1default_permissions = ":read-only"2
3[allowed_permission_profiles]4":read-only" = true5":danger-full-access" = false
The cloud requirements would take precedence over the system requirements file at /etc/codex/requirements.toml, so an entry in that file cannot override the explicit ":danger-full-access" = false above. Leaving :workspace unspecified allows another requirements layer to supply that entry. Profiles whose entries are false or absent from the final merged table are unavailable.
This separation lets organizations enforce limits while users tailor their configuration within those limits. The resulting permission profiles can be used by the harness or applied directly to a command, as we’ll see next.
Using the codex sandbox command
The Codex CLI provides a sandbox command to facilitate running an arbitrary command under a permission profile defined in the Codex config. This is commonly used to test out the profile, ensuring that the sandbox prevents the behavior it was designed to block.
For example, the following command attempts to configure VS Code to run a malicious auto-formatter on save. Assuming .vscode already exists, the dev profile defined above should block this write because that directory is read-only (codex sandbox treats cwd as a workspace root by default):
Bash
1codex sandbox --permission-profile dev -- \2 bash -c 'cat > .vscode/settings.json' <<'JSON'3{4 "prettier.prettierPath": "./node_modules/evil-prettier",5 "[typescript]": {6 "editor.defaultFormatter": "esbenp.prettier-vscode",7 "editor.formatOnSave": true8 }9}10JSON
Indeed, on macOS this fails with:
Plain text
1bash: .vscode/settings.json: Operation not permitted
The codex sandbox command makes Codex’s sandboxing mechanism available independently of an agent session. You can use the same configuration language and platform-specific enforcement to constrain commands launched by your own tools.
Example: sandboxing an MCP server
For a stdio MCP server configured in config.toml, the Codex harness does not attempt to sandbox the command used to start the server. Codex cannot reliably infer which files or network services that server needs, so applying a default sandbox profile could break an otherwise valid configuration.
For example, the standard way to configure the @modelcontextprotocol/server-memory(opens in a new window) MCP server for use with Codex is as follows:
TOML
1[mcp_servers.memory]2command = "npx"3args = [4 "-y",5 "@modelcontextprotocol/[email protected]"6]7
8[mcp_servers.memory.env]9MEMORY_FILE_PATH = "~/mcp-data/memory.jsonl"
Because this npx command runs unsandboxed, it can write files and make network requests with the same permissions as the user running Codex, which is overly permissive. To lock it down, we can define a permission profile named memory-mcp and then wrap the original npx command with codex sandbox --permission-profile memory-mcp to limit where the server can write and to prevent it from accessing the network:
TOML
1[permissions.memory-mcp.filesystem]23":root" = "read"4"~/.npm" = "write"5"~/mcp-data" = "write"6
7[permissions.memory-mcp.network]8enabled = false9
10[mcp_servers.memory]11command = "codex"12args = [13 "sandbox",14 "--permission-profile",15 "memory-mcp",16 "--",17 "npx",18 "--offline",19 "@modelcontextprotocol/[email protected]"20]21
22[mcp_servers.memory.env]23MEMORY_FILE_PATH = "~/mcp-data/memory.jsonl"
Before starting the server, create its data directory and populate the npm cache with the pinned package. That lets npx --offline launch the server under a profile that disables network access:
Bash
12mkdir -p ~/mcp-data3
45npx -y --package=@modelcontextprotocol/[email protected] -c true
Once the package is cached, Codex can start the memory server without network access, with writes limited to the npm cache and the server’s data directory.
Codex sandbox implementation
The sandbox implementation turns a permission profile into restrictions enforced by the operating system. The network proxy’s core request-handling and policy logic is shared across all three major operating systems, while proxy setup and integration with the sandbox are OS-specific. We’ll examine the shared proxy first, followed by the implementations for macOS, Linux, and Windows.
Network proxy
To enforce a permission profile’s network restrictions, the harness starts a network proxy and configures the sandbox to allow connections to it while blocking direct connections to external hosts. The proxy checks each request against the profile’s domain rules to determine whether to forward it.
In the Codex repo, the network proxy is implemented in the codex-network-proxy(opens in a new window) crate, which the harness uses as a library, though it can also be built as a standalone CLI(opens in a new window). When enabled, codex-network-proxy starts both an HTTP proxy and a SOCKS5 proxy by default. These proxy addresses are communicated to the process spawned by the sandbox via environment variables. In addition to injecting standard environment variables such as HTTP_PROXY, HTTPS_PROXY, and ALL_PROXY, a number of well-known application-specific environment variables(opens in a new window) (such as PIP_PROXY) are injected, as well. Admittedly, not all programs honor these environment variables. If a program attempts a direct connection to an external host, the operating system’s sandbox restrictions block it, as described in the platform-specific sections below.
The network proxy is responsible for implementing the network restrictions defined in a permission profile. For example, the dev profile shown earlier allows requests to *.openai.com and explicitly denies requests to evil.example. When a request targets a domain that does not match an allow or deny rule, the proxy can suspend the request while it delegates to the harness for approval. Like the shell command example, Codex may prompt the user directly, or it might route the request to auto-review(opens in a new window). Upon receiving a decision, the proxy either allows the request to proceed or rejects it with an error response.
The order matters here because even a DNS lookup can leak information encoded in a hostname. The proxy therefore resolves the requested hostname only after determining that it is allowed or approved. Note that broad wildcard rules or access to DNS services can still permit DNS-based exfiltration.
macOS
On macOS, Codex uses Seatbelt(opens in a new window), Apple’s kernel-enforced sandboxing mechanism. Seatbelt policies are written in Sandbox Profile Language (SBPL), a Scheme-based language for expressing sandbox restrictions. Codex invokes Seatbelt through macOS’s /usr/bin/sandbox-exec command. Like codex sandbox, it takes options describing the sandbox followed by the command to run:
Bash
1sandbox-exec -p PROFILE [-Dkey=value]* -- PROG ARGS...
The PROFILE is a string of SBPL that contains entries that configure the sandbox. For example, the following SBPL snippet makes /dev/null and /dev/zero readable and writable under the sandbox policy:
Scheme
1(allow file-read* file-test-existence file-write-data2 (literal "/dev/null")3 (literal "/dev/zero"))
When the network proxy is enabled as part of a sandbox invocation, rules like the following are injected into the profile to limit connections to the appropriate local ports:
Scheme
12(allow network-outbound (remote ip "localhost:3128"))3
45(allow network-outbound (remote ip "localhost:8081"))
Codex’s base profile starts with (deny default), so outbound connections remain blocked unless explicitly allowed.
Finally, the SBPL can contain placeholders using (param):
Scheme
12(deny file-write-unlink3 (require-all4 (literal (param "WRITABLE_ROOT_0"))5 (vnode-type DIRECTORY)))
which are populated by the -Dkey=value options passed to sandbox-exec.
To implement its own sandbox API, Codex builds up the list of arguments(opens in a new window) to sandbox-exec starting from a base policy(opens in a new window), and then uses permission_profile and other context to amend it to produce the complete Seatbelt profile. The resulting profile and accompanying -D arguments configure the restrictions enforced by Seatbelt, while the network proxy enforces additional network rules. With the full arg list assembled, the invocation of sandbox-exec is straightforward.
Generating the correct SBPL is challenging because Apple does not document the language for third-party use. Indeed, man sandbox-exec states The sandbox-exec command is DEPRECATED (as is the sandbox_init() library function documented via man 3 sandbox_init). Despite the deprecation warning, macOS still ships Seatbelt profiles in /usr/share/sandbox, and third-party software, including Google Chrome and Chromium(opens in a new window), continues to rely on Seatbelt. As such, we plan to continue to use Seatbelt for the foreseeable future.
Linux
To create the sandbox on Linux, Codex uses a combination of bubblewrap(opens in a new window) (bwrap), a command-line tool for constructing isolated environments, and seccomp-bpf(opens in a new window), a Linux kernel mechanism for filtering system calls. An internal helper named codex-linux-sandbox coordinates the setup. Like sandbox-exec on macOS, it takes a sandbox configuration followed by a command to run:
Bash
1codex-linux-sandbox SANDBOX_ARGS... -- PROG ARGS...
When filesystem isolation or proxy routing is required, codex-linux-sandbox invokes bwrap to create the initial sandbox environment. bwrap then launches codex-linux-sandbox --apply-seccomp-then-exec inside it. This second invocation uses seccomp-bpf to apply additional restrictions before running the user’s command.
To construct that initial sandbox environment, Codex uses bubblewrap to create a filesystem view in a separate mount namespace that reflects the permission profile’s filesystem rules. Because this is fundamental to the sandbox implementation, Codex vendors its own copy of bwrap in case the user has not installed their own, but it prefers a compatible installation of (opens in a new window)bwrap(opens in a new window) found on PATH, when available. Empirically, some Linux distributions disable access to user namespaces by default(opens in a new window), but grant an exception for the system bwrap.
Also like sandbox-exec, bwrap takes a sandbox configuration followed by a command to run within the sandbox. Instead of using a custom config language like SBPL, bwrap uses individual flags for configuration. Codex uses the following options to create the filesystem view:
--bindto specify a writable file or directory--ro-bindto specify a read-only file or directory--perms 000 --tmpfs DIR --remount-ro DIRto deny access toDIR--perms 000 --ro-bind-data FD FILEto deny access toFILE(whereFDis an open file descriptor to/dev/null)
To apply deny globs using these options, Codex expands them to concrete paths before launching each command. New matching paths are not automatically added to that command’s sandbox restrictions.
Codex also specifies options such as --unshare-ipc and --unshare-pid to prevent the sandbox from accessing other types of resources on the host, so bubblewrap affects more than just file visibility.
When using bubblewrap, Codex passes --unshare-net whenever networking is disabled or connections must go through the network proxy, which will create a new network namespace for the sandbox. We then use seccomp-bpf to apply additional restrictions on the networking system calls and socket families available to the command.
Specifically, we use the seccompiler crate(opens in a new window) to dynamically compile a BPF program based on the desired filters(opens in a new window) and apply it to a launcher process in the sandbox so the constraints are inherited by the entire process tree. As such, bwrap does not run the user’s command, but runs the codex-linux-sandbox launcher with its own config args followed by the user’s command:
Bash
1bwrap BWRAP_ARGS... -- \2 codex-linux-sandbox --apply-seccomp-then-exec CODEX_LINUX_SANDBOX_ARGS... -- \3 PROG ARGS...
To apply seccomp filters without elevated privileges, the launcher sets Linux’s no_new_privs flag(opens in a new window). This flag is inherited by child processes and prevents them from gaining additional privileges when executing another program, such as a setuid executable.
The seccomp filters depend on the network configuration. When network access is disabled, we block a number of network-related syscalls, such as connect(2) and bind(2). Though when the network proxy is enabled in the sandbox, we allow IP sockets so the TCP listener created by codex-linux-sandbox can be reached, but block the creation of standalone Unix domain sockets by default, as those could enable inadvertent access to resources from the host.
Connecting to the network proxy
When the sandbox configuration merits the use of the network proxy, the Codex harness creates one instance of the proxy that can be reused across multiple invocations of codex-linux-sandbox within the same Codex thread. Each sandbox needs a way to reach that shared proxy from its isolated network namespace. Codex provides a loopback TCP listener inside that namespace and arranges for a process outside the sandbox to accept its connections and relay them to the proxy.
The following diagrams illustrate this setup for one proxy endpoint, with one connection through it shown in the final diagram. Before launching bubblewrap, codex-linux-sandbox creates a Unix socket pair to serve as a control channel and forks itself. The child runs run_host_bridge() and waits to receive the listener’s file descriptor over that channel:
In this example, the parent process uses exec to replace its program image with bwrap. This sets up the sandbox and launches codex-linux-sandbox --apply-seccomp-then-exec within it, passing along the FD for the control channel:
Inside the sandbox’s network namespace, the second invocation of codex-linux-sandbox creates a loopback TCP listener and passes its file descriptor via the socket. The listener remains associated with the sandbox’s network namespace, allowing the child process that remained outside the sandbox to accept connections from sandboxed programs while opening its upstream connections in the host’s network namespace. After the handoff, both processes close their control-channel descriptors, and the process inside the sandbox closes its copy of the listener.
Once the TCP listener is ready, the process inside the sandbox sets the appropriate value for HTTP_PROXY(opens in a new window) and related environment variables to point to that listener. It then applies seccomp before forking and executing the user’s command:
The process outside the sandbox keeps the listener open. For each accepted connection, it opens a connection to the configured proxy and relays data in both directions.
This additional machinery gives the command its own network namespace, including a separate loopback interface. On macOS, Seatbelt allows the command to connect directly to specified ports on the host’s loopback interface. On Linux, the command instead connects to a listener inside its isolated namespace, and a process outside the sandbox relays those connections to the configured proxy. The descriptor handoff makes this connection possible without exposing the host’s network namespace to the command.
Windows
Earlier this year, we implemented and wrote about our sandboxing efforts on Windows. Since then, Microsoft has released a library called MXC alongside new features for process isolation inside the Windows operating system. We are currently replacing our existing sandbox with one that makes use of the MXC library.
What is MXC?
MXC (Microsoft eXecution Container) is a sandboxed code execution system(opens in a new window) from Microsoft that supports several containment backends across Windows, Linux, and macOS. Codex supports an MXC-based sandbox on compatible Windows devices, using native process isolation to restrict commands within the user’s existing environment.
We are transitioning to MXC to improve security and usability while addressing several limitations of our existing Windows sandbox:
Need for elevated/admin access to set up the sandbox
Expensive/slow ACL checking and setting operations
Persistent sandbox setup state on the host machine, including
ACLs
Firewall rules
Sandbox users
Control plane files
MXC exposes a JSON configuration schema(opens in a new window). Codex uses the MXC SDK(opens in a new window) to construct an execution request following that schema and containing the command, working directory, environment, and permissions. Those permissions cover filesystem and network access, along with Windows resources such as the desktop and clipboard.
Translating policy into MXC invocation
Codex uses fixed settings for several controls to balance compatibility and security. It permits registry reads and retains the Win32k and desktop access PowerShell needs during startup. Clipboard access, input injection, and desktop and system-settings controls are disabled. Finally, MXC is prevented from falling back to modifying host filesystem permissions.
Codex translates the permission profile’s filesystem and network rules into MXC’s configuration. Using the earlier dev profile, and assuming:
C:\,D:\andZ:\are the machine’s only local drives.The workspace root and working directory are
C:\work\demo.The user’s home directory is
D:\Users\dev, so~/build-cacheresolves toD:\Users\dev\build-cache.The deny glob matches only
C:\work\demo\config\dev.envandC:\work\demo\config\prod.env.
The corresponding MXC settings would include:
JSON
1{2 ...3 "filesystem": {4 "readwritePaths": [5 "C:\\work\\demo",6 "D:\\Users\\dev\\build-cache",7 ...8 ],9 "readonlyPaths": [10 "C:\\",11 "D:\\",12 "Z:\\",13 "C:\\work\\demo\\.agents",14 "C:\\work\\demo\\.aws",15 "C:\\work\\demo\\.codex",16 "C:\\work\\demo\\.devcontainer",17 "C:\\work\\demo\\.git",18 "C:\\work\\demo\\.vscode",19 ...20 ],21 "deniedPaths": [22 "C:\\work\\demo\\config\\dev.env",23 "C:\\work\\demo\\config\\prod.env",24 "C:\\work\\demo\\secrets"25 ]26 },27 "network": {28 "egress": {29 "default": "deny",30 "allow": [{31 "to": [32 {"cidr": "127.0.0.0/8"},33 {"cidr": "::1/128"}34 ]35 }]36 },37 "ingress": {38 "default": "deny",39 "hostLoopback": "allow"40 }41 },42 ...43}
Drive-root access
MXC’s filesystem policy denies access by default. Codex therefore adds read-only grants for the local drive roots to provide the broad reads allowed by this profile. These grants apply recursively, subject to the user’s existing OS permissions.
One wrinkle: writable drive-root grants do not apply recursively, so Codex expands them to include the drive’s existing immediate children.
Conflicting grants
More-specific paths override ancestor grants, so C:\work\demo can be writable beneath a read-only C:\, while C:\work\demo\.git remains read-only.
When different path spellings or symlink/junction aliases refer to the same path, MXC applies the stricter permission: deny takes precedence over read-only, which takes precedence over read-write.
Deny globs
MXC takes concrete deny paths only, so Codex expands deny globs to matching files and directories before launch. New paths that match the glob are not automatically added while the command is running.
Network access
Domain rules such as *.openai.com are enforced by the shared Codex network proxy described earlier. Codex runs that proxy outside the sandbox and passes its addresses to the command through the same standard *_PROXY environment variables as mentioned previously. MXC blocks direct external connections while allowing host-loopback connections, including access to the proxy. Other local services remain reachable.
Across macOS, Linux, and Windows, the harness uses the same sandbox API to launch commands under a permission profile. The platform-specific implementations handle the setup needed to apply those restrictions.
Building on the Codex sandbox
Writing and executing code gives agents a flexible way to solve problems beyond software development. The Codex sandbox lets them use that capability in the user’s existing environment with explicit limits on filesystem and network access. It is a reusable primitive within the harness, and the codex sandbox command makes it available to tools you build yourself.
As agents take on more tasks, we want to make sandboxing practical for more tools and environments. That means making permissions easier to configure and taking advantage of better operating system protections as they become available. Our goal is to expand what agents can do while keeping people in control of what they can access.


