Skip to main content
A template normally fixes the CPUs and memory of every sandbox created from it. A resizable template sets a maximum next to each, and every sandbox chooses its own size up to that maximum:
  • When it is created: Sandbox.create() takes cpuCount and memoryMB in JavaScript or cpu_count and memory_mb in Python.
  • When it resumes or reboots after a pause: Sandbox.connect() takes them inside onResume in JavaScript or on_resume in Python.
A running sandbox is never resized. Sizes are chosen only when a sandbox starts.
Resizable templates are currently in private beta. If you’d like access, please reach out to us at support@e2b.dev.CPU resizing on create needs the E2B SDK 2.64.0 or later. Resizable memory, and choosing sizes on connect(), need SDK 2.66.0 or later.

Build a resizable template

Set maxCpuCount and maxMemoryMB in JavaScript or max_cpu_count and max_memory_mb in Python next to cpuCount and memoryMB. The cpuCount and memoryMB of the template are what a sandbox starts with when it doesn’t ask for anything else.
The same options work with Template.buildInBackground() in JavaScript or Template.build_in_background() in Python. You can make a template resizable for CPUs only, memory only, or both. Leave a maximum out and that resource stays fixed, as before.

Choose the size when you create a sandbox

Pass cpuCount and memoryMB in JavaScript or cpu_count and memory_mb in Python to Sandbox.create(). Leave them out to use the template’s own cpuCount and memoryMB.
On a template that isn’t resizable, only its own cpuCount and memoryMB are accepted.

Choose the size when you resume or reboot

When you connect to a paused sandbox, pass an onResume object in JavaScript or an on_resume dict in Python. It sets how the sandbox comes back and the size it comes back with:
  • action: 'restore' (the default) restores the memory snapshot; 'reboot' reboots the sandbox from disk, like reboot on resume.
  • memoryMB: memory in MiB, from the size the sandbox was paused with up to the template’s maxMemoryMB, in steps of 128 MiB. A sandbox’s memory can only grow, so a size below the paused size is refused.
  • cpuCount: from 1 to the template’s maxCpuCount, up or down from the count it was paused with.
The sizes apply only when the call resumes a paused sandbox. If the sandbox is already running, or another request is already resuming it (for example auto-resume on inbound traffic), it keeps its size and the values you passed are ignored, with no error. Read the size back to see what the sandbox runs with.

What changes inside the sandbox

CPUs

The change is asynchronous. The sandbox brings CPUs online, or takes them offline, one at a time as it resumes, and connect() can return before that has finished. Until it has, nproc inside the sandbox can show a count in between. getInfo() in JavaScript or get_info() in Python reports the count you asked for from the start, not the count that is online at that moment. If your code depends on the CPU count, for example to size a worker pool, check it inside the sandbox before you use it:
When you lower the count, the highest-numbered CPUs are the ones removed: a sandbox resumed with 2 CPUs has CPUs 0 and 1.
A process pinned to specific CPUs, with taskset for example, loses that pin when its CPUs are removed: Linux moves it to the CPUs that remain, and it keeps running. If you rely on pinning, pin the process again after you raise the count.

Memory

Adding memory is asynchronous too. The sandbox adds it as it starts, and create() or connect() can return before all of it is in place. Processes can use the memory as it arrives. getInfo() in JavaScript or get_info() in Python reports the size you asked for from the start; to see what the sandbox has at that moment, read it inside the sandbox, with free -m for example.
Memory growth needs a recent version of the agent that runs inside the sandbox. If a template built a while ago refuses a larger memoryMB, rebuild the template.

Snapshots

A snapshot keeps the size of the sandbox it was taken from, and so does a filesystem-only snapshot. A sandbox created from one starts with that size unless you choose another. It can grow up to the template’s maximums, and it can’t have less memory than the snapshot has.

Read the sizes back

getInfo() in JavaScript or get_info() in Python on a sandbox returns the CPUs and memory it runs with. For a template, Template.list(), Template.getInfo() and Template.listBuilds() in JavaScript or Template.list(), Template.get_info() and Template.list_builds() in Python return the maximums next to the template’s CPUs and memory; both maximums are unset for a template that isn’t resizable.
e2b template list shows the maximums in its MAX VCPUS and MAX RAM MIB columns.

Billing

A sandbox is billed based on the size you request for it. The CPUs and memory chosen at a create, resume or reboot apply until the sandbox next pauses or stops. See Billing.