techlist.io

Seatbelt

2 posts

OpenAI2026-05-125 min readCurated summary

Building a safe, effective sandbox to enable Codex on Windows

# Building a Safe, Effective Sandbox for Codex on Windows OpenAI's Codex coding agent had no sandbox on Windows, forcing users to either approve nearly every command or disable restrictions entirely. The author's team built a custom sandbox because none of the existing Windows isolation tools fit an agent that needs to work like a real developer. The final design, which requires elevation at setup time, combines restricted tokens, dedicated sandbox users, firewall rules, and a separate command-runner binary. The author concludes that Windows offers no single primitive for a safe autonomous coding agent, so the solution had to be composed from several parts. ## Why Existing Windows Tools Fell Short - **AppContainer** offers a real OS isolation boundary, but it is built for apps that know their exact access needs in advance. Codex runs open-ended workflows such as shells, Git, Python, and package managers, which makes AppContainer a poor fit. - **Windows Sandbox** provides a strong, disposable VM with broad software compatibility. However, Codex needs to act directly on the user's real checkout and tools, and Windows Sandbox is unavailable on Windows Home editions. - **Mandatory Integrity Control (MIC)** labeling could allow a non-admin, low-integrity sandbox. However, relabeling a workspace as low integrity lets any low-integrity process write there, which turns the user's real checkout into a broadly writable target and changes the trust model in a way that is hard to contain. ## First Prototype: The Unelevated Sandbox The first prototype aimed to run without administrator privileges and limited two things: file writes and network access. ### Limiting File Writes - A synthetic SID named `sandbox-write` was created for the sandbox. - That SID received write, execute, and delete access to the current working directory and any `writable_roots` set in `config.toml`. - It was explicitly denied write access to read-only subpaths such as `<cwd>/.git`, `<cwd>/.codex`, and `<cwd>/.agents`. - Commands launched under a write-restricted token whose restricted SID list included `Everyone`, the logged-in session SID, and `sandbox-write`. A write succeeds only if both the user identity and a restricted SID are granted access. ### Limiting Network Access - Windows Firewall could not be used without admin rights, so network control was advisory. - The sandbox set environment variables such as `HTTPS_PROXY`, `ALL_PROXY`, and `GIT_HTTPS_PROXY` to point at a dead endpoint (`127.0.0.1:9`), and set `GIT_SSH_COMMAND` to fail. - A `denybin` directory with stub SSH and SCP scripts was prepended to `PATH`, with `PATHEXT` reordered so the stubs resolved first. - This blocked common tool traffic but could be bypassed by programs that ignored the variables or opened sockets directly. ### Tradeoffs The prototype was lightweight and granular and avoided elevation prompts. Its drawbacks were: - Applying workspace ACLs could be slow, depending on directory structure. - It modified real ACLs on the developer's system, though only for the sandbox's own SID. - Changing sandbox semantics required slow ACL updates, unlike macOS, where the Seatbelt profile can be regenerated. - Network protection was weak and not designed to resist adversarial code. ## Redesign: The Elevated Sandbox Windows Firewall rules could not target only the commands the agent spawns. They could match a specific binary, but that would also affect `codex.exe` and other copies of the same program. They also could not match a restricted token's SID, and user-scoped rules applied to the real user. Isolating network access therefore required running sandboxed commands as a separate Windows principal, which meant accepting an elevation requirement at setup. ### Two Sandbox Users - Commands run under a restricted token whose principal is one of two local users created by Codex: `CodexSandboxOffline`, which firewall rules block from all outbound network access, and `CodexSandboxOnline`, which is not restricted. ### A Dedicated Setup Step Setup now needs to: - Create the synthetic SID and the two sandbox users if they do not exist. - Store the users' credentials encrypted with the Windows Data Protection API (DPAPI), in a location the sandbox users cannot read. - Create or validate firewall rules that block all outbound traffic for `CodexSandboxOffline`. - Grant read ACLs to the sandbox users on common directories such as `C:\Users\<real-user>`, `C:\Windows\`, `C:\Program Files\`, `C:\Program Files (x86)\`, and `C:\ProgramData\`. Because the sandbox user is a different principal, it cannot otherwise read other users' profile directories. This step runs asynchronously so it does not block the user. - Live in a separate binary, `codex-windows-sandbox-setup.exe`. This crosses the UAC boundary only when needed and keeps `codex.exe` a normal unelevated process. ### A Separate Command Runner The first approach, in which `codex.exe` logged on as the sandbox user, created a restricted token, and spawned the child, failed at `CreateProcessAsUserW(...)` because of a privilege restriction. The fix was a new binary, `codex-command-runner.exe`: - `codex.exe` launches the runner as the sandbox user with `CreateProcessWithLogonW(...)`, without a restricted token. - Inside the runner, `OpenProcessToken(GetCurrentProcess(), ...)` gets the sandbox user's token, and `GetTokenInformation(...)` extracts the logon SID. - The runner calls `CreateRestrictedToken(...)` and then `CreateProcessAsUserW(...)` to launch the actual child process. ### Final Architecture 1. `codex.exe`, the unelevated harness 2. `codex-windows-sandbox-setup.exe`, for elevated setup 3. `codex-command-runner.exe`, for launching restricted-token commands 4. The child process ## Lessons - Windows did not provide one primitive for a safe autonomous coding agent, so the design combines several mechanisms. - Some early approaches were dead ends, and the final design is a hybrid of earlier prototypes. - Coding agent security differs from classic application security. The work required balancing compatibility with real developer workflows against actual enforcement.

Anthropic2025-10-203 min readCurated summary

Making Claude Code safer with sandboxing

Anthropic's Claude Code can edit files, run commands, and navigate a codebase, which creates real risk when it is exposed to prompt injection. To address this, Anthropic introduced two features built on sandboxing: a sandboxed bash tool that lets Claude run commands without a permission prompt for each action, and Claude Code on the web, which runs each session in an isolated cloud sandbox. Anthropic reports that sandboxing reduced internal permission prompts by 84%, showing that defined boundaries can improve both security and autonomy. ## The Problem with Permission Prompts - By default, Claude Code is read-only and asks for approval before modifying files or running most commands. Only safe commands such as `echo` and `cat` are auto-allowed. - Constant approval requests slow development and cause "approval fatigue," where users stop scrutinizing what they approve, which makes development less safe. ## Sandboxing: Fixed Boundaries Instead of Per-Action Approval Sandboxing sets pre-defined limits within which Claude can act freely. It is built on operating system features and enforces two kinds of isolation: - **Filesystem isolation:** Claude can access only specific directories, which prevents a prompt-injected agent from modifying sensitive system files. - **Network isolation:** Claude can connect only to approved servers, which prevents data leaks and malware downloads. Anthropic stresses that both are required. Network isolation alone lets a compromised agent exfiltrate files such as SSH keys, and filesystem isolation alone lets it escape the sandbox and reach the network. ## Sandboxed Bash Tool - Anthropic released the sandbox runtime in beta as an open-source research preview. It restricts which directories and network hosts a process can use, without the overhead of containers, and can wrap arbitrary processes, agents, and MCP servers. - In Claude Code, the runtime sandboxes the bash tool. Commands run without prompts inside the limits, and any attempt to go outside them triggers a notification so the user can allow or deny it. - It is built on Linux bubblewrap and macOS seatbelt, so restrictions apply to subprocesses and scripts the command spawns, not just Claude's direct actions. - Filesystem access allows reads and writes in the current working directory and blocks modifications elsewhere. - Network access goes only through a Unix domain socket to a proxy running outside the sandbox. The proxy enforces domain allowlists, asks the user to confirm new domains, and can be customized with arbitrary outbound rules. - Both the file paths and domains are configurable. Users enable the feature with `/sandbox`. ## Claude Code on the Web - Each session runs in an isolated cloud sandbox with full access to its own server. - Sensitive credentials, such as git credentials and signing keys, never enter the sandbox, so compromised code cannot easily cause further harm. - A custom proxy handles all git operations. Inside the sandbox, git authenticates with a scoped credential. The proxy checks that the credential is valid and that the operation matches the allowed scope (for example, pushing only to the configured branch), then attaches the real token before forwarding the request to GitHub. ## Recommendation Developers who use Claude for engineering work can run `/sandbox` in Claude Code to reduce prompts while improving safety, or try Claude Code on the web at claude.com/code. Teams building their own agents can also adopt the open-sourced sandboxing code.