Feature: per-session CPU/memory override in Sandbox.create()
Summary
Sandboxes created from the same template share identical CPU and memory allocation set at template build time. There is no way to override resource limits at sandbox creation time via Sandbox.create() — even though the orchestrator gRPC proto already carries the vcpu and ram_mb fields end-to-end.
This gap was first raised in #1257 (closed April 2026 without implementation, redirected to read-only metrics). This issue proposes a concrete, minimal fix across the SDK and API layers.
Current behaviour
# The only way to control resources today:
# Build a separate template for each resource tier
# — no runtime override exists
sandbox = await Sandbox.create("my-template") # always uses template's fixed Vcpu/RamMb
Desired behaviour
sandbox = await Sandbox.create(
"my-template",
cpu_count=2, # override template default
memory_mb=1024, # override template default
)
Why this matters
- Multi-tenant workloads: different tasks have very different resource requirements (a data analysis job needs more RAM than a simple shell command)
- Cost control: code execution agents can now right-size each sandbox instead of provisioning a large template for all tasks
- Security: a per-session limit bounds the blast radius of a runaway process; currently an OOM kill makes the entire sandbox unresponsive (issue #339) with no pre-emptive cap
Root cause
The infrastructure proto (orchestrator.proto, fields 26–27) already defines int64 vcpu and int64 ram_mb in SandboxConfig. The orchestrator already reads these fields. The gap is that the HTTP API layer hard-codes them from the template's build record rather than accepting them from the caller:
// packages/api/internal/orchestrator/create_instance.go
// Vcpu and RamMb always come from sbxData.Build, never from the HTTP request body
Proposed fix (minimal, two-repo)
e2b-dev/e2b (SDK + OpenAPI spec)
spec/openapi.yml— the spec already defines reusableCPUCountandMemoryMBcomponents; add them toNewSandboxschema as optional fieldspackages/python-sdk/e2b/sandbox_async/main.py— addcpu_count: int | None = Noneandmemory_mb: int | None = NonetoAsyncSandbox.create()packages/python-sdk/e2b/sandbox_sync/main.py— same for sync variant- Pass through to the generated API client in
sandbox_api.py
e2b-dev/infra (API service layer)
packages/api/internal/orchestrator/create_instance.go— ifreq.CpuCount != nil, use it instead ofsbxData.Build.Vcpu; same forMemoryMb- Add validation:
cpu_countmust not exceed the template's original allocation unless the team has theresource_overridepermission flag
No Firecracker or envd changes are needed — the VM's hard memory cap is already set at launch from the Vcpu/RamMb values in the orchestrator.
Willingness to contribute
Happy to submit a PR to e2b-dev/e2b covering the OpenAPI spec and Python SDK changes (steps 1–4). The e2b-dev/infra change (step 5) may need maintainer guidance on the validation/permission model.
thanks, we are aware that users want this and it's currently on the roadmap