External Sandbox: Adding a Security Isolation Layer for Coding Agents

Prime Radiant proposes the external sandbox pattern and open-sources three implementations for safe code execution by coding agents.
Simon Willison and Prime Radiant propose the external sandbox pattern: coding agents run on the host and send only code to a separate sandbox process via a localhost API. Prime Radiant released three open-source implementations (v86/WebAssembly, Apple Containers, Quicksand/QEMU) with an HTTP/HTTPS allowlist proxy and credential swapping.
Title
External Sandbox: Adding a Security Isolation Layer for Coding Agents
Meta Description
Simon Willison and Prime Radiant propose the external sandbox pattern, letting coding agents execute code in isolated environments, and release three open-source implementations with network allowlisting and credential swapping to improve AI programming security.
Article Content
When coding agents execute code locally, a single mistake or prompt injection attack can cause damage to the machine. Simon Willison, in collaboration with AI research lab Prime Radiant, has proposed a pattern called "external sandbox" and released three open-source implementations that let agents run code in isolated environments while remaining outside the sandbox themselves.
What Is the External Sandbox Pattern?
The traditional approach is to put the entire coding agent inside a sandbox, or simply trust the agent not to make mistakes. The external sandbox pattern does the opposite: the agent itself runs on the host machine, and only the code it wants to execute is sent to a separate sandbox process. The agent communicates with the sandbox through an API, and the sandbox handles isolating the filesystem, network, and processes.
This separation brings two benefits. On one hand, the agent's reasoning and tool-calling logic are not constrained by the sandbox and can normally access project files and the development environment; on the other hand, the actually risky code execution is confined to a disposable container or virtual machine, so even if manipulated by prompt injection, the damage is limited to the interior of the sandbox.
According to Simon Willison's introduction on the Prime Radiant blog, the goal of this pattern is to let developers try local models more safely without worrying that model errors or malicious prompts could damage the host machine.

Prompt Injection refers to an attacker embedding malicious instructions in the input processed by the agent (for example, code comments, document content, or web page text), inducing the large language model to deviate from its original task and perform operations intended by the attacker. For coding agents with code execution capabilities, the harm of prompt injection is amplified: the agent may be induced to read sensitive files, initiate outbound requests, or run destructive commands. The external sandbox pattern is designed precisely for this threat model—it isolates the execution environment from the host machine, so that even if the agent is successfully injected, the attacker's scope of impact is limited to a disposable sandbox. Understanding prompt injection is a key prerequisite for understanding why "execution isolation" is needed rather than only "model alignment."
Three Open-Source Implementations: From WebAssembly to QEMU
To let developers get started directly, Prime Radiant released three sandbox server implementations, which expose the same localhost API:
- external-sandbox-v86: A Node.js server that uses v86 to run Alpine Linux in WebAssembly. Suitable for scenarios that want lightweight, cross-platform operation.
- external-sandbox-container: A Python web server that runs an Alpine Linux sandbox in an Apple Containers instance. Aimed at macOS users, leveraging Apple's containerization technology.
- external-sandbox-quicksand: Another Python web server, based on Microsoft's Quicksand sandbox library, which packages QEMU and Alpine Linux into a Python package that works once installed.
These three implementations cover different technology stacks and platform preferences, but all follow the same API convention. Developers can choose the most suitable solution for their environment without modifying the agent-side code.
WebAssembly (Wasm) is a binary instruction format that can run in hosts such as browsers and Node.js, featuring memory isolation, portability, and fast startup. v86 is an x86 emulator implemented in JavaScript/WebAssembly that can run a complete Linux system in a web page or Node environment. Choosing the v86-based solution means the sandbox itself is an emulated complete virtual machine, with a naturally hardware-level isolation boundary from the host machine, without relying on the host operating system's container capabilities. Compared with container solutions, Wasm emulation has controllable startup and resource overhead and does not require the host machine to install additional virtualization tools, making it suitable for cross-platform, lightweight local experimentation scenarios.
QEMU is a mature general-purpose open-source virtualization and emulator that supports software-level emulation of multiple CPU architectures and complete machines. Microsoft's Quicksand library packages QEMU and Alpine Linux as a Python package, enabling developers to obtain a virtual-machine-level sandbox without manually configuring a virtualization environment. Unlike containers that share the host kernel, QEMU virtual machines have an independent kernel and stronger isolation, but startup and resource costs are relatively higher. The three implementations make different trade-offs among isolation strength, platform compatibility, and ease of use.
Network Control and Credential Swapping
The external sandbox does more than isolate code execution; it also provides fine-grained network control. Each sandbox includes an optional HTTP/HTTPS allowlist proxy, and developers can precisely specify the hosts that agent code is allowed to communicate with. This means that even if the agent is induced to initiate external requests, it can only access addresses within the allowlist.
Even more clever is the credential swapping mechanism. When agent code makes API calls that require authentication, it does not need to directly hold the keys. The sandbox proxy replaces credentials when the request is sent, thereby avoiding exposing sensitive keys to the agent itself. In this way, even if the agent is compromised, the attacker cannot obtain long-term valid credentials.
The sandbox also provides a UI that allows dynamic reconfiguration of agent policies while the sandbox is running, including allowed targets, policy JSON editing, and recent proxy activity logs. This facilitates debugging and temporary adjustments.
An allowlist proxy is an intermediary layer between the sandbox and the external network. It intercepts all HTTP/HTTPS requests sent by the sandbox and only allows requests whose target host is on the allowlist. This mechanism follows a "default deny" policy: addresses not explicitly allowed are blocked, thereby limiting the data exfiltration and lateral movement capabilities of injected code. Compared with simple firewall rules, an HTTP-layer proxy can parse request targets and enforce control at the application layer, with finer granularity.
Credential swapping/injection addresses the dilemma of key management: the agent needs to call protected APIs but should not hold long-term valid keys. The approach is for the sandbox proxy to inject real credentials when requests go outbound, while the agent code itself can only see placeholders or cannot access the keys at all. Even if the agent is compromised, the attacker can only initiate requests within the scope allowed by the sandbox and cannot steal credentials that can be reused offline. Together, these two mechanisms form a dual constraint on external communication: controlling "who can be accessed" while also controlling "with what identity access is made."
Integration with Coding Agents
These sandbox servers are designed to work with existing coding agents. Developers can configure Pi, Claude Code, or Codex to send calls to the sandbox API when code execution is needed. The agent is still responsible for generating code and making decisions, but the execution step is transferred to an isolated environment.
This integration approach does not require modifying the agent's core logic; only its code execution backend needs to be adjusted. For developers already using these agents, the migration cost is low. At the same time, because the sandbox exposes a unified localhost API, it can also be conveniently replaced with other sandbox implementations in the future.
Why It Is Worth Paying Attention To
Running untrusted code safely has always been an engineering challenge. The spread of coding agents has made this problem more urgent: agents actively generate and execute code, and prompt injection attacks may cause them to perform unexpected operations. The external sandbox pattern provides a pragmatic compromise—retaining the agent's flexibility while limiting risk through isolation and network control.
Simon Willison says he remains fascinated by the challenge of safely running untrusted code, and the external sandbox pattern provides a clean way to experiment with different approaches. For developers who want to try new models or agent tools locally, these three open-source implementations are worth watching.
The project code has been released on GitHub under the prime-radiant-inc organization, open-sourced for community use and extension.
One-line Summary
Prime Radiant proposes the external sandbox pattern and open-sources three implementations, letting coding agents execute code safely.
Paragraph Summary
Simon Willison, in collaboration with AI research lab Prime Radiant, proposes the "external sandbox" pattern: the coding agent itself runs on the host machine and sends only the code to be executed into a separate sandbox process, communicating through a localhost API, thereby isolating the filesystem, network, and processes. This pattern preserves the agent's flexibility to access project files while limiting the damage from prompt injection manipulation to a disposable sandbox. Prime Radiant released three open-source implementations—based on v86/WebAssembly, Apple Containers, and Microsoft Quicksand (QEMU)—which expose a unified API. The sandbox also provides an HTTP/HTTPS allowlist proxy and credential swapping mechanism to prevent unauthorized network access and key leakage, and can be configured for agents such as Pi, Claude Code, and Codex.
Related articles

Claude-Assisted Riemann Hypothesis Proof Passes Lean Kernel Checks, But Human Understanding Has Only Just Begun
A Claude-assisted Riemann Hypothesis proof passes multiple Lean kernel checks with 175,187 modules and zero errors, but human understanding has only just begun. This article analyzes the verification process, the four checkpoints, the author's background, and the mathematical community's reaction.

Genesis Map: A Visualized Risk Map for AI Agent Changes
Genesis Map is a visualization tool featured on Hacker News that shows the impact scope and potential breakpoints of AI agent code changes, helping developers identify risk areas in advance.

Training-Free Decoding Method SLA: Tackling Schema Ambiguity in Text-to-SQL
Researchers propose SLA, a training-free decoding method that adjusts logits via semantic similarity to improve SQL diversity under Text-to-SQL schema ambiguity, with low cost and easy deployment.