Stateful Sandboxes for Code Execution: MicroVM Providers
Nathanael Chiang13 min read
A stateful sandbox for code execution keeps an agent's work between steps: its files at minimum, and on the stronger platforms its RAM and running processes too. If your agent idles between tool calls and needs its processes back, pick a VM-based sandbox that restores memory on resume, such as Beam VMs, E2B, Daytona VM sandboxes or Tensorlake named sandboxes. If files are enough, Vercel Sandbox, Fly.io Sprites, Daytona container sandboxes and a stopped Beam VM keep the disk.
What is a stateful sandbox for code execution?
A stateful sandbox is an isolated environment whose state outlives a single command or session. That lets an agent edit files, run a dev server and read errors across many steps, the loop behind AI app builders. Vendors use the word for three different guarantees: the filesystem survives a stop, memory and running processes survive a pause, or a running environment can be forked into copies. Check which of the three a provider means before you compare prices.
Filesystem persistence
Installed packages, cloned repositories, build caches and SQLite files survive when the environment stops. Running processes do not, so on the next boot the agent restarts its dev server, reloads its data and warms up the interpreter again. Most platforms offer this level. Daytona container sandboxes keep their disk on stop, Vercel's persistent sandboxes save the filesystem automatically when a session ends, and a Beam VM keeps its root disk when you stop it.
Memory persistence
A pause checkpoints RAM along with the disk, and a resume puts every process back where it was. A Jupyter kernel keeps its variables, a dev server keeps its port, and a half-finished test run carries on. E2B, Daytona VM sandboxes, Tensorlake named sandboxes and Beam VMs all offer an explicit pause. Sprites does it on its own for a short while after the machine goes idle, then drops memory once the Sprite goes cold. Beam warns that open connections can close during a pause, Fly says they always drop, and E2B says pauses, snapshots and forks all disconnect clients, so agents should reconnect after resuming.
Forks and snapshots
A snapshot saves state as a reusable artifact, and a fork starts new environments from that state. Whether the copy carries memory decides what forking is good for. A memory fork lets ten agents branch from one warmed-up session; a filesystem fork gives each branch the same files and a fresh boot. Beam VM snapshots and forks are filesystem only, so on Beam the memory fork comes from a sandbox memory snapshot.
Which state survives pause, stop and snapshot?
Pause, stop and snapshot keep different state on each platform: E2B, Daytona VMs, Tensorlake named sandboxes and Beam VMs hand back RAM and running processes after a pause, while Vercel and cold Sprites keep only the disk. The table maps each provider's isolation model to what each operation keeps.
| Provider | Isolation | Pause keeps | Stop keeps | Snapshot keeps | Fork with memory |
|---|---|---|---|---|---|
| Beam VMs | CPU microVM with its own kernel | RAM, processes and disk | Disk | Disk only | No, forks copy the disk |
| Beam sandboxes | Container, or microVM with use_vm | No pause | Nothing unless snapshotted or on mounted storage | Filesystem image, or memory checkpoint | Yes, from a memory snapshot on supported runtimes |
| E2B | Firecracker microVM | RAM, processes and disk | No stop; kill discards everything | Filesystem and memory | Yes |
| Daytona containers | Container | No pause | Disk | Filesystem only | No |
| Daytona Linux VMs | VM with its own kernel | RAM, processes and disk | Disk | Filesystem and memory | Yes |
| Modal | gVisor, or VM runtime | No pause | Nothing by default; opt-in beta exit snapshots save the filesystem | Filesystem; memory in alpha | Alpha memory snapshots only |
| Fly.io Sprites | Firecracker microVM | RAM while warm, disk once cold | No manual stop; disk persists when cold | Disk only | Not documented |
| Tensorlake | Firecracker microVM for CPU, gVisor for GPU | RAM, processes and disk on named sandboxes | Restartable for 48 hours after terminate | Filesystem, or memory and processes | Yes |
| Vercel Sandbox | Firecracker microVM | No pause documented | Disk, saved automatically | Filesystem | No, forks copy the filesystem |
| Northflank | Cloud Hypervisor microVM, gVisor for GPU | Compute stops; RAM handling not stated | Attached volumes | Not documented | Not documented |
A few details sit behind the cells. E2B pauses take about 4 seconds per GiB of RAM and resumes take about 1 second; a paused sandbox is kept indefinitely and isn't billed. Daytona offers pause, fork and memory snapshots only on its VM classes. Its default container class keeps the disk on stop, and its GPU sandboxes are ephemeral: Daytona deletes them when they stop, so anything worth keeping goes in a filesystem snapshot or a volume. Modal has no pause: filesystem snapshots expire after 30 days by default, its alpha memory snapshots expire after 7 days, and an opt-in beta exit snapshot can save the filesystem when a sandbox terminates or times out. Tensorlake suspends only named sandboxes; unnamed ones are ephemeral.
Best microVM sandbox providers for agent code execution
For agents that need state back after idle time, the strongest managed options are Beam VMs, E2B, Daytona's VM sandboxes and Tensorlake, because each pauses an environment with its memory. Sprites fits long-lived dev boxes that can accept a cold wake, Vercel Sandbox fits Firecracker sessions with saved disks, and Beam sandboxes, Modal, Northflank or Daytona's ephemeral GPU sandboxes fit GPU code. Each one has limits, covered in its section below.
Beam VMs and Beam sandboxes
Beam has two products for this job. Beam virtual machines are persistent CPU microVMs, each with its own kernel. Pause keeps RAM and running processes, stop keeps the disk, and each VM supports forks, snapshots, SSH, a browser terminal, an Ubuntu desktop with screenshot, click and typing APIs, Docker and systemd. Published ports keep the same URL across stop, start, pause and resume. An idle timeout can pause the VM and wake it on the next request, and running time is billed per second.
Beam sandboxes are isolated containers for short-lived code execution. They boot in seconds and can attach a GPU such as an RTX 4090, and on supported runtimes they take memory snapshots that fork into new sandboxes. Beam's open-source runtime, beta9, ships runc, gVisor and microVM runtimes, and its default worker configuration uses gVisor. If a comparison site lists Beam as containers only, it is describing the sandboxes, not the VMs.
Where Beam falls short: VMs are CPU-only and run Linux only, VM forks and snapshots don't carry RAM, and Beam publishes no VM boot or resume time. On price, the default Performance tier is about level with E2B and Daytona per vCPU, and the cheaper tiers carry limits: Shared stops at 8 vCPU and 16 GiB, and Spot can be interrupted.
E2B
Every E2B sandbox runs in its own Firecracker microVM. Pause saves the filesystem and memory, paused sandboxes don't count toward concurrency, and snapshots and forks both carry memory. A sandbox can run continuously for 1 hour on Hobby or 24 hours on Pro, and a pause resets that clock. E2B is CPU-only. Our E2B alternatives guide covers the wider field.
Daytona
Daytona's default class is a container that it creates in under 90 ms. Its Linux VM and Windows classes run a full VM with its own kernel, and only those classes pause, fork and take memory snapshots. GPU sandboxes are ephemeral containers with a dedicated GPU: they can't pause or fork, and Daytona deletes them when they stop. Container and GPU sandboxes auto-stop after 15 minutes without outside activity by default, and a long process inside doesn't count as activity. VM sandboxes default to auto-pausing after 60 minutes idle instead, so their memory is kept. More detail is in our Daytona alternatives comparison.
Tensorlake
Tensorlake runs CPU sandboxes in Firecracker microVMs and GPU sandboxes, available on request, on gVisor. Named sandboxes suspend with their filesystem, memory and processes, either on demand or when an idle timeout passes. Memory checkpoints restore with a warm start and can be cloned. The idle timeout tops out at 2 hours on the free tier, 24 hours with usage credits, and has no limit on Pro.
Fly.io Sprites
Sprites are persistent Linux machines on Firecracker with a fixed 8 vCPUs and 100 GB of disk. About 30 seconds after activity stops, a Sprite goes warm: memory freezes, compute billing stops, and the next request resumes it in 100 to 500 ms. Left idle longer, it goes cold, drops memory and takes 1 to 2 seconds to wake. You can't choose between the two states, and checkpoints capture the disk only.
Vercel Sandbox
Each Vercel sandbox is a Firecracker microVM with a dedicated kernel. Sandboxes are persistent by default: when a session stops, Vercel snapshots the filesystem and the next SDK call resumes from it. You can fork new sandboxes from a snapshot, but the docs describe filesystem snapshots only. Sessions run up to 45 minutes on Hobby and 24 hours on Pro.
Modal Sandboxes
Modal sandboxes run on gVisor or a VM runtime with its own Linux kernel. There is no pause, though an opt-in beta exit snapshot can save the filesystem when a sandbox terminates or times out. A sandbox lives 5 minutes by default and 24 hours at most. GPU sandboxes run on gVisor only and can be preempted, and sandbox compute is billed at three times Modal's list price.
Northflank
Northflank runs sandboxes as Cloud Hypervisor microVMs and uses gVisor for GPU sandboxes. Sandboxes have no time limit, a pause stops compute billing, and state that must survive goes on attached volumes. Its $0.01667 per vCPU-hour is below every rate in this group except Beam's Shared and Spot tiers, and it runs in your own cloud account as well as its own.
Which managed microVM providers have the fastest cold starts?
Among microVM providers, warm Fly.io Sprites (100 to 500 ms to wake), Vercel Sandbox (milliseconds) and Tensorlake (hundreds of milliseconds) publish the quickest startup figures, with Northflank at 0.8 seconds and E2B resuming in about 1 second. Daytona's containers create in under 90 ms, but they share the host kernel, and its VM class resumes in under a second. These figures measure different events, from creation to boot, wake and resume, and none come from a shared benchmark. For a stateful agent, resume time after a pause usually matters more than a first boot.
| Provider | Published startup figure | What it measures |
|---|---|---|
| Daytona | Under 90 ms | Container sandbox creation |
| Daytona | Under a second | VM resume from pause |
| Fly.io Sprites | 100 to 500 ms warm, 1 to 2 s cold | Wake from idle |
| Tensorlake | Hundreds of milliseconds | MicroVM boot |
| Vercel Sandbox | Milliseconds | Sandbox start |
| Northflank | 0.8 seconds | Scheduling, VM boot and container start with a cached image |
| E2B | About 1 second | Resume from pause |
| Modal | Sub-second | Cold start on custom images |
| Beam sandboxes | Seconds | Sandbox boot |
| Beam VMs | Not published | None |
Beam doesn't publish a VM boot or resume time, so measure it against your own image before you commit. Pause cost matters too: an E2B sandbox with 8 GiB of RAM takes about 32 seconds to pause at the documented rate of 4 seconds per GiB.
Pricing and usage tiers for pay-as-you-go Firecracker sandboxes
Among Firecracker sandboxes, E2B charges $0.0504 per vCPU-hour and $0.0162 per GiB-hour of allocated RAM, while Vercel Sandbox, Tensorlake and Fly.io Sprites charge for CPU only while it is working (Tensorlake where active metering is available). E2B, Vercel and Tensorlake each have a no-fee entry tier capped on sessions, hours or concurrency, and Sprites starts with a trial credit.
| Provider | CPU rate | Memory rate | Entry tier | Paid tier |
|---|---|---|---|---|
| E2B | $0.0504 per vCPU-hour | $0.0162 per GiB-hour | Hobby: $0 plan, one-time $100 usage credit, 1-hour runs, 20 concurrent | Pro: $150 a month plus usage, 24-hour runs, 100 concurrent |
| Vercel Sandbox | $0.128 per active CPU-hour | $0.0212 per GB-hour provisioned | Hobby: 5 CPU-hours and 420 GB-hours a month, 45-minute sessions | Pro: $20 a month platform fee that includes $20 of usage credit, then usage is billed; 24-hour sessions |
| Tensorlake | $0.07 per active core-hour | $0.015 per GB-hour | Free: one 1 vCPU and 1 GB sandbox, idle timeout up to 2 hours; prepaid packs from $5 | Pro: $250 a cycle with $250 of usage included, lower rates, unlimited duration |
| Fly.io Sprites | $0.0385 per CPU-hour used | $0.021875 per GB-hour used | $30 trial credit | Plans such as Hero at $100 a month with bundled CPU and RAM hours |
Vercel's rates are for its default iad1 region; other regions differ.
Rates mean more side by side. Here is one hour of a 2 vCPU, 4 GiB environment at full CPU, including the other providers in this guide:
| Provider | Isolation | One hour | Arithmetic |
|---|---|---|---|
| Beam, Spot tier | Container or microVM | $0.018 | 2 × $0.0063 + 4 × $0.00135 |
| Beam, Shared tier | Container or microVM | $0.044 | 2 × $0.011 + 4 × $0.0055 |
| Northflank | microVM | $0.067 | 2 × $0.01667 + 4 × $0.00833 |
| Beam, Performance tier (default) | Container or microVM | $0.14 | 2 × $0.05 + 4 × $0.01 |
| Fly.io Sprites | Firecracker | $0.165 | 2 × $0.0385 + 4 × $0.021875 |
| E2B | Firecracker | $0.166 | 2 × $0.0504 + 4 × $0.0162 |
| Daytona | Container or VM | $0.166 | 2 × $0.0504 + 4 × $0.0162 |
| Tensorlake | Firecracker | $0.20 plus disk | 2 × $0.07 + 4 × $0.015 |
| Modal | gVisor or VM | $0.238 | 1 core (2 vCPU) × $0.1419 + 4 × $0.0240 |
| Vercel Sandbox | Firecracker | $0.341 | 2 × $0.128 + 4 × $0.0212 |
Full CPU is the worst case for the three usage-metered providers. An agent that spends most of its time waiting on a model pays far less there: the same Vercel sandbox at 10% CPU comes to about $0.11 an hour, because memory is the only full-rate charge. Sprites can't be sized to this shape: each one has a fixed 8 vCPUs and memory the platform manages, so its row assumes 2 CPUs and 4 GB of actual use.
Beam's three rows are the same sandboxes and VMs on different CPU tiers. Performance, the default for new accounts, is level with E2B and Daytona per vCPU ($0.05 against $0.0504) and cheaper on memory ($0.01 against $0.0162 per GiB-hour), and Northflank undercuts it at this 2 vCPU, 4 GiB shape. Shared costs less than Northflank but stops at 8 vCPU and 16 GiB. Spot is the lowest rate here, with limits that matter for stateful work: it can interrupt a workload with 30 seconds' notice, a sandbox fails if no capacity frees up within 20 minutes, and a preempted VM has to be restarted by hand.
Memory-heavy shapes change the order. One vCPU with 8 GiB costs $0.13 an hour on Beam Performance (1 × $0.05 + 8 × $0.01), $0.083 on Northflank (1 × $0.01667 + 8 × $0.00833) and $0.055 on Beam Shared (1 × $0.011 + 8 × $0.0055). CPU and RAM attached to a GPU bill at separate GPU rates on every tier. Paused and stopped Beam VMs release compute, storage isn't billed yet, and the rates are on Beam pricing. Beam's Developer plan is $20 a month and prepays $20 of usage each month; Team is $89 a month plus usage. For a deeper look at one vendor's tiers, see E2B pricing explained.
Which cloud APIs create VMs that keep state between agent steps?
Beam, E2B, Daytona and Tensorlake all expose SDK calls that create an environment, pause it with its memory between agent steps, and resume it by name or ID. Fly.io Sprites pauses on its own schedule, and Vercel Sandbox restores the filesystem on the next call. The real differences are who decides when to pause and whether RAM comes back.
- Beam VMs:
VM("name").create()creates a VM,vm.pause()andvm.resume()keep RAM across steps, andVM.connect(name)starts or resumes one on demand. The Python and TypeScript SDKs, the CLI and the Beam MCP server cover the same lifecycle for coding agents. - E2B:
sandbox.pause()saves memory and disk, andSandbox.connect(id)resumes it. Setting the timeout action to pause, with auto-resume, makes this automatic. - Daytona: Linux VM sandboxes pause and resume, and an auto-pause interval can pause idle ones.
- Tensorlake:
Sandbox.create(name=...)makes a named sandbox that suspends and resumes under the same ID. - Vercel Sandbox: a persistent sandbox resumes from its latest filesystem snapshot on the next SDK call.
- Fly.io Sprites: pausing is automatic, and the Tasks API holds a Sprite active while a run finishes.
On Beam, an idle VM can pause itself and wake on the next request. These commands come from the VM docs and the lifecycle guide:
beam vm new devbox
beam vm pause devbox
beam vm resume devbox
beam vm update devbox --ttl 300 --idle-action pause --auto-resumeThe same idle pause from Python:
from beam import VM
vm = VM.get("devbox")
vm.update(ttl=300, idle_action="pause", auto_resume=True)
vm.close()For fan-out from a warmed-up state, a Beam sandbox memory snapshot forks into new sandboxes, which is the pattern behind parallel RL rollouts in sandboxes. This block is the documented sandbox quickstart, and the sandbox docs cover the rest of the API:
from beam import Sandbox
sb = Sandbox(cpu=1, memory="1Gi", keep_warm_seconds=600).create()
print(sb.process.run_code("print(sum(range(10)))").stdout) # 45
# Start a web server and get a URL
sb.fs.write_text("/workspace/index.html", "Hello from a Beam sandbox")
sb.process.exec(
"python3", "-m", "http.server", "8000", "--bind", "0.0.0.0",
cwd="/workspace",
)
print(sb.expose_port(8000))
# Snapshot memory, including the running server, then fork it
snapshot_id = sb.snapshot_memory()
sb.terminate()
forks = [Sandbox().create_from_memory_snapshot(snapshot_id) for _ in range(3)]
for fork in forks:
print(fork.list_urls()) # each fork serves its own copy
fork.terminate()Sandbox URLs are public, so add authentication inside the app before exposing anything sensitive.
How to choose a stateful sandbox for an AI agent
Start from the state your agent has to get back, then filter by GPU, isolation and session length. Leave price for last, because a low hourly rate rarely makes up for an agent that rebuilds its environment on every step.
- Processes must survive idle time. Use an explicit pause with memory: Beam VMs, E2B, Daytona VM sandboxes or Tensorlake named sandboxes.
- Files are enough. Filesystem persistence is simpler to reason about: Vercel persistent sandboxes, Daytona containers, Beam VM stop and start, or Sprites.
- Many branches from one warm state. Pick a memory fork: E2B, Daytona VMs, Tensorlake, or Beam sandbox memory snapshots.
- GPU in the same environment. Beam sandboxes, Daytona GPU sandboxes (ephemeral), Modal, Northflank and Tensorlake (on request) support GPUs. E2B and Beam VMs are CPU-only.
- A desktop for computer-use agents. Beam VMs include an Ubuntu desktop with screenshot, click, typing and recording APIs, and E2B Desktop sandboxes also give agents a Linux desktop. For Windows apps, Daytona's Windows sandboxes (on request for higher-tier accounts) support Computer Use, and Daytona also offers macOS sandboxes; Beam VMs run Linux only.
- Long sessions. A Beam VM runs until you stop, pause or remove it, and its idle timeout is off by default. Tensorlake Pro and Northflank have no session limit. E2B Pro and Vercel Pro cap a continuous run at 24 hours, but the clock resets when a sandbox pauses, or stops and resumes; Modal sandboxes end at 24 hours.
- Untrusted code. Prefer a VM boundary with its own kernel or a gVisor sandbox over a plain container, which shares the host kernel.
FAQ
Should a code execution sandbox be stateful or ephemeral?
Stateful, for agents that work across many steps: an agent that installs packages, edits files and reruns tests loses that setup on every call in an ephemeral sandbox. Ephemeral sandboxes still suit one-shot jobs where each run stands alone, such as scoring a single snippet.
What is the difference between pausing and snapshotting a sandbox?
A pause suspends one environment and saves its state so the same environment can resume later. A snapshot saves state as an artifact that new environments start from, and the original keeps running or stays as it was. On Beam VMs, pause keeps RAM while snapshots keep only the disk; on E2B both can include memory.
Which sandboxes keep memory between agent steps?
Beam VMs, E2B, Daytona's VM sandboxes and Tensorlake named sandboxes pause with RAM and running processes and resume by name or ID. Fly.io Sprites keeps memory only while warm, and Vercel Sandbox restores the filesystem alone.
Do paused sandboxes cost money?
Most platforms stop compute charges during a pause, but storage can still cost money. E2B doesn't bill paused sandboxes, paused Beam VMs release compute and Beam doesn't bill storage yet (a rate of $0.0001 per GB-hour is planned), and Tensorlake charges $0.07 per GB-month for snapshot storage while a sandbox is suspended. Sprites and Daytona stop CPU charges while paused, and their storage rates still apply.
Should AI-generated Python run in a microVM or a container sandbox?
For code you don't control, use a boundary that keeps it away from the host kernel: a microVM with its own kernel, or a gVisor sandbox that handles system calls in a user-space kernel. A plain container shares the host kernel, so a kernel exploit can cross it. MicroVMs also tend to be where memory pause and fork live, which helps stateful agents.
