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

# Switch from Vercel Sandbox or Modal

> Move a Vercel Sandbox or Modal Sandbox workload to Styne with the E2B SDK (Python e2b or JavaScript e2b, version 2.63 and later) and Styne's snapshot calls. Each call...

Move a Vercel Sandbox or Modal Sandbox workload to Styne with the E2B SDK (Python `e2b` or JavaScript `e2b`, version 2.63 and later) and Styne's snapshot calls. Each call of your harness has a one-line counterpart below; the ports of three real harnesses (a Vercel snapshot benchmark, a per-visitor preview service and a Modal sandbox pool) ran start to finish this way.

**You need** a Styne API key; create one on the dashboard ([API keys](https://docs.styne.ai/authentication.md)).

**1. Point the E2B SDK at Styne**

```text theme={"theme":"css-variables"}
E2B_API_KEY=<your Styne API key>
E2B_API_URL=https://api.styne.ai
E2B_SANDBOX_URL=https://sandbox.styne.ai
```

Set the three variables in the process that runs your code. [Switch from E2B](https://docs.styne.ai/e2b-drop-in.md) lists what they change.

**2. Map your calls**

From Vercel Sandbox (`@vercel/sandbox`):

| In Vercel Sandbox | On Styne |
| - | - |
| `Sandbox.create({ runtime, timeout, resources })` | `Sandbox.create(template="base", timeout=<seconds>)`. `base` carries Python 3, Node 22, git, curl and wget, with 4 vCPU and 8 GiB memory; `timeout` is in seconds (Vercel's is in milliseconds) |
| `source: { type: "git", url }` | `sbx.commands.run("git clone <url> /home/user/app")` |
| `sandbox.runCommand("npm", ["install"], { cwd, env, sudo })` | `sbx.commands.run("npm install", cwd=..., envs={...}, user="root")`; the result has `stdout`, `stderr` and `exit_code` |
| `runCommand({ detached: true })` | `sbx.commands.run(cmd, background=True)` |
| `sandbox.writeFiles([{ path, content }])`, `readFile`, `mkDir` | `sbx.files.write(path, content)`, `sbx.files.read(path)`, `sbx.files.make_dir(path)` |
| `ports: [3000]` and `sandbox.domain(3000)` | No port list to declare. `sbx.get_host(3000)` answers `3000-<id>.styne.ai`; the URL `https://3000-<id>.styne.ai` opens without a token |
| `sandbox.snapshot()` | `POST /sandboxes/{id}/snapshots` with `{"name": "<name>"}` ([snapshots](https://docs.styne.ai/snapshots.md)) |
| `source: { type: "snapshot", snapshotId }` | `POST /sandboxes` with `{"snapshot": "<name>"}` instead of `templateID`; a sandbox from a snapshot starts in 0.07 to 0.26 seconds |
| `snapshot.delete()` | `DELETE /snapshots/{name}` answers `204` |
| `sandbox.stop()` | `sbx.kill()` ends the sandbox; `sbx.pause()` keeps its state and `Sandbox.connect(id)` resumes it |
| `sandbox.extendTimeout(ms)` | `sbx.set_timeout(<seconds>)` |
| `Sandbox.get({ name })`, `Sandbox.list({ tags })` | `Sandbox.connect(id)`; send `metadata` (a map of strings) on create and list by it |
| `networkPolicy` | `network.allowOut` and `network.denyOut` on create, and `allowInternetAccess: false` to close the internet ([Switch from E2B](https://docs.styne.ai/e2b-drop-in.md)) |

From Modal (`modal.Sandbox`):

| In Modal | On Styne |
| - | - |
| `modal.Sandbox.create("sleep", "infinity", app=app, image=image, timeout=600)` | `Sandbox.create(template="base", timeout=600)`; there is no app or image object, so install what the image installed with `sbx.commands.run("pip install ...")` once and save it as a snapshot |
| `sb.exec("bash", "-c", cmd)`, `p.stdout.read()`, `p.wait()`, `p.returncode` | `r = sbx.commands.run(cmd)`; read `r.stdout`, `r.stderr` and `r.exit_code`. A non-zero exit raises `CommandExitException` with the same fields |
| `sb.open(path, "w")`, `f.write(...)` | `sbx.files.write(path, data)`; `sbx.files.read(path)` for `open(path, "r")` |
| `encrypted_ports=[8000]` and `sb.tunnels()[8000].url` | `https://` + `sbx.get_host(8000)`; every port is reachable without declaring it |
| `sb.snapshot_filesystem()` and `Sandbox.create(image=snapshot_image)` | `POST /sandboxes/{id}/snapshots`, then `POST /sandboxes` with `{"snapshot": "<name>"}` |
| `sb.terminate()` | `sbx.kill()` |
| `Sandbox.from_name`, `Sandbox.list(tags=...)`, `set_tags` | `Sandbox.connect(id)`; `metadata` on create, listed with the sandbox |
| A pool of warm sandboxes with an idle limit and a reaper | The same pool over `Sandbox.create`, `Sandbox.connect` and `kill`; a create answers in about 0.27 seconds, so a pool of 8 served 24 sessions in 0.5 seconds |

**3. Check**

Run this once. It takes a Vercel-style flow, bootstrap, snapshot, start from the snapshot, delete, end to end.

```text theme={"theme":"css-variables"}
import os
import requests
from e2b import Sandbox

api = os.environ["E2B_API_URL"]
auth = {"Authorization": "Bearer " + os.environ["E2B_API_KEY"]}

base = Sandbox.create(template="base", timeout=300)
try:
    base.commands.run("pip install requests && echo ready > /home/user/ready.txt")
    name = "migrate-check-" + base.sandbox_id[:8]
    snap = requests.post(f"{api}/sandboxes/{base.sandbox_id}/snapshots", json={"name": name}, headers=auth)
    print("snapshot", snap.status_code)
    made = requests.post(f"{api}/sandboxes", json={"snapshot": name, "timeout": 300}, headers=auth).json()
    child = Sandbox.connect(made["sandboxID"])
    try:
        print("from snapshot", child.files.read("/home/user/ready.txt").strip())
        print("host", child.get_host(3000).startswith("3000-"))
    finally:
        child.kill()
    print("delete", requests.delete(f"{api}/snapshots/{name}", headers=auth).status_code)
finally:
    base.kill()
```

```text theme={"theme":"css-variables"}
snapshot 201
from snapshot ready
host True
delete 204
```

**4. Adapt what differs**

| In Vercel Sandbox or Modal | On Styne |
| - | - |
| Vercel images and Modal `Image` builders | One `base` template. Add your toolchain with a command and keep it as a [snapshot](https://docs.styne.ai/guide-templates.md#make-your-own-start-state) |
| Snapshot ids and Modal image ids | A snapshot is named by you; a name is 1 to 128 characters of letters, digits, `.`, `_` and `-` |
| Vercel's snapshot expiry and Modal's image lifetime | You remove a snapshot yourself with `DELETE /snapshots/{name}` |
| Vercel `resources.vcpus`, Modal `cpu` and `memory` | A sandbox takes the size of its template (4 vCPU, 8 GiB memory); asking for more answers `400` |
| Modal volumes, Vercel drives | Keep state with [pause and snapshots](https://docs.styne.ai/pause-tiers.md) |
| Regions | `region` is `ash` (default); `ams` is accepted and served in Ashburn for now; an unknown one answers `422` |

**5. Cut over**

Keep the three variables behind a switch in your config, send a small share of work to Styne, compare exit codes and timings, and move the rest. [Errors](https://docs.styne.ai/errors.md) lists every code the API can answer; [limits](https://docs.styne.ai/limits.md) every limit.


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