Moving from E2B
Updated
Run E2B Python and TypeScript code on Prized sandboxes by changing its imports (code that creates sandboxes, runs commands, moves files, pauses and forks), map each E2B call to the Prized API and CLI, and see what works differently and what is not on Prized yet.
On this page7
An E2B sandbox becomes a Prized sandbox: a Firecracker microVM that boots from a template, pauses with its memory and processes, and forks into live copies (how they compare). prized_e2b.py for Python and prized-e2b.ts for TypeScript are one file each that keep the names, results, and errors of E2B's sandbox, command, and file calls and speak the Sandbox API, so E2B code that sticks to those calls (synchronous in Python) runs once you change its imports. The adapter has no get_host or Python AsyncSandbox yet, though a sandbox's ports do have https URLs (Not in the adapter), and sandboxes have no run_code code interpreter or streamed output over the API (Not on Prized yet).
1. Make a key
On the API keys page, make a key with Sandboxes: Write, then export it in place of E2B_API_KEY:
export PRIZED_API_KEY=dcp_…On the free credit alone, sandboxes run within the free tier: up to 10 at once, 2 vCPU and 4 GB each, and 60 minutes of running per sandbox, then it is deleted. A plan or a top-up lifts the workspace to the full quotas.
2. Swap the import
Save the file for your language next to your code. prized_e2b.py needs Python 3.9 or later, prized-e2b.ts Node 18 or later (or any runtime with fetch), and neither needs anything else:
curl -fsSLO https://prized.dev/skills/prized-sandboxes/scripts/prized_e2b.pyThen change e2b to prized_e2b in your Python imports, or "e2b" to "./prized-e2b" in TypeScript ("./prized-e2b.ts" when Node runs the file itself). This harness sets up one sandbox, forks it into two builders, pauses it, and cleans up:
from prized_e2b import Sandbox # was: from e2b import Sandbox
base = Sandbox.create(timeout=3600, metadata={"job": "build-42"})
builders = []
try:
base.files.write("/home/user/app/main.py", "print(6 * 7)")
base.commands.run("python3 -m venv .venv")
builders = base.fork(count=2, timeout=600) # live copies: files, memory, processes
for i, b in enumerate(builders):
print(b.commands.run(f"python3 app/main.py && echo builder {i}").stdout)
base.pause() # kept on its machine, with its memory, until you delete it (30 days after last use on the free tier; disk only after a move to a different kind of machine)
base = Sandbox.connect(base.sandbox_id) # resumes it where it was
print(base.commands.run("ls app").stdout) # main.py
finally:
for s in [*builders, base]: # copies before their parent
s.kill()/home/user is /home/prized here: the file maps it in paths, commands, and environment variables, relative paths start in the home folder (the CLI's relative paths start in /home/prized/work), and files outside it, such as in /tmp, are copied through it. A command that exits non-zero raises CommandExitException and a missing file FileNotFoundException. An error from the API raises the matching E2B exception, such as RateLimitException past a quota, with the API's error as code and its answer as body.
In TypeScript, options, results, and errors keep E2B's JavaScript names, such as timeoutMs, onStdout, exitCode, CommandExitError, and RateLimitError, and an error from the API also carries its HTTP status as statusCode.
To write new code for Prized rather than keep E2B's calls, install the SDK (pip install prized, npm i @prized/sdk), whose Sandbox.create, exec, files, pause and fork cover the same steps (Sandbox SDK for Python and TypeScript).
3. Check each call
| E2B | Prized API | Prized CLI |
|---|---|---|
Sandbox.create(template, timeout, metadata, envs) | POST /api/v1/sandboxes with template, maxRuntimeMin, labels, envVars | prized sandbox create --max-runtime 1h --label job=42 --env K=V |
| CPU and memory on a template build | resources: {vcpu, memoryMb, diskGb} on each create | --vcpu 2 --memory 4 --disk 20 |
lifecycle={"on_timeout": "pause"} | autoPauseMin (after idle minutes), autoDeleteMin (after paused minutes) | --auto-pause 10m --auto-delete 1d |
sbx.commands.run(cmd, envs, cwd, timeout) | POST {toolboxBase}/ | prized sandbox exec ID --cwd app --env K=V --timeout 10m -- CMD |
sbx.files.write(), files.read() | POST {toolboxBase}/, GET {toolboxBase}/ | prized sandbox cp ./app.py ID:app.py, and the reverse |
sbx.pause(), Sandbox.connect(id) | POST /, /resume; any command resumes it too | prized sandbox pause ID --wait, prized sandbox resume ID |
sbx.fork(count, timeout) | POST / with count | prized sandbox fork ID --count 3 |
sbx.set_timeout(seconds) | POST /, or /extend | prized sandbox timeout ID --in 30m, prized sandbox extend ID --by 2h |
sbx.get_info(), is_running() | GET /api/v1/sandboxes/{id} | prized sandbox get ID |
Sandbox.list(query=SandboxQuery(metadata=…)) | GET /api/v1/sandboxes, then match labels | prized sandbox ls |
sbx.kill() | DELETE /api/v1/sandboxes/{id} | prized sandbox rm ID |
metadata becomes labels and envs becomes envVars. background=True returns a handle with wait() and kill(), files.write keeps the mode of a file it replaces (a script stays executable), and files.list, exists, make_dir, rename, and remove work as on E2B. Every route's fields and answers are on Sandbox API.
4. What works differently
- Size it on the create. Each sandbox takes 1 to 32 vCPU, 1 to 128 GB of memory, and 10 to 128 GB of disk, and is billed per second for its shape (Billing: Sandboxes). The adapter asks for 2 vCPU and 1 GB unless you pass
vcpu,memory_mb(memoryMbin TypeScript), ordisk_gb(diskGb) toSandbox.create; the API's own default is 4 vCPU and 8 GB (2 vCPU and 4 GB on the free tier). timeoutis run time. It (timeoutMsin TypeScript) becomesmaxRuntimeMin, rounded up to whole minutes: how long the sandbox runs before it is deleted, 5 minutes if you pass none. Paused time does not count; on a paid plan it goes up to 7 days (a top-up lifts it too) and each resume starts it again (Run time). On the free tier it is 60 minutes of running in all, then the sandbox is deleted, andset_timeoutcan only bring the end earlier, so pass the whole run time tocreate.- Pausing on timeout means pausing when idle. With
lifecycle={"on_timeout": "pause"},timeoutbecomesautoPauseMin: the sandbox pauses after that many minutes with no commands or file transfers, and the next one resumes it. Its run time, 24 hours by default (60 minutes in all on the free tier), still applies while it runs. - Paused sandboxes are kept, and stored. A paused sandbox keeps its memory and disk until you delete it, or on the free tier 30 days after its last use, on the machine it ran on: not backed up, so lost if that machine fails (Paused retention). A move to a different kind of machine keeps only its disk (Pause and resume). Its disk and saved memory count toward the workspace's paused storage, billed past an included amount (Billing: Sandboxes), and toward the workspace's disk quota: delete each one when its job is done, or pass
auto_delete_min=toSandbox.createto setautoDeleteMin. - Forks start on the parent's machine. A fork makes only as many copies as fit there, and a busy machine fits fewer. When they do not fit,
fork()raises withcodefork_capacityandbody["fits"], the number that fits now: fork that many, or create a fresh sandbox and fork it (Fork). Once the workspace has paid in, each copy gets the parent's run time unless you passtimeout; on the free tier copies end when the parent does. - Commands answer when they end.
on_stdoutandon_stderrare called once, with the whole output. A command with atimeoutof up to 4 minutes is one request, and each of its streams keeps its first 4 MiB; with a longertimeout, or none (0or infinity), the adapter runs it in the background and polls until it ends, and the sandbox stops it at that longertimeouteven if your program has exited. A command started withbackgroundruns until it ends or you kill it: unlike on E2B,timeoutdoes not stop it.kill(), andcommands.kill(pid)with the pid of a background command your program started, stop the command and what it started in its process group; once it has ended they answerFalserather than signal a process that has its pid now. So does one a Prized SDK started, until its output is cleaned up; any other pid is signalled alone, as on E2B. A background command, and one withon_stdoutoron_stderr, runs withPYTHONUNBUFFERED=1unlessenvsor the sandbox's own env sets it (""keeps Python's buffering), so a Python program's output is kept up to akill().
Not in the adapter
These are gaps in prized_e2b.py and prized-e2b.ts, not in sandboxes.
get_host(): ports have https URLs. The adapter raises, with the port's URL in its message. Every port of a sandbox has an https URL of its own,prized sandbox port ID PORTor the sandbox'spreviewUrlTemplate, that answers your API key in a header, a short-lived token in the URL, or anyone on a port you made public (tokens and public ports need a workspace that has paid in); with a token or on a public port, itsprized.linkaddress opens in a browser (Preview a port).AsyncSandbox. From async Python, callSandboxin a thread (asyncio.to_thread); every call inprized-e2b.tsis async already.
Not on Prized yet
- Templates from a Dockerfile, and root. Sandboxes start from
prized-base-v1,prized-agent-v1orprized-docker-v1as the userprized, without sudo; E2B'sbasemaps toprized-base-v1, aprized-name passes through, and any other name raisesTemplateException. Build and run your image with Docker onprized-docker-v1, once the workspace has paid in, passingmemory_mbanddisk_gbfor room (Run Docker and Compose in a sandbox), or set up one sandbox and fork it for each job (Use a sandbox as your own template);apt installneeds a box. - Streaming output, stdin, terminals, and a code interpreter over the API. Each command is a new process, so keep state between commands in files. For an interactive shell,
prized sandbox ssh IDopens one with yourprized login, and a program opens one with any SSH client through SSH access. - Egress rules and the MCP gateway. Every sandbox has outbound internet; the adapter raises on
allow_internet_access=False,network, ormcprather than ignore them. - Snapshots that outlive their sandbox, volumes, file watching, presigned URLs, metrics over the API, and webhooks. Pause or fork a sandbox in place of a snapshot, and poll
GET /api/v1/sandboxes/{id}in place of a webhook. - Regions. Sandboxes run in US West (Oregon),
us-west-2.
Getting help moving
Email with what you run on E2B, and we will help you map it.