> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superserve.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Migrate from E2B

> Move your sandboxes, templates and agent code from E2B to Superserve. Includes an API mapping, before and after code, a migration script and a prompt for coding agents.

Superserve runs cloud coding agents, long-running agents, CI workers, background jobs, evals, and RL environments in isolated VMs. If you run these on E2B today, most code moves call by call.

## How Superserve compares

Source: [ComputeSDK ratings](https://www.computesdk.com/benchmarks/sandboxes/compare/e2b-vs-superserve),
Nov 16, 2026.

## Ready to switch

Pick how you want to migrate. Do it yourself step by step, or give the prompt to a coding agent and let it change your code.

> [tab] Human
>
> > [!NOTE]
> >
> > **Before you start**
> >
> > * **Get a Superserve API key.** Sign in to the [console](https://console.superserve.ai?utm_source=docs\&utm_medium=link), or sign up for free (no card required). Open **API Keys** and click **Create Key**. See [Get an API key](https://console.superserve.ai/api-keys/).
> > * **Keep E2B installed.** You remove it only after the cutover, in step 6.
>
> **1. Install the SDK and set your API key**
>
> Install the Superserve SDK next to E2B. Set `SUPERSERVE_API_KEY` in your environment and CI secrets.
>
> ```bash TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
> npm install @superserve/sdk
> export SUPERSERVE_API_KEY=ss_live_...
> ```
>
> ```bash Python theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
> pip install superserve
> export SUPERSERVE_API_KEY=ss_live_...
> ```
>
> **2. Map the API**
>
> Most calls keep their names. The main changes: every sandbox needs a `name`, timeouts are in seconds, and a timeout pauses the sandbox instead of killing it.
>
> > [tab] TypeScript
> >
> > | Task | E2B | Superserve |
> > | - | - | - |
> > | Create | `Sandbox.create("tpl", { timeoutMs, envs, metadata })` | `Sandbox.create({ name, fromTemplate, timeoutSeconds, envVars, metadata })`. `name` is required. |
> > | Reconnect | `Sandbox.connect(id)` | `Sandbox.connect(id)`. Resumes a paused sandbox automatically. |
> > | Run a command | `sbx.commands.run(cmd, { envs, cwd, timeoutMs })` | `sbx.commands.run(cmd, { env, cwd, timeoutMs })` |
> > | Background process | `sbx.commands.run(cmd, { background: true })` | `sbx.commands.spawn(cmd)` |
> > | Files | `sbx.files.write(path, data)` / `read(path)` | `sbx.files.write(path, data)` / `read(path)` |
> > | Templates | `Template().fromImage(img)` and `Template.build()` | `Template.create({ name, from: img, steps })` |
> > | Snapshot | `sbx.createSnapshot()`, then `Sandbox.create(snapshotId)` | `sbx.snapshot()`, then `Sandbox.create({ name, fromSnapshot })`. Saves memory and disk; forks keep running processes. |
> > | Pause and resume | `sbx.pause()` / `sbx.connect()` | `sbx.pause()` / `sbx.resume()` |
> > | Timeout | `sbx.setTimeout(ms)`. Kills by default. | `sbx.update({ timeoutSeconds })`. Pauses. Also `idleTimeoutSeconds`. |
> > | Env vars | `envs` | `envVars` on create, `env` per command, `secrets` for API keys |
> > | Public URL | `sbx.getHost(port)` | `await sbx.publishPreviewPort(port)`, then `sbx.getPreviewUrl(port)`. New sandboxes route only published ports. See [Preview URLs](https://docs.superserve.ai/sandbox/preview-urls.md). |
> > | Public URL with auth | `network: { allowPublicTraffic: false }`, then send `sbx.trafficAccessToken` | `await sbx.publishPreviewPort(port, { access: "private" })`, then `sbx.getPreviewUrl(port)`. For the token, use `await sbx.getPreviewToken(port)` (send `token` in the returned `header`) or `await sbx.getSignedPreviewUrl(port)` for a browser. |
> > | List and kill | `Sandbox.list()` / `sbx.kill()` | `Sandbox.list()` / `sbx.kill()` |
>
> > [tab] Python
> >
> > | Task | E2B | Superserve |
> > | - | - | - |
> > | Create | `Sandbox.create("tpl", timeout=, envs=, metadata=)` | `Sandbox.create(name=, from_template=, timeout_seconds=, env_vars=, metadata=)`. `name` is required. |
> > | Reconnect | `Sandbox.connect(id)` | `Sandbox.connect(id)`. Resumes a paused sandbox automatically. |
> > | Run a command | `sbx.commands.run(cmd, envs=, cwd=, timeout=)` | `sbx.commands.run(cmd, env=, cwd=, timeout_seconds=)` |
> > | Background process | `sbx.commands.run(cmd, background=True)` | `await sbx.commands.spawn(cmd)` on `AsyncSandbox` |
> > | Files | `sbx.files.write(path, data)` / `read(path)` | `sbx.files.write(path, data)` / `read(path)` |
> > | Templates | `Template().from_image(img)` and `Template.build()` | `Template.create(name=, from_=img, steps=)` |
> > | Snapshot | `sbx.create_snapshot()`, then `Sandbox.create(snapshot_id)` | `sbx.snapshot()`, then `Sandbox.create(name=, from_snapshot=)`. Saves memory and disk; forks keep running processes. |
> > | Pause and resume | `sbx.pause()` / `sbx.connect()` | `sbx.pause()` / `sbx.resume()` |
> > | Timeout | `sbx.set_timeout(seconds)`. Kills by default. | `sbx.update(timeout_seconds=)`. Pauses. Also `idle_timeout_seconds`. |
> > | Env vars | `envs` | `env_vars` on create, `env` per command, `secrets` for API keys |
> > | Public URL | `sbx.get_host(port)` | `sbx.publish_preview_port(port)`, then `sbx.get_preview_url(port)`. New sandboxes route only published ports. See [Preview URLs](https://docs.superserve.ai/sandbox/preview-urls.md). |
> > | Public URL with auth | `network={"allow_public_traffic": False}`, then send `sbx.traffic_access_token` | `sbx.publish_preview_port(port, access="private")`, then `sbx.get_preview_url(port)`. For the token, use `sbx.get_preview_token(port)` (send `token` in the returned `header`) or `sbx.get_signed_preview_url(port)` for a browser. |
> > | List and kill | `Sandbox.list()` / `sbx.kill()` | `Sandbox.list()` / `sbx.kill()` |
>
> To rebuild an E2B template, see [Create a template](https://docs.superserve.ai/templates/create.md).
>
> **3. Update your code**
>
> Change the import, add a `name`, and convert timeouts to seconds.
>
> ```ts E2B theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
> import { Sandbox } from "e2b"
>
> const sbx = await Sandbox.create("my-tpl", {
>   timeoutMs: 600_000,
>   envs: { MODE: "ci" },
> })
> await sbx.commands.run("npm test")
> const snap = await sbx.createSnapshot()
> const fork = await Sandbox.create(snap.snapshotId)
> ```
>
> ```ts Superserve theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
> import { Sandbox } from "@superserve/sdk"
>
> const sbx = await Sandbox.create({
>   name: "ci-run",
>   fromTemplate: "my-tpl",
>   timeoutSeconds: 600,
>   envVars: { MODE: "ci" },
> })
> // run() stops a command after 30 s by default
> await sbx.commands.run("npm test", { timeoutMs: 10 * 60 * 1000 })
> const snap = await sbx.snapshot()
> const fork = await Sandbox.create({ name: "fork", fromSnapshot: snap })
> ```
>
> ```python E2B theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
> from e2b import Sandbox
>
> sbx = Sandbox.create("my-tpl", timeout=600, envs={"MODE": "ci"})
> sbx.commands.run("pytest")
> snap = sbx.create_snapshot()
> fork = Sandbox.create(snap.snapshot_id)
> ```
>
> ```python Superserve theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
> from superserve import Sandbox
>
> sbx = Sandbox.create(
>     name="ci-run",
>     from_template="my-tpl",
>     timeout_seconds=600,
>     env_vars={"MODE": "ci"},
> )
> # run() stops a command after 30 s by default
> sbx.commands.run("pytest", timeout_seconds=10 * 60)
> snap = sbx.snapshot()
> fork = Sandbox.create(name="fork", from_snapshot=snap)
> ```
>
> **4. Move existing sandboxes with the migration script**
>
> The script copies `/home/user` from each E2B sandbox into a new Superserve sandbox. It does not change or delete your E2B sandboxes; it removes only the temporary archive. If a copy fails, the script deletes the new Superserve sandbox. Run it with both `E2B_API_KEY` and `SUPERSERVE_API_KEY` set.
>
> ```ts migrate-from-e2b.ts theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
> import { Sandbox as E2B } from "e2b"
> import { Sandbox } from "@superserve/sdk"
>
> // Map each E2B template ID to the Superserve template that replaces it.
> // Sandboxes from other templates start from superserve/base.
> const TEMPLATES: Record<string, string> = { "my-e2b-template-id": "my-tpl" }
> const DIR = "/home/user"
> const TIMEOUT_MS = 10 * 60 * 1000 // limit for each archive, upload and extract
>
> const pages = E2B.list()
> while (pages.hasNext) {
>   for (const info of await pages.nextItems()) {
>     const src = await E2B.connect(info.sandboxId)
>     let tgz: Uint8Array
>     try {
>       // commands.run throws when tar exits with a nonzero code.
>       await src.commands.run(`tar czf /tmp/state.tgz -C ${DIR} .`, {
>         timeoutMs: TIMEOUT_MS,
>       })
>       tgz = await src.files.read("/tmp/state.tgz", { format: "bytes" })
>     } catch (err) {
>       console.error(`${info.sandboxId}: archive failed: ${err}`)
>       process.exitCode = 1
>       continue
>     } finally {
>       // Remove the temporary archive from the source, also after a failure.
>       await src.commands
>         .run("rm -f /tmp/state.tgz")
>         .catch(() =>
>           console.error(`${info.sandboxId}: remove /tmp/state.tgz by hand`),
>         )
>     }
>
>     const dst = await Sandbox.create({
>       name: `from-e2b-${info.sandboxId}`,
>       fromTemplate: TEMPLATES[info.templateId] ?? "superserve/base",
>       metadata: { ...info.metadata, migrated_from: info.sandboxId },
>     })
>     try {
>       await dst.files.write("/tmp/state.tgz", tgz, { timeoutMs: TIMEOUT_MS })
>       const out = await dst.commands.run(
>         `tar xzf /tmp/state.tgz -C ${DIR} && rm /tmp/state.tgz`,
>         { timeoutMs: TIMEOUT_MS },
>       )
>       if (out.exitCode !== 0) throw new Error(out.stderr)
>     } catch (err) {
>       console.error(`${info.sandboxId}: copy failed: ${err}`)
>       process.exitCode = 1
>       // Delete the new sandbox so a failed copy does not keep running.
>       await dst
>         .kill()
>         .catch(() =>
>           console.error(`${info.sandboxId}: delete ${dst.id} by hand`),
>         )
>       continue
>     }
>     console.log(`${info.sandboxId} -> ${dst.id}`)
>   }
> }
> ```
>
> ```python migrate_from_e2b.py theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
> import sys
>
> from e2b import Sandbox as E2B
> from superserve import Sandbox
>
> # Map each E2B template ID to the Superserve template that replaces it.
> # Sandboxes from other templates start from superserve/base.
> TEMPLATES = {"my-e2b-template-id": "my-tpl"}
> DIR = "/home/user"
> TIMEOUT_SECONDS = 10 * 60  # limit for each archive, upload and extract
> failed = False
>
> pages = E2B.list()
> while pages.has_next:
>     for info in pages.next_items():
>         src = E2B.connect(info.sandbox_id)
>         try:
>             # commands.run raises when tar exits with a nonzero code.
>             src.commands.run(
>                 f"tar czf /tmp/state.tgz -C {DIR} .", timeout=TIMEOUT_SECONDS
>             )
>             tgz = src.files.read("/tmp/state.tgz", format="bytes")
>         except Exception as err:
>             print(f"{info.sandbox_id}: archive failed: {err}", file=sys.stderr)
>             failed = True
>             continue
>         finally:
>             # Remove the temporary archive from the source, also after a failure.
>             try:
>                 src.commands.run("rm -f /tmp/state.tgz")
>             except Exception:
>                 print(
>                     f"{info.sandbox_id}: remove /tmp/state.tgz by hand", file=sys.stderr
>                 )
>
>         dst = Sandbox.create(
>             name=f"from-e2b-{info.sandbox_id}",
>             from_template=TEMPLATES.get(info.template_id, "superserve/base"),
>             metadata={**info.metadata, "migrated_from": info.sandbox_id},
>         )
>         try:
>             dst.files.write("/tmp/state.tgz", bytes(tgz), timeout=TIMEOUT_SECONDS)
>             out = dst.commands.run(
>                 f"tar xzf /tmp/state.tgz -C {DIR} && rm /tmp/state.tgz",
>                 timeout_seconds=TIMEOUT_SECONDS,
>             )
>             if out.exit_code != 0:
>                 raise RuntimeError(out.stderr)
>         except Exception as err:
>             print(f"{info.sandbox_id}: copy failed: {err}", file=sys.stderr)
>             failed = True
>             # Delete the new sandbox so a failed copy does not keep running.
>             try:
>                 dst.kill()
>             except Exception:
>                 print(f"{info.sandbox_id}: delete {dst.id} by hand", file=sys.stderr)
>             continue
>         print(f"{info.sandbox_id} -> {dst.id}")
>
> sys.exit(1 if failed else 0)
> ```
>
> Each archive, upload and extract can take up to 10 minutes. For large directories or slow connections, raise `TIMEOUT_MS` / `TIMEOUT_SECONDS`.
>
> > [!WARNING]
> >
> > The script copies files only. Running processes and memory do not move. Start your services again in the new sandbox, then take a Superserve [snapshot](https://docs.superserve.ai/sandbox/snapshots.md) to keep that state.
>
> **5. Verify and cut over**
>
> Run your test suite against Superserve. Check the sandbox list in the [console](https://console.superserve.ai?utm_source=docs\&utm_medium=link). When the results match, send production traffic to Superserve.
>
> **6. Uninstall E2B**
>
> After the cutover, remove the `e2b` package and delete `E2B_API_KEY` from your environment and CI secrets.
>
> ```bash TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
> npm uninstall e2b
> ```
>
> ```bash Python theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
> pip uninstall e2b
> ```

> [tab] Agent
>
> Paste this prompt into Claude Code, Codex, Cursor or another coding agent at the root of your repo. The agent changes the code and runs your tests. You review the diff.
>
> ```text Migration prompt theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
> Migrate this repository from the E2B SDK to the Superserve SDK.
>
> Reference: https://docs.superserve.ai/llms-full.txt (read it first).
>
> Before you start: ask me for a Superserve API key if SUPERSERVE_API_KEY is not set.
> I get it from the console (https://console.superserve.ai/api-keys/). Do not create a key yourself.
>
> 1. Install @superserve/sdk (npm) or superserve (pip) next to e2b. Do not remove e2b.
>    Add SUPERSERVE_API_KEY to code, .env.example, and CI config.
> 2. Find every import of "e2b" (TypeScript) or "from e2b" (Python). Apply this mapping:
>    - Sandbox.create(tpl, {timeoutMs, envs}) -> Sandbox.create({name, fromTemplate: tpl,
>      timeoutSeconds: timeoutMs/1000, envVars: envs}). name is required: derive it from context.
>    - commands.run(cmd, {envs}) -> commands.run(cmd, {env})
>      Without timeoutMs, run() stops the command after 30 seconds. Set timeoutMs on installs,
>      builds, tests and any other command that can take longer.
>    - commands.run(cmd, {background: true}) -> commands.spawn(cmd)
>    - createSnapshot() + Sandbox.create(snapshotId) -> snapshot() + Sandbox.create({name, fromSnapshot})
>    - setTimeout(ms) -> update({timeoutSeconds}). Note: Superserve pauses on timeout, E2B kills.
>      If the code relies on the sandbox being killed, call kill() explicitly.
>    - getHost(port) -> publishPreviewPort(port), then getPreviewUrl(port). New sandboxes route only
>      published ports. getPreviewUrl returns a full URL, so remove any "https://" prefix.
>      A new port is public by default. If the E2B sandbox set allowPublicTraffic: false and sent
>      trafficAccessToken, publish with publishPreviewPort(port, {access: "private"}) and send the
>      Superserve preview credential: getPreviewToken(port) returns {header, token} for machine
>      clients; getSignedPreviewUrl(port) returns a URL for browsers.
>    - Python: use snake_case (from_template, timeout_seconds, env_vars, from_snapshot).
> 3. Convert E2B templates to Template.create({name, from, steps}).
> 4. Run the test suite. Fix failures. Do not delete E2B code paths you cannot test; list them.
> 5. Report: files changed, tests run and their result, and anything left for a human.
> 6. Only after I confirm the cutover: uninstall e2b and remove E2B_API_KEY.
> ```
>
> ### Give your agent the full reference
>
> | Resource | Use |
> | - | - |
> | [`docs.superserve.ai/llms-full.txt`](https://docs.superserve.ai/llms-full.txt) | The whole docs in one file for the agent context |
> | [`superserve` skill](https://github.com/superserve-ai/superserve/tree/main/skills/superserve) | Full SDK reference for Claude Code and other skill-aware agents |
> | [Superserve MCP server](https://docs.superserve.ai/integrations/mcp.md) | Lets the agent create and test sandboxes while it migrates |
>
> The API mapping and the migration script are in the **Human** tab.

## Known differences

| Area | What to do |
| - | - |
| Timeout behavior | E2B kills a sandbox at its timeout by default. Superserve pauses it and stops compute billing. Call `kill()` or set `autoDeleteSeconds` if you want it gone. |
| Commands | Without a timeout, `run()` stops a command after 30 seconds. Set `timeoutMs` / `timeout_seconds` on installs, builds and tests. |
| Images | Build an image into a template with `Template.create` first, then create sandboxes from the template. |
| Preview ports | New sandboxes route only published ports, and a new port is public by default. Call `publishPreviewPort` before you use a preview URL. Publish with `access: "private"` and send a preview token to keep a port protected. Ports 1024 to 65535 only: move a server on port 80 or 443 to a higher port. |
| Process state | The migration script moves files, not memory. Take a Superserve snapshot after you restart services. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.