9 min
A guide to scaling sandboxes for concurrent AI agents
Learn how to scale sandboxes for AI agents. Size warm pools from burst create rate and p95 refill time, then gate every create with per-tenant quotas.

One agent sandbox is easy to run. Thousands of concurrent sandboxes, spread across many users and agents, turn into a capacity problem. Bursts collide with sandbox concurrency limits, and idle warm pools keep costing money between sessions.
Providers enforce those limits directly. E2B, for example, responds to excess requests with an HTTP 429 and a Retry-After header. Agent sandbox capacity planning has to treat quotas and burst traffic as design inputs from day one.
Idle warm pools and leaked sandboxes keep billing after the burst ends.
Key takeaways
- Sessions per user and parallel tasks per agent set peak live sandboxes. Bursts set the peak create rate, so track both.
- Warm pools trade idle spend for start latency. Faster creation shrinks the pool you need.
- Move idle sandboxes to standby and resume them on demand instead of paying for always-on capacity between turns.
- Gate every create request with per-tenant quotas, queues, and idempotency keys so bursts wait instead of failing.
- Check each provider's concurrency cap and create-rate quota against your peak live sessions and burst create rate.
What concurrency means for AI agent sandboxes
Concurrency for agent sandboxes is the count of isolated environments alive at one moment.
Three demand patterns feed it:
- Sessions per user: A developer running a coding agent in three repositories holds three sandboxes.
- Parallel tasks per agent: One agent edits code in one sandbox while another sandbox runs the test suite.
- Burst versus steady load: Steady load sets how many sandboxes stay alive. Bursts set how many must start per second.
Fan-out is a separate case, where one request splits into short parallel tasks whose results merge at the end. The fan-out execution guide goes deeper.
Choosing an isolation layer that scales
The isolation layer sets both the security boundary and the density ceiling. These figures mix papers, workloads, and versions, so read them as rough scale rather than a benchmark:
| Layer | Boundary | Startup | Memory per instance | Density or overhead |
|---|---|---|---|---|
| Docker (runc) | Shared host kernel | 571.6ms, measured (Goldilocks study) | 3.9 MiB (serverless study) | 3,000 Node.js instances per VM (SEUSS paper) |
| gVisor | User-space kernel | 684.4ms, measured (Goldilocks study) | 24.7 MiB (serverless study) | getpid 830ns on KVM platform vs 62ns native (Ant Group post) |
| Firecracker microVMs | Separate guest kernel | 2,421.8ms, measured (Goldilocks study). Spec target: up to 125ms to guest init (Firecracker spec) | Up to 5 MiB virtual machine monitor (VMM) overhead, spec, guest RAM excluded (Firecracker spec) | 450 Node.js instances per VM (SEUSS paper) |
Measured startup times come from one Goldilocks test bed, timed from VM init to container start with cached images. The Firecracker spec figures assume a minimal kernel and a 1 vCPU, 128 MiB guest. The SEUSS densities come from one 16-CPU, 88 GB VM running Firecracker through Kata Containers.
- Containers start fast, pack densely and share the host kernel. NIST SP 800-190 says a shared kernel creates a larger attack surface than hypervisors. The Cloud Security Alliance goes further. Its research note says "shared-kernel container isolation is insufficient for executing untrusted AI agent code at enterprise scale."
- Firecracker microVMs put a hypervisor between guest code and both the host and other tenants.
For tenant boundaries beyond the kernel, see the multi-tenant isolation guide.
Planning sandbox capacity for bursty agent traffic
Agent sandbox capacity planning starts with the warm pool, sized from burst arrivals and refill time. Little's Law relates mean occupancy to arrival rate multiplied by mean time in the system.
This heuristic swaps those means for a measured p95 refill time and a buffer:
pool size = burst create requests per second × p95 refill seconds × (1 + buffer)
The NSDI paper applies Little's Law with mean values. At 125ms per create, every 8 create requests per second need one pooled microVM. Set the buffer from measured burst variance. Decide what a drained pool does: queue the request, or create cold and accept the latency.
Pool depth and queue wait make better sandbox autoscaling triggers than CPU utilization, which lags a login burst.
Worked capacity-planning example
Every input is an assumption for a hypothetical coding-agent product.
Rows with a formula in the Basis column derive from those inputs:
| Item | Value | Basis |
|---|---|---|
| Peak live sessions | 2,000 | Assumption |
| Average session length | 20 minutes | Assumption |
| Steady arrival rate | 1.67 create requests per second | 2,000 ÷ 1,200 |
| Burst arrival rate | 20 create requests per second | Assumption |
| p95 refill (create) time | 3 seconds | Assumption |
| Buffer | 50% | Assumption |
| Memory per sandbox | 2 GiB | Assumption |
| Idle share of session time | 70% | Assumption |
| Warm pool size | 90 sandboxes | 20 × 3 × 1.5 |
| Always-on memory per peak hour | 14,400,000 GiB-seconds | 2,000 × 2 × 3,600 |
| Active memory with idle in standby | 4,320,000 GiB-seconds | 14,400,000 × 0.3 |
| Warm pool memory per peak hour | 648,000 GiB-seconds | 90 × 2 × 3,600 |
Multiply each GiB-second figure by your provider's rate. In this hypothetical, moving idle sessions to standby removes 70% of peak-hour compute. The pool adds 15% on top of active use. Storage for standby state bills separately. Fast create is the alternative to a large warm pool, since pool size scales with refill time. If create time drops to 1 second, the pool falls to 30 sandboxes.
How to enforce per-tenant quotas and backpressure
Without admission control in front of the create API, one tenant's batch run can drain a shared provider quota:
- Per-tenant token buckets: Refill each tenant's bucket at a set rate up to a burst capacity. AWS's fairness article warns that an oversized burst capacity defeats the limit.
- Per-tenant queues: Queue each tenant's excess create requests separately. Dispatch with fair queuing, so the tenant sending the most requests waits in its own line.
- Retry budgets: Let a client retry only while retries stay below 10% of requests, per Google SRE guidance. E2B's
Should-Retryheader separates temporary capacity failures from permanent ones, so clients know which failures to retry. - Idempotent create: A client-generated key makes a retried create request return the original sandbox. Use V4 UUIDs for these keys, as Stripe suggests.
- Regional shards: Eight workers form 28 two-worker shards in AWS's shuffle sharding article. One tenant's blast radius drops to 1/28th. Assign tenants to regions with the same shuffle-sharding method, so one region's quota or outage hits only some tenants.
With these controls in place, a burst waits in line, and one tenant can't drain the shared quota.
How to cut idle cost with standby, TTLs, and reapers
Three lifecycle models trade idle compute against return time:
| Model | Compute while idle | Return path | State kept |
|---|---|---|---|
| Always-on | Billed | Immediate | Everything |
| Standby or pause | None, storage only | Resume | Memory and files, where supported |
| Recreate from template | None | Full creation plus setup | Only externally saved data |
Standby replaces always-on capacity for sessions that idle between turns. Compute stops while the sandbox waits, and the session returns by resume instead of a full create. Set a maximum lifetime and an inactivity time-to-live (TTL) on every sandbox at create time. Kubernetes' TTL-after-finished controller shows the pattern.
A timer starts when a Job finishes; then cascading deletion runs. A reaper catches what timers miss: sandboxes, volumes, and IPs with no owning session. Netflix's Janitor Monkey unmarks resources that become active again, so its reaper skips anything back in use. The scale-to-zero cost guide covers billing.
How to persist agent state without always-on sandboxes
Keep scratch files on the sandbox disk. Put durable work on volumes and shared context on a shared filesystem. Attached volumes add per-host limits. Most AWS Nitro instances allow 28 attachments, shared between volumes and network interfaces.
A volume still mounted in the guest can stick in the busy state, per AWS's DetachVolume reference. Detach can then stall indefinitely. A shared filesystem avoids moving volumes, because every sandbox mounts the same data. Unmount cleanly before standby and track attach latency per node.
Security controls that hold across thousands of sandboxes
Nobody reviews thousands of sandboxes one by one, so every control belongs in the template:
- Resource limits: Cap CPU and memory and restrict system calls against denial of service, per OWASP's agentic threats guidance.
- Egress allowlist: Set one up with the egress control guide. The OWASP Agentic Top 10 says to "Enforce outbound allowlists and deny all non-approved network destinations."
- Credential proxy: A proxy outside the sandbox adds credentials to allowlisted requests. Anthropic notes that "if credentials never enter the sandbox, they can't be exfiltrated."
Because each control lives in the template, every new sandbox starts with it.
Building on Kubernetes or using a managed sandbox provider
Kubernetes handles a small fleet with stock tooling. As the fleet grows, your team owns scheduler limits, runtimes, and pool controllers. Kubernetes v1.34 targets 110 pods per node, 5,000 nodes, and 150,000 total pods. The Kubernetes agent-sandbox project adds SandboxWarmPool, a pool of pre-created sandboxes.
A managed provider takes on that work, and your planning shifts to its sandbox concurrency limits and create-rate quotas. These limits come from each provider's own docs, checked on December 2, 2026:
| Provider | Concurrent sandboxes | Create rate |
|---|---|---|
| E2B | Hobby 10, Pro 100 (up to 1,100 with add-ons), Enterprise 1,100+ (billing and limits) | 1 per second Hobby, 5 per second Pro, Enterprise custom |
| Modal | Starter 250, Team 10,000, Enterprise custom (Sandboxes FAQ) | No per-plan cap in the Sandboxes FAQ |
| Daytona | No fixed count, compute pool of 10 vCPU (Tier 1) to 500 vCPU (Tier 4) (limits) | 300 to 600 per minute by tier |
Only running E2B sandboxes count toward concurrency, per its FAQ. Daytona's stopped, paused, and archived sandboxes no longer count CPU and memory against the compute pool. For the staffing and compute costs of running your own fleet, see the build-versus-buy breakdown.
Sandbox concurrency checklist
Run through this list before traffic grows again:
- Use separate-kernel isolation for untrusted code and measure density on your own agent image.
- Size the warm pool based on burst rate and p95 refill time, and decide what a drained pool does.
- Put per-tenant token buckets, queues, and retry budgets in front of every create request.
- Send an idempotency key with every create request, and retry only failures marked temporary.
- Set a maximum lifetime and inactivity TTL on every sandbox, and reap ownerless sandboxes, volumes, and IPs.
- Move durable state to volumes or a shared filesystem, and track attach latency.
- Enforce egress allowlists and proxy-based secret injection from the template.
- Alarm on NAT port allocation errors.
Any unchecked item is a failure point the next burst will find. Start with the create path in items 2 through 4.
How Baseten Sandboxes help
Baseten Sandboxes address two of these failure points: burst creation and idle spend. Every sandbox gets its own Firecracker microVM. Creation takes under a second, so a burst needs only a small warm pool. An idle sandbox enters standby after about 15 seconds of network inactivity. Returning sessions resume from standby in under 25ms without a new create request. As a result, you hold less warm capacity between agent turns.
FAQs about scaling AI agent sandboxes
How many concurrent sandboxes can one AI agent product run?
Two ceilings apply: your provider's concurrency quota and the number of sandboxes each host holds before tail latency climbs. E2B's published plan limits run from 10 on its Hobby tier to 1,100+ on Enterprise. Plan for peak live sessions and the burst create rate.
Should I use a warm pool or create sandboxes on demand?
Use a warm pool when creation takes long, and bursts are sharp. Pooled sandboxes bill compute while they wait. If creation takes under a second, or idle sessions resume from standby, a much smaller pool covers the same burst.
How do I stop one tenant from exhausting sandbox capacity?
Put admission control in front of the create API. Give each tenant a token bucket with a bounded burst and its own queue. Fair queuing then serves tenants in turn, so one busy tenant can't starve the rest.
Which metrics show a sandbox fleet is healthy under load?
Alert on p99 create and resume latency, and on the count of sandboxes with no owning session. Averages hide both failures.
Related articles

Guides
A guide to OpenSandbox alternatives for managed AI agent sandboxes
Compare OpenSandbox alternatives on isolation and idle behavior. See how Baseten Sandboxes, E2B, Daytona, Modal, and Vercel Sandbox fit agent workloads.
11 min read

Guides
What infrastructure do multi-agent AI systems need?
Learn the seven layers of multi-agent AI infrastructure, from orchestration to cost controls. See where isolated sandboxes fit and what each layer stops.
11 min read

Guides
A guide to GitHub Codespaces alternatives for secure AI agent sandboxing
Compare GitHub Codespaces alternatives for AI agents, from Coder and Ona cloud IDEs to Baseten Sandboxes, Daytona, E2B, and Modal, with criteria for choosing.
11 min read