Sign in

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.py

Then 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:

harness.py
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

E2BPrized APIPrized CLI
Sandbox.create(template, timeout, metadata, envs)POST /api/v1/sandboxes with template, maxRuntimeMin, labels, envVarsprized sandbox create --max-runtime 1h --label job=42 --env K=V
CPU and memory on a template buildresources: {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}/process/executeprized sandbox exec ID --cwd app --env K=V --timeout 10m -- CMD
sbx.files.write(), files.read()POST {toolboxBase}/files/upload, GET {toolboxBase}/files/downloadprized sandbox cp ./app.py ID:app.py, and the reverse
sbx.pause(), Sandbox.connect(id)POST /api/v1/sandboxes/{id}/pause, /resume; any command resumes it tooprized sandbox pause ID --wait, prized sandbox resume ID
sbx.fork(count, timeout)POST /api/v1/sandboxes/{id}/fork with countprized sandbox fork ID --count 3
sbx.set_timeout(seconds)POST /api/v1/sandboxes/{id}/timeout, or /extendprized 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 labelsprized 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 (memoryMb in TypeScript), or disk_gb (diskGb) to Sandbox.create; the API's own default is 4 vCPU and 8 GB (2 vCPU and 4 GB on the free tier).
  • timeout is run time. It (timeoutMs in TypeScript) becomes maxRuntimeMin, 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, and set_timeout can only bring the end earlier, so pass the whole run time to create.
  • Pausing on timeout means pausing when idle. With lifecycle={"on_timeout": "pause"}, timeout becomes autoPauseMin: 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= to Sandbox.create to set autoDeleteMin.
  • 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 with code fork_capacity and body["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 pass timeout; on the free tier copies end when the parent does.
  • Commands answer when they end. on_stdout and on_stderr are called once, with the whole output. A command with a timeout of up to 4 minutes is one request, and each of its streams keeps its first 4 MiB; with a longer timeout, or none (0 or infinity), the adapter runs it in the background and polls until it ends, and the sandbox stops it at that longer timeout even if your program has exited. A command started with background runs until it ends or you kill it: unlike on E2B, timeout does not stop it. kill(), and commands.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 answer False rather 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 with on_stdout or on_stderr, runs with PYTHONUNBUFFERED=1 unless envs or the sandbox's own env sets it ("" keeps Python's buffering), so a Python program's output is kept up to a kill().

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 PORT or the sandbox's previewUrlTemplate, 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, its prized.link address opens in a browser (Preview a port).
  • AsyncSandbox. From async Python, call Sandbox in a thread (asyncio.to_thread); every call in prized-e2b.ts is async already.

Not on Prized yet

  • Templates from a Dockerfile, and root. Sandboxes start from prized-base-v1, prized-agent-v1 or prized-docker-v1 as the user prized, without sudo; E2B's base maps to prized-base-v1, a prized- name passes through, and any other name raises TemplateException. Build and run your image with Docker on prized-docker-v1, once the workspace has paid in, passing memory_mb and disk_gb for 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 install needs 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 ID opens one with your prized 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, or mcp rather 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.