E2B vs Modal: Sandboxes for AI Agents Compared
Eli Mernit11 min read
E2B is a sandbox product built for AI agents: each sandbox is a Firecracker microVM that can pause with its memory intact, and it runs on CPU only. Modal Sandboxes are one part of a serverless compute platform: they run under gVisor or in a VM, can attach a GPU, and keep state through snapshots. Pick E2B for stateful agent sessions on CPU, and Modal when the sandbox needs a GPU or sits next to other Modal workloads.
E2B vs Modal at a glance
The two overlap on the basics: both start an isolated Linux environment from an SDK call, run commands and code in it, and expose ports. They differ in the isolation boundary, in what is kept when a sandbox stops, in GPU support and in how CPU is billed.
| E2B | Modal Sandboxes | |
|---|---|---|
| What it is | A dedicated sandbox product for agents | One primitive of a serverless compute platform |
| Isolation | Firecracker microVM per sandbox | gVisor by default; a VM runtime with its own Linux kernel |
| State between runs | Pause keeps files and memory, kept indefinitely; snapshots | Filesystem, directory and memory snapshots; no pause |
| GPUs | No | Yes, on the gVisor runtime |
| Longest continuous run | 1 hour on Hobby, 24 hours on Pro; a pause resets it | 24 hours; 5 minutes by default |
| Sandbox size | 1 to 8 vCPUs and 1 to 8 GiB; custom on Pro | CPU and memory you request, billed on the higher of request and use |
| CPU and memory rates | $0.0504 per vCPU-hour, $0.0162 per GiB-hour, provisioned | $0.00003942 per core-second, $0.00000667 per GiB-second; one core is 2 vCPUs |
| Plans | Hobby at $0 with a one-time $100 credit; Pro at $150 a month | Starter at $0 with $30 of monthly credits; Team at $250 a month |
| Concurrency | 10 sandboxes on Hobby, 100 on Pro, add-ons up to 1,100 | 250 containers and 10 GPUs on Starter; 10,000 and 50 on Team |
| SDKs | Python, JavaScript and TypeScript | Python; JavaScript and Go in beta |
| Self-hosting | Apache-2.0 code; BYOC for Enterprise | Managed service only |
How E2B and Modal isolate untrusted code
E2B runs every sandbox in its own Firecracker microVM, so the code gets a guest kernel and a hardware virtualization boundary. Modal runs sandboxes under gVisor by default, which keeps the container model and puts a user-space kernel between the code and the host. Modal also has a VM runtime that gives a sandbox its own Linux kernel.
Both boundaries are much stronger than a plain container. The practical difference is compatibility. A microVM runs a real Linux kernel, so software sees the syscalls it expects. gVisor reimplements the kernel interface in user space, and a small share of software hits a syscall it doesn't support. Modal's docs point to the VM runtime for those cases, including running Docker inside a sandbox, and note that GPU sandboxes only run on gVisor.
Our explainers on what a microVM is and what gVisor is go through how each boundary works and what it costs in overhead.
What survives when a sandbox stops: pause vs snapshots
E2B can pause a running sandbox and bring it back with its processes still running. Modal has no pause; it saves state through snapshots, and a new sandbox starts from one. That is the largest functional gap between the two for agents that hold state in a running process.
What E2B's pause does:
- Keeps files and memory. Running processes and loaded variables are still there on resume.
- Is kept indefinitely. A paused sandbox stays until you delete it. E2B bills running sandboxes per second, and its pricing page lists no separate charge for paused ones.
- Takes seconds. E2B's docs put a pause at about 4 seconds per GiB of RAM and a resume at about 1 second.
- Can run on a timer. Set the timeout behavior to pause, and a sandbox pauses when it times out.
- Drops connections. Clients are disconnected while the sandbox is paused, so a served port stops answering until the sandbox resumes.
E2B also has snapshots, which capture files and memory at a point in time, and one snapshot can start many new sandboxes.
What Modal's snapshots do:
- Filesystem snapshots save the whole disk as an image, and several sandboxes can start from the same one. They expire 30 days after creation by default.
- Directory snapshots save one directory, which can then be mounted into another running sandbox.
- Memory snapshots capture process state too, and they are experimental. Taking one ends the sandbox, the snapshot expires after 7 days, open TCP connections are closed, and a sandbox restored from one can't use a GPU.
Modal sandboxes can also mount Volumes and cloud buckets, so files an agent writes there outlive any one sandbox without a snapshot.
E2B vs Modal pricing for the same sandbox
A sandbox with 2 vCPUs and 4 GiB of memory costs $0.1656 an hour on E2B at any load. On Modal the same shape costs $0.2380 an hour when the CPU is requested or busy, and $0.1138 an hour when the sandbox requests no CPU and sits at 10% load. The gap comes from the billing model: E2B bills what you provision, and Modal bills the higher of what you request and what you use.
| Inputs for 2 vCPUs and 4 GiB | One hour, CPU busy | One hour, CPU at 10% | 500 hours a month | |
|---|---|---|---|---|
| E2B | 2 × $0.0504 + 4 × $0.0162, provisioned | $0.1656 | $0.1656 | $82.80 |
| Modal Sandboxes | 1 core × 3,600 × $0.00003942 + 4 GiB × 3,600 × $0.00000667 | $0.2380 | $0.1138 with no CPU requested | $56.90 to $119.00 |
The inputs behind the Modal figures: one Modal core is 2 vCPUs, and sandboxes bill at Modal's non-preemptible rates, which are three times its list rates for functions. Every container has a 0.125-core minimum. Ten percent of 2 vCPUs is 0.1 cores, which is under the minimum, so the minimum is billed: 0.125 × 3,600 × $0.00003942 is $0.0177, plus $0.0960 for 4 GiB of memory. A sandbox that requests 2 vCPUs is billed for them whether it uses them or not. The 500-hour column is the hourly figure times 500, which is about 1,000 agent sessions of 30 minutes each.
Plan fees and limits sit on top of usage:
- E2B Hobby has no monthly fee and comes with a one-time $100 usage credit. It allows 10 running sandboxes and sessions up to 1 hour, with 10 GiB of disk per sandbox included.
- E2B Pro is $150 a month plus usage. It allows 100 running sandboxes, 24-hour sessions, custom CPU and memory, and 20 GiB of disk per sandbox. Paid add-ons raise the concurrency limit to 600 or 1,100.
- Modal Starter is $0 a month plus usage and includes $30 of credits each month. It allows 250 containers and 10 GPUs at once.
- Modal Team is $250 a month plus usage and includes $100 of monthly credits, with limits of 10,000 containers and 50 GPUs.
Our E2B pricing and Modal pricing guides work through larger workloads on each.
GPUs, images and SDKs
Modal can attach a GPU to a sandbox and E2B can't. E2B's pricing page says its sandboxes are CPU-only. If the code an agent writes is itself a GPU job, such as a training script or a model evaluation, that settles the choice between these two.
On Modal, a GPU sandbox runs on the gVisor runtime and, unlike a CPU sandbox, can be preempted. GPU time is billed at Modal's standard GPU rates: $0.000164 a second for a T4, which is $0.59 an hour, $0.000306 for an A10, which is $1.10 an hour, and $0.001097 for an H100, which is $3.95 an hour. CPU and memory are billed alongside the GPU.
Environments are defined differently too:
- E2B templates are built with a template SDK or the CLI from a base image plus build steps. A start command runs at build time and its result is captured in the template, so a sandbox boots with that process already running.
- Modal images are defined in code with method chaining or pulled from a container registry, the same way as for Modal functions. Modal recommends named, pre-built images for sandboxes so nothing is built at launch.
E2B ships SDKs for Python and for JavaScript and TypeScript, a code interpreter that runs Python, JavaScript, TypeScript, R, Java and Bash, and a Desktop sandbox for computer-use agents. Modal's primary SDK is Python. Its JavaScript and Go SDKs are in beta and working toward parity with the Python one, and they cover sandboxes.
Network controls and public URLs
Both platforms can cut a sandbox off from the internet, restrict it to an allowlist and give a port a public URL.
- E2B leaves internet access on by default and takes an
allowOutanddenyOutlist when a sandbox is created. Domain names and wildcards work in the allow list, deny rules take IP ranges only, and allow rules win over deny rules. Each sandbox can hold up to 1,500 outbound TCP connections at once. Every port gets an HTTPS hostname. - Modal takes
block_network=Trueto stop all outbound traffic, oroutbound_cidr_allowlistfor IP ranges. A domain allowlist is in beta and covers TLS traffic on port 443. Ports are published as tunnels listed at creation, an inbound CIDR allowlist limits who can connect, and connect tokens authenticate HTTP requests to a sandbox.
Our guide to sandboxing AI-generated code covers how to set timeouts and network rules for code a model wrote.
E2B vs Modal for long-running coding agents
For a coding agent that works for hours and comes back the next day, E2B fits better out of the box, because a pause keeps the agent's processes and a paused sandbox is kept indefinitely. Modal caps a sandbox at 24 hours and recommends filesystem snapshots to carry state past that, which means the agent's processes start again in a new sandbox.
Neither is a permanent machine. An E2B sandbox runs for at most 24 hours at a stretch on Pro, and the clock resets after a pause and resume, so a long-lived agent needs something to pause and resume it. Both bill a running sandbox for its full size while the agent waits on a model, apart from Modal's CPU when none is requested.
A persistent VM is the other way to run this kind of agent. A Beam VM is a named Linux machine in a microVM with a root disk that persists. Pausing it keeps memory and processes and stops compute billing, and it has no session cap. VMs are CPU-only.
beam vm new agent-box --cpu-tier shared --cpu 2 --memory 4096
beam vm update agent-box --ttl 300 --idle-action pause --auto-resumeThe second line pauses the VM after five idle minutes and resumes it on the next connection. The idle timer counts connections such as SSH sessions and SDK calls, not commands running inside the VM, so leave it unset while an agent works unattended. On the Shared tier a 2 vCPU, 4 GiB VM is $0.011 per vCPU-hour plus $0.0055 per GiB-hour, which is $0.044 an hour while it runs. The --cpu-tier flag needs beam-client 0.2.236 or later. Our AI agent hosting guide compares VMs, sandboxes and serverless for agents in more detail.
A third option for GPU sandboxes
If you want E2B's kind of sandbox API with a GPU attached, a Beam sandbox covers that case. It is a disposable environment you drive from Python or TypeScript. It runs in a container by default, and use_vm=True runs a CPU sandbox in a microVM instead. This one runs on the Shared CPU tier, installs a package into the image, runs code and saves the filesystem as a reusable image:
from beam import Image, Sandbox
sb = Sandbox(
cpu=2,
memory="4Gi",
cpu_tier="shared",
image=Image(python_version="python3.11").add_python_packages(["pandas"]),
keep_warm_seconds=1800,
).create()
try:
result = sb.process.run_code("import pandas as pd; print(pd.__version__)")
print(result.stdout)
# Save the filesystem; Image.from_id(image_id) boots new sandboxes from it
image_id = sb.create_image_from_filesystem()
finally:
sb.terminate()keep_warm_seconds is the sandbox's lifetime, not an idle timer, so 1800 ends it after 30 minutes unless you call update_ttl(), and -1 removes the limit. The cpu_tier argument needs beam-client 0.2.236 or later. On supported runtimes snapshot_memory() captures process state as well as files, and new sandboxes start from that point.
The same 2 vCPU, 4 GiB shape is $0.044 an hour on Beam's Shared tier ($0.011 per vCPU-hour plus $0.0055 per GiB-hour, for sandboxes up to 8 vCPUs and 16 GiB) and $0.14 an hour on the Performance tier ($0.05 plus $0.01), which is the default for new accounts. A third tier, Spot, is $0.0063 per vCPU-hour plus $0.00135 per GiB-hour, or $0.018 an hour for this shape. Spot capacity is preemptible, so it suits work that can be interrupted and restarted. To use a GPU, pass gpu with a model name such as "RTX4090". A GPU sandbox bills the GPU rate plus GPU-attached CPU and memory: $0.69 an hour for an RTX 4090, $0.18972 per vCPU-hour and $0.0198 per GiB-hour. With 2 vCPUs and 4 GiB that is $0.69 + $0.3794 + $0.0792, or about $1.15 an hour.
How to choose between E2B and Modal
Start from what the sandbox has to do, because the two are built for different jobs.
- The agent keeps state in running processes between turns: E2B. Pause and resume are part of the product, and paused sandboxes are kept.
- The code needs a GPU: Modal, or a Beam sandbox. E2B is CPU-only.
- You already run inference or batch jobs on Modal: Modal Sandboxes, so images, Volumes and secrets are shared with the rest of your app.
- You need Docker inside a Modal sandbox: use its VM runtime; the gVisor runtime is the one that takes GPUs.
- Most sandbox time is spent waiting on a model: compare Modal's usage-based CPU billing with E2B's provisioned rate using the table above and your own CPU profile.
- Your backend is TypeScript: both work. E2B's JavaScript SDK is a first-class SDK, and Modal's is in beta.
- You have to run it in your own cloud: E2B's code is Apache-2.0 and its BYOC offering is for Enterprise customers. Modal is a managed service.
- The agent needs a machine that lasts for weeks: neither is built for that; use a persistent VM.
If neither fits, our E2B alternatives and Modal Sandbox alternatives guides compare more options, including Daytona, Vercel Sandbox and Cloudflare.
FAQ
What is the difference between E2B and Modal?
E2B is a dedicated sandbox service for AI agents, with a Firecracker microVM per sandbox and a pause that keeps memory. Modal is a serverless compute platform for AI workloads, and Sandboxes are one of its primitives, with gVisor isolation by default, optional GPUs and snapshot-based state.
Is E2B or Modal better for AI agents?
It depends on the agent. E2B suits agents that need a stateful session on CPU, since a paused sandbox keeps its processes and is stored until you delete it. Modal suits agents whose code needs a GPU, or teams that already run their models on Modal.
Does E2B support GPUs?
No. E2B's pricing page says sandboxes are CPU-only, with 1 to 8 vCPUs and 1 to 8 GiB of memory. Modal Sandboxes can attach a GPU on the gVisor runtime, and Beam and Daytona offer GPU sandboxes too.
How long can an E2B or Modal sandbox run?
An E2B sandbox runs for up to 1 hour at a time on Hobby and 24 hours on Pro, and pausing and resuming resets that limit. A Modal sandbox has a default lifetime of 5 minutes and a maximum of 24 hours, and Modal recommends filesystem snapshots for work that has to continue past that.
How much do E2B and Modal sandboxes cost?
E2B charges $0.0504 per vCPU-hour and $0.0162 per GiB-hour for the size you provision, so 2 vCPUs and 4 GiB cost $0.1656 an hour. Modal charges $0.00003942 per core-second and $0.00000667 per GiB-second on the higher of request and use, so the same shape costs $0.2380 an hour with the CPU busy and $0.1138 with no CPU requested at 10% load. E2B Pro adds $150 a month, and Modal's Starter plan has no monthly fee.
Can you self-host E2B or Modal?
E2B publishes its SDK and infrastructure code under the Apache-2.0 license, and its BYOC offering on AWS, Google Cloud and Azure is available to Enterprise customers. Modal is a managed service; only its client library and CLI are open source.
What are the alternatives to E2B and Modal?
Daytona, Vercel Sandbox, Cloudflare's sandboxes and Beam are the usual shortlist. Daytona and Beam offer GPU sandboxes, Vercel bills CPU only while it is active, and Beam also has persistent VMs that pause with memory. Our Vercel Sandbox alternatives guide prices one sandbox shape on all of them.
Run agent code on Beam
A Beam sandbox gives agent code an isolated environment with optional GPUs and filesystem and memory snapshots, and a Beam VM keeps a long-lived agent's memory and processes between sessions. Create a Beam account to run the snippet above. Current rates are on the Beam pricing page.
