How to Run Untrusted Code Safely
Containers share the host kernel, so truly untrusted code such as AI-generated scripts or user submissions needs hardware isolation, allowlist-based network egress control enforced from outside the sandbox, rollback and multiple runtimes. Fly.io's Sprites meet these requirements. A code runner is set up with a deny-all network policy applied through the external API, which code inside cannot change even as root, and specific domains can be selectively allowed. Broken environments are recovered by destroying the Sprite or restoring a checkpoint in about a second.
Related posts
- What is an AI code sandbox?
Modal easyNovice
AI code sandboxes are ephemeral, isolated environments for executing LLM-generated code so hallucinated packages, crashes or prompt-injected exploits can't affect the host or other tenants. They run on VMs or containers, ideally with a hardened runtime like gVisor that intercepts syscalls through a user-space kernel instead of sharing the host kernel as runc does. Around that sit filesystem sync APIs, controlled networking, orchestration and state snapshotting. Use cases include background coding agents, code review, chatbot code interpreters, RL reward scoring and AI app builders. Buyers should weigh sub-second cold starts, isolation strength, egress control, high-concurrency scaling, dynamic runtime images and snapshotting.
- The Untrusted Autonomous Workload: How AI Coding Agents Reshape What Isolation Has to Do
Docker mediumAdeptAI coding agents are untrusted, autonomous workloads that containers were never designed to isolate, so Docker Sandboxes runs each agent in a microVM (custom VMM on Hypervisor.framework, WHP or KVM) with its own kernel and private Docker Engine. Outbound traffic goes through a TLS-intercepting host proxy that enforces domain policies and injects credentials from the host keychain, so secrets never enter the VM. Two limits remain: domain-level allowlists still permit exfiltration via sites like github.com, and the shared workspace lets an agent plant Git hooks, package.json scripts or CI configs that later run on the host. A real Astro build showed no measurable microVM overhead, though a jemalloc dependency failed on 16K-page Apple Silicon VMs. Agent output should be reviewed like an untrusted pull request, for example by diffing .git/hooks and using --branch worktrees.
- Building Agents that Don't Break Themselves
Fly.io mediumAdeptSeparate where an agent lives from where it executes code: keep the agent loop on a durable host and send every shell command to a disposable Sprite sandbox. SpriteDoc, an internal multi-user troubleshooting agent built on Pi, creates one Sprite per session on first filesystem use and tears it down when idle. It injects each user's flyctl token only for the duration of a single command, so no credential ever rests in the sandbox. Kyle's Hermes Agent backend instead keeps one persistent Sprite per task and skips dangerous-command approval prompts because the sandbox is the security boundary. Copy-on-write checkpoints let an agent that deletes its own work and toolchain be restored in about nine seconds.
- Agent Swarms on Sprites
Fly.io mediumAdeptRunning each coding agent in a swarm on its own Sprite (a Fly.io sandboxed machine) avoids the shared-filesystem, conflicting-dependency and blast-radius problems of co-located agents. An orchestrator Sprite running Claude Code creates worker Sprites via the API and hands them tasks. Workers can checkpoint and restore their whole environment in about three seconds, which makes speculative parallel attempts practical. Per-agent DNS-level network policies restrict egress, results can flow back over HTTP endpoints, a shared Postgres Sprite or orchestrator file reads, and idle Sprites pause and persist.
- Why AI Agents Need Isolation
Docker easyNoviceAI coding agents that run commands, install packages and handle credentials should execute behind an isolation boundary rather than directly on the developer's host. Docker Sandboxes (sbx) runs agents in microVMs instead of plain containers, because containers share the host kernel. Docker built its own VMM rather than using Firecracker so the same model works on macOS and Windows as well as Linux. Credentials stay on the host: the agent sees a sentinel placeholder, and a proxy swaps in the real auth header on outbound requests. Sandbox Kits package tools, network rules, credentials, files, startup commands and agent memory (e.g. AGENTS.md) into reusable specs, either as stackable Mixin Kits that extend an existing agent or as Agent Kits that define a full agent environment from scratch.