Overview
All commands executed by Codex run inside a sandbox that restricts:- Filesystem access — Read-only by default, configurable write permissions
- Network access — Optional restrictions or proxy routing
- Process capabilities — Reduced privileges and system call filtering
- Protected paths —
.git,.codexalways read-only even in writable roots
macOS
Seatbelt sandbox profiles via
/usr/bin/sandbox-execLinux
Landlock LSM + Bubblewrap container isolation
Windows
Process isolation and token restrictions
Sandbox Modes
Codex provides three sandbox policies:Read-Only (Default)
read-only
Maximum security: entire filesystem is read-only, network blocked.Use case: Exploring unfamiliar code, running untrusted prompts
Workspace Write
workspace-write
Balanced security: write access within workspace, network optional.Use case: Active development, file modifications neededProtected paths (always read-only):
.gitdirectory or pointer file- Resolved
gitdir:target .codexdirectory
Danger Full Access
danger-full-access
No sandbox enforcement: full system access.Use case: Running in external container/VM, advanced users
Platform Implementations
macOS (Seatbelt)
Codex uses Apple’s Seatbelt sandbox via/usr/bin/sandbox-exec.
Core Implementation
Core Implementation
Location:
codex-core expects /usr/bin/sandbox-execFeatures:- Network access control via
SandboxPolicy - Filesystem read/write roots configuration
- Protected path enforcement (
.git,.codex) - Seatbelt profile generation at runtime
Permission Profiles
Permission Profiles
Seatbelt supports macOS-specific permission extensions:No extension profile:
- Legacy default preferences read access (
user-preference-read)
macos_preferences grant:- No preferences access clauses added
macos_preferences = "readonly":- cfprefs read clauses
user-preference-readoperation
macos_preferences = "readwrite":- All readonly clauses
user-preference-writeoperation- cfprefs shm write clauses
macos_automation = true:- Broad Apple Events send permissions
macos_automation = ["com.apple.Notes", ...]:- Apple Events send only to listed bundle IDs
macos_accessibility = true:com.apple.axservermach lookup
macos_calendar = true:com.apple.CalendarAgentmach lookup
Testing Seatbelt
Testing Seatbelt
Test sandbox behavior with:Flags:
--full-auto— Run command automatically--log-denials— Log all denied operations
Linux (Landlock + Bubblewrap)
Codex uses a dual-mode Linux sandbox with legacy and modern pipelines.Architecture
Architecture
Crate:
codex-linux-sandboxProduces:- Standalone
codex-linux-sandboxexecutable (bundled with npm CLI) - Library crate exposing
run_main()for arg0 routing
codex-linux-sandbox, it executes sandbox logic instead of normal CLI.Legacy Pipeline (Landlock)
Legacy Pipeline (Landlock)
Original implementation using Landlock LSM and mount namespaces.Features:
- Landlock filesystem restrictions
- Mount protection
- Default when
use_linux_sandbox_bwrapfeature is off
Modern Pipeline (Bubblewrap)
Modern Pipeline (Bubblewrap)
Standardized container-based isolation using vendored bubblewrap.Feature gate:
use_linux_sandbox_bwrap (temporary during rollout)CLI flag: -c features.use_linux_sandbox_bwrap=trueIsolation mechanisms:- Process hardening:
PR_SET_NO_NEW_PRIVSapplied in-process- seccomp network filter
- Filesystem isolation:
- Read-only by default:
--ro-bind / / - Writable roots:
--bind <root> <root> - Protected subpaths re-applied:
--ro-bindfor.git,gitdir:,.codex - Symlink blocking: mount
/dev/nullon symlinks or missing components
- Read-only by default:
- Namespace isolation:
- PID namespace:
--unshare-pid - Network namespace:
--unshare-net(when network restricted) - Fresh
/proc:--proc /proc(skip with--no-procin restricted containers)
- PID namespace:
- Managed proxy mode:
--unshare-net+ internal TCP→UDS→TCP bridge- Tool traffic reaches only configured proxy endpoints
- seccomp blocks new
AF_UNIX/socketpaircreation for user command
Testing Linux Sandbox
Testing Linux Sandbox
Test sandbox behavior with:Flags:
--full-auto— Run command automatically
Vendored Bubblewrap
Codex vendors bubblewrap for consistent behavior across distributions.Location:
codex-rs/vendor/bubblewrap/The vendored build ensures Codex doesn’t depend on system package versions.Windows Sandbox
Platform-specific process isolation for Windows.Windows Implementation
Windows Implementation
Crate: Setup:
App-server exposes
codex-windows-sandbox (inferred from Cargo.toml)Testing:windowsSandbox/setupStart for elevated/unelevated modes.Process Hardening
All Codex processes apply security hardening pre-main.codex-process-hardening
Cross-platform hardening applied via
#[ctor::ctor] before main().Hardening steps:- Disable core dumps
- Prevents process memory dumps
- Protects sensitive data (API keys, tokens)
- Disable ptrace attach (Linux/macOS)
- Blocks debugger attachment
- Prevents runtime inspection
- Remove dangerous environment variables
LD_PRELOAD— Prevents shared library injectionDYLD_*— Blocks macOS dynamic linker attacks
Execution Policy
Codex tracks command trust decisions via execution policies.codex-execpolicy
codex-execpolicy
Modern execution policy management.Features:
- Command allow-lists
- Session-scoped approvals (
acceptForSession) - Persistent trust decisions
- Amendment proposals from approvals
codex-execpolicy-legacy
codex-execpolicy-legacy
Legacy execution policy support for backwards compatibility.
Approval Flows
Codex implements interactive approval for sensitive operations.Command Approvals
Approval requested
Based on
approval_policy config, Codex may request approval.Available decisions:accept— Run this command onceacceptForSession— Trust for current sessionacceptWithExecpolicyAmendment— Add to allow-listapplyNetworkPolicyAmendment— Allow network hostdecline— Reject commandcancel— Cancel entire turn
File Change Approvals
Approval requested
User accepts or declines the entire patch.Available decisions:
accept— Apply changesdecline— Reject changes
Network Access Control
Codex supports multiple network access modes:Managed Proxy Mode
Linux bubblewrap pipeline supports managed proxy routing:- Network namespace isolation —
--unshare-net - Internal bridge — TCP→UDS→TCP routing
- Endpoint filtering — Only configured hosts reachable
- seccomp enforcement — Block new socket creation after bridge setup
Configuration
Sandbox settings are configured in~/.codex/config.toml:
CLI Override
Override sandbox mode per-invocation:External Sandbox Mode
For pre-sandboxed environments (containers, VMs):externalSandbox Policy
externalSandbox Policy
Tell Codex it’s already sandboxed externally:Behavior:
- Codex won’t enforce its own sandbox
- Agent sees full filesystem access in context
networkAccessstate passed through environment context
- Docker containers
- Kubernetes pods
- VMs with dedicated Codex instances
Testing Sandboxes
Codex provides dedicated commands to test sandbox behavior:--full-auto— Automatically run the command (non-interactive)--log-denials— Log all denied operations (macOS only)
Security Properties
Defense in Depth
Multiple security layers:
- Process hardening
- Sandbox isolation
- Approval flows
- Execution policies
Principle of Least Privilege
Minimum required permissions:
- Read-only by default
- Writable roots explicit
- Network opt-in
- Protected paths enforced
Platform-Native
OS security primitives:
- macOS Seatbelt
- Linux Landlock/Bubblewrap
- Windows token restrictions
User Control
User in the loop:
- Interactive approvals
- Configurable policies
- Session-scoped trust
- Persistent allow-lists
Documentation References
For more information, see:- Official Sandbox Documentation — Codex sandboxing and approvals
docs/sandbox.md— Additional sandbox detailscodex-rs/core/README.md— Core sandbox expectationscodex-rs/linux-sandbox/README.md— Linux implementation details
Next Steps
Architecture Overview
High-level architecture of Codex CLI
Rust Crates
Workspace structure and crate organization