The formula
Current rates
These rates are shown for convenience and can change. The pricing page and its usage cost calculator are the source of truth for current prices.
Worked example
A default sandbox has 2 vCPU and 512 MiB (0.5 GiB) of RAM. Running it for 1 hour:- vCPU:
2 x $0.0504 = $0.1008 - RAM:
0.5 x $0.0162 = $0.0081 - Total: about $0.109 for the hour
$0.109 x (300 / 3600) = $0.009.
Get the numbers for your own sandboxes
You need three inputs: vCPU, RAM, and running time.vCPU and RAM of a running sandbox
getInfo() returns the sandbox’s allocated cpuCount and memoryMB. Use Sandbox.list() to get the same fields for all of your running and paused sandboxes at once.
Running time
For completed runs, set up lifecycle event webhooks. Thesandbox.lifecycle.killed and sandbox.lifecycle.paused events carry an event_data.execution object with everything you need to compute cost for that run:
vcpu_countandmemory_mb- the resources that were allocatedexecution_time- how long the sandbox ran, in millisecondsstarted_at- when the run began
sandbox.lifecycle.created event does not include resource allocation, so read compute off the killed and paused events (or from getInfo while the sandbox is still running).
Example: cost from a webhook
The handler below receives lifecycle deliveries, and whenever a sandbox is killed or paused it readsevent_data.execution and applies the formula above to log the cost of that run.
In production, verify the
e2b-signature header and deduplicate on the e2b-delivery-id header, since a delivery can be retried and arrive more than once. See Sandbox lifecycle webhooks for registration and the full payload.Reducing your bill
Do I pay for paused or stopped sandboxes?
Do I pay for paused or stopped sandboxes?
No. Billing stops the moment a sandbox is paused or killed. See Do paused sandboxes count toward the concurrency limit?
How do I allocate less compute?
How do I allocate less compute?
Start with the default resources (2 vCPU, 512 MiB RAM) and only increase them if you need to. You set
cpuCount and memoryMB when building a custom template. See Billing & limits.Where do I see my actual costs?
Where do I see my actual costs?
In the dashboard usage tab. You can also set a spending limit on the budget page.