Compute and browsers

E2B API for AI agents: what a sandbox costs per second, minute and hour

How E2B sandboxes run agent-written code, what an execution returns, the per-vCPU-second arithmetic, and why idle time, not code, is what you pay for.

#e2b#ai-agents#code-sandbox#code-execution#data-analysis#pricing#firecracker

Your agent wrote some code and now needs to run it somewhere that is not your server. E2B gives it an isolated Linux VM in the cloud: send the code, get back stdout, errors and any charts, and pay per second while the VM is alive. The surprise is how small the per-second price is and how little it has to do with the code. A 5-second sandbox at E2B's default size costs $0.00015, about 1% of one Tavily advanced search; a sandbox left open for an hour costs 720 times more. This guide gives you the arithmetic, the fields, and the four habits that turn cheap into expensive.

$0.000014per vCPU-secondE2B list price, Oct 2026
$0.0000045per GiB-second of RAMstorage is free
$100one-time credits on Hobby$0 monthly fee
1 hourmax continuous runtime on Hobby24 h on Pro at $150/mo

Why this matters for agents

A person opens a notebook, runs a few cells, and closes it. An agent creates a sandbox per task, or per tool call, and forgets about it. That changes what you pay for.

Billing is per second of a running sandbox, not per execution. "You pay per second for compute resources while your sandbox is running", and "once a sandbox is paused, killed or times out, billing stops immediately" (billing). Ten runCode() calls in one sandbox and zero calls in one sandbox cost the same for the same wall-clock time.

Resources are chosen at template build time, not per call. The default sandbox is 2 vCPU and 512 MiB; cpuCount and memoryMB are set when you build a custom template, up to 8 vCPU and 8 GiB on Hobby (compute). An agent cannot ask for more RAM mid-run.

Creation is rate-limited: 1 sandbox per second on Hobby and 5 on Pro, with 20 and 100 concurrent sandboxes respectively (limits). An agent that spins up a fresh sandbox for every snippet hits the creation rate long before it hits the money. API endpoints are limited to 10 requests per second per endpoint on Hobby (20 on Pro), with a Retry-After on 429 that SDKs from 2.49.1 honour automatically.

The timeout is the budget. Every SDK example creates a sandbox with a 60-second timeout, and the runtime hard limit is 1 hour on Hobby or 24 on Pro (sandbox lifecycle). The agent's timeoutMs is the most it can spend on one sandbox if it crashes before calling kill(). Set it as if you expect to crash.

What E2B returns

The Code Interpreter SDK's runCode() returns an execution object. The JavaScript example prints it in full:

Field What it holds
results[] Rich outputs of the cell: charts as base64 png, tables, the value of the last expression
logs.stdout[], logs.stderr[] Arrays of printed lines, not one string
error undefined on success; otherwise name, value and traceback
executionCount Cell number within this sandbox's kernel, starting at 1

results is empty more often than new users expect. In the docs' TypeScript example the HTTP response lands in logs.stdout and results is []; the Python version of the same code puts it in results instead. A script that only print()s puts everything in logs.stdout. A chart appears as a result whose png is "in base64 format", and E2B's data analysis guide tells you to check execution.error first, then iterate results looking for png.

Variables persist between runCode() calls in the same sandbox, so an agent can load a dataset once and query it several times. Python is the default; language: "ts", "js", "r", "java" and "bash" select the others.

sandbox.getInfo() is worth a call before a long task. The lifecycle docs' example shows a sandbox created with only a timeout reporting onTimeout: 'kill' and autoResume: false, meaning it will be destroyed, not paused, when the clock runs out (sandbox lifecycle).

The economics

E2B charges "$0.000014 per vCPU-second" and "$0.0000045 per GiB-second" of RAM, with storage free (pricing, as of October 2026). The Hobby plan is $0 a month with $100 in one-time credits; Pro is $150 a month plus usage. There is no per-call or per-execution fee.

At the default 2 vCPU and 512 MiB, one second costs 2 × $0.000014 + 0.5 × $0.0000045 = $0.00003025. That gives:

One default sandbox (2 vCPU, 512 MiB) by runtimeE2B list prices, October 2026
10 seconds: $0.0003 10 seconds $0.0003 1 minute: $0.0018 1 minute $0.0018 10 minutes: $0.018 10 minutes $0.018 1 hour: $0.109 1 hour $0.109 $0$0.1$0.2

Source: E2B pricing · Default resources from the sandbox compute docs; per-second rate is 2 x $0.000014 + 0.5 x $0.0000045.

View data
ItemValue
10 seconds$0.0003
1 minute$0.0018
10 minutes$0.018
1 hour$0.109
  • 10 seconds: 10 × $0.00003025 = $0.0003
  • 1 minute: 60 × $0.00003025 = $0.0018
  • 1 hour: 3,600 × $0.00003025 = $0.109

Bigger sandboxes scale linearly. At 2 vCPU and 4 GiB, a second is $0.000028 + $0.000018 = $0.000046, so an hour is $0.166. At the Hobby maximum of 8 vCPU and 8 GiB it is $0.000148 a second, $0.53 an hour.

The idle multiplier. An agent that runs a 5-second script in a sandbox created with timeoutMs: 300_000 and never calls kill() pays for 300 seconds, not 5: $0.009 instead of $0.00015, a 60x difference. Across 1,000 tool calls that is $9 versus $0.15. The $100 of Hobby credits covers about 55,000 one-minute sandboxes, or 918 one-hour ones.

One hour at 2 vCPU and 4 GiBPay-as-you-go list prices, October 2026
Modal: $0.079 Modal $0.079 Vercel Sandbox, Pro, 10% CPU: $0.11 Vercel Sandbox, Pro, 10% CPU $0.11 E2B: $0.166 E2B $0.166 Daytona: $0.166 Daytona $0.166 $0$0.1$0.2

Source: E2B pricing · Modal bills per physical core (2 vCPU); Vercel bills active CPU only, shown at its docs' 10% assumption. See References.

View data
ItemValue
Modal$0.079
Vercel Sandbox, Pro, 10% CPU$0.11
E2B$0.166
Daytona$0.166

Daytona prices vCPU at $0.0504 an hour and memory at $0.0162 per GiB-hour, which is the same $0.1656 at this size. Modal charges $0.0000131 per physical core-second (a core is 2 vCPU) and $0.00000222 per GiB-second, so about $0.079. Vercel Sandbox meters active CPU at $0.128 per vCPU-hour and provisioned memory at $0.0212 per GB-hour; its own example assumes 10% CPU utilisation "reflecting time spent waiting for LLM calls", which is $0.11 an hour, but at full CPU the same sandbox is $0.34. Which is cheapest depends on whether your sandbox computes or waits.

How to call it from your agent

AMXP is in private preview. Once it opens, running a snippet looks like this:

ts
const [tool] = await amxp.discover({ query: "run python code in a sandbox", provider: "e2b" })
const spec = await amxp.inspect(tool.id)   // per-second price and resource size
const run = await amxp.execute(tool.id, {
  code: "import pandas as pd\ndf = pd.DataFrame({'x': [1, 2, 3]})\nprint(df.describe())",
  language: "python",
  timeoutMs: 60_000,   // the most this call can bill: 60 s x $0.00003025 = $0.0018
})
// run.output.logs.stdout, run.output.results, run.output.error

code and language mirror the arguments of runCode(); timeoutMs mirrors the option on Sandbox.create(), which is milliseconds in the JavaScript SDK and seconds (timeout) in Python (sandbox lifecycle).

With your own E2B key (E2B_API_KEY), the direct SDK call is:

ts
import { Sandbox } from "@e2b/code-interpreter"

const sbx = await Sandbox.create({ timeoutMs: 60_000 })
try {
  const execution = await sbx.runCode("print(2 + 2)")
  if (execution.error) throw new Error(execution.error.traceback)
  console.log(execution.logs.stdout)
} finally {
  await sbx.kill()   // billing stops here, not at the timeout
}

What most people get wrong

Leaving sandboxes running. The sandbox bills until kill(), pause, or timeout. Put kill() in a finally, and keep timeoutMs short enough that a crashed agent cannot run up an hour. If the agent needs the state later, pause() instead: billing stops, the filesystem and memory are kept "indefinitely" and a resume takes about 1 second (persistence).

One sandbox per snippet. Creation is limited to 1 per second on Hobby, and each new VM throws away the packages you installed and the data you loaded. Reuse one sandbox for a task; variables persist across runCode() calls.

Reading results and ignoring logs. A print-only script returns results: []. Read error first, then logs.stdout, then results for charts and the last expression's value.

Mixing up timeout units. timeoutMs: 60 in JavaScript is 60 milliseconds and the sandbox dies before the kernel starts. timeout=60_000 in Python is 16.7 hours and exceeds Hobby's 1-hour limit.

Calling setTimeout() to extend and assuming it adds. It resets: setTimeout(30_000) means 30 seconds from now, whatever was left. connect() to a paused sandbox defaults to a 5-minute timeout and only ever extends.

When to use something else

  • Other code sandboxes. Daytona matches E2B's rate to the cent at 2 vCPU and 4 GiB and starts with $200 of credit. Vercel Sandbox is cheaper when the sandbox mostly waits on an LLM, and its Hobby tier includes 5 CPU-hours a month at no cost. Runloop is built around devboxes for coding agents.
  • GPUs or serverless functions. Modal is the cheapest CPU-hour in the chart and adds GPUs and scheduled functions. Fly.io if you want full machines.
  • Long-lived, stateful work. If the agent needs a sandbox for hours or days, E2B's pause and resume on your own account is simpler than per-call runs; a paused sandbox has no time-to-live.
  • Steady volume. If your product runs sandboxes all day, Pro's 100 concurrent sandboxes, 24-hour runtime and 5-per-second creation rate are the reason to open an E2B account. AMXP is for the occasional run where another account is not worth it.

Common questions

How long can an E2B sandbox run?

Up to 1 hour continuously on Hobby and 24 hours on Pro. Pausing resets that window, and a paused sandbox "is kept indefinitely" with no automatic deletion (billing and limits). Pausing takes about 4 seconds per GiB of RAM.

Can the agent get charts back?

Yes. When code produces a plot, it appears in results as a base64 png, which the agent can decode and save. E2B's data analysis guide walks through this with a CSV.

Is the code isolated from my machine?

Yes. Each sandbox is an isolated Linux VM in E2B's cloud (sandbox lifecycle). Sandboxes have outbound internet access by default, so restrict it if the code should not reach the network.

AMXP is in private preview; the flow above shows how it works through AMXP once it opens.

References

  1. E2B pricing, E2Be2b.dev/pricing
  2. E2B billing and limits, E2Bdocs.e2b.dev/billing
  3. E2B limits, E2Bdocs.e2b.dev/limits
  4. E2B sandbox lifecycle, E2Bdocs.e2b.dev/sandbox
  5. E2B sandbox compute, E2Bdocs.e2b.dev/sandbox/compute
  6. E2B sandbox persistence, E2Bdocs.e2b.dev/sandbox/persistence
  7. Analyze data with AI, E2Bdocs.e2b.dev/code-interpreting/analyze-data-with-ai
  8. Run JavaScript and TypeScript code, E2Bdocs.e2b.dev/code-interpreting/supported-languages/javascript
  9. E2B internet access, E2Bdocs.e2b.dev/network/internet-access
  10. Daytona pricing, Daytonawww.daytona.io/pricing
  11. Modal pricing, Modalmodal.com/pricing
  12. Vercel Sandbox pricing, Vercelvercel.com/docs/vercel-sandbox/pricing
  13. Tavily credits and pricing, Tavilydocs.tavily.com/documentation/api-credits

Cite as: AMXP, “E2B API for AI agents: what a sandbox costs per second, minute and hour,” AMXP, November 4, 2026. https://amxp.ai/blog/e2b-api-for-ai-agents · Markdown version