> ## 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 E2B

> Run the unmodified e2b package, Python and JavaScript 2.63.0, against Styne by setting three environment variables.

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

**1. Switch**

Set these in the process that runs your code:

```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
```

The SDK then calls `https://api.styne.ai` and serves ports on `https://<port>-<sandbox id>.styne.ai`, the domain the create answer names. Your code stays as it is.

`E2B_SANDBOX_URL` sends the commands and file calls of every sandbox over one kept-open connection, so the first command of a new sandbox answers as fast as the second.

On e2b versions before 2.48 (some agent frameworks pin e2b 2.31), also set `E2B_VALIDATE_API_KEY=false`: those versions
check that a key starts with `e2b_`.

To set them from Python instead:

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

os.environ["E2B_API_KEY"] = os.environ["STYNE_API_KEY"]
os.environ["E2B_API_URL"] = "https://api.styne.ai"
os.environ["E2B_SANDBOX_URL"] = "https://sandbox.styne.ai"

with Sandbox.create(template="base") as sbx:
    print(sbx.commands.run("uname -sm").stdout)
```

The `with` block kills the sandbox when it ends. The SDK sends its own `timeout` of 300 seconds on create; pass `timeout=` to change it.

**2. Check**

Run this once. It uses the calls most programs use; every line has to print.

```python theme={"theme":"css-variables"}
from e2b import Sandbox

sbx = Sandbox.create(template="base", timeout=300)
try:
    print("create", bool(sbx.sandbox_id))
    print("run", sbx.commands.run("echo ok").stdout.strip())
    sbx.files.write("/root/check.txt", "file\n")
    print("file", sbx.files.read("/root/check.txt").strip())
    print("host", sbx.get_host(3000).startswith("3000-"))
    sbx.pause()
    sbx = Sandbox.connect(sbx.sandbox_id)
    print("resume", sbx.files.read("/root/check.txt").strip())
finally:
    sbx.kill()
```

```text theme={"theme":"css-variables"}
create True
run ok
file file
host True
resume file
```

**3. Adapt what differs**

| In E2B | On Styne |
| - | - |
| Templates you build with the SDK's `Template.build` (v2 build system) | Built here: `Template().from_base_image()` (or any Styne template or your snapshot) with its steps runs in a builder sandbox and is saved under the template's name; `Sandbox.create("<name>")` starts from it. A template built on E2B's own servers is not copied over: build it again here, or save a [snapshot](https://docs.styne.ai/guide-templates.md#make-your-own-start-state) and start from it with `snapshot` |
| A template such as `code-interpreter-v1` or `node` | `code-interpreter-v1` starts `base` (Python 3 with `pip install`, Node 22, git, curl and wget). Another unknown name answers `404 not_found` |
| `e2b-code-interpreter`, `Sandbox.run_code` | Works as is: Python contexts keep their variables between calls. `pip install` the packages your code imports |
| e2b 1.x SDKs (`e2b` and `e2b-code-interpreter` 1.x, Python and JavaScript) | Work as is: a create from a 1.x SDK, or one that sends `secure: false`, makes an unsecured sandbox, so `run_code` runs without an envd token as on E2B; the sandbox shows `styne.open_envd` in its metadata. The 2.x SDKs always send the token |
| Public port URLs | The same: ports open without a token unless the create sends `network.allowPublicTraffic: false` |
| `update_network` on a running sandbox | Works as is: `PUT /sandboxes/{id}/network` replaces `allowOut`, `denyOut` and `allowInternetAccess` of a running or hot-paused sandbox, and a field you leave out returns to its default. `egressProxy`, `rules` and `dnsServers` answer `400`; resume a deeply paused sandbox first |
| `files.watch_dir` | Supported |
| Signed file URLs computed by the SDK | Not honoured. Make a link with `POST /sandboxes/{id}/files/signed-url` ([files](https://docs.styne.ai/files.md)) |
| Volumes | Supported: `POST /volumes`, `volumeMounts` on a create, see [Volumes](https://docs.styne.ai/volumes.md). A sandbox with a volume is killed, not paused, at its timeout |
| Sandbox lifetime up to your plan's maximum | 1 to 86,400 seconds |
| `Sandbox.kill()` returns `False` for an unknown id | Same for `404`; the `410` of an ended sandbox raises |
| Your own regions | `region` `ash` (default); `ams` is accepted and served in Ashburn for now. E2B calls without it start in `ash`. An unknown region or `class` answers `422` |

**4. Cut over**

Run both providers side by side behind a switch in your own config (the variables from step 1), send a small share of traffic to Styne, compare exit codes and timings, and move the rest. Nothing in your sandbox code needs a second code path.

## What is the same

* `Sandbox.create`, `Sandbox.connect`, `kill`, `pause` and `resume`, `get_info`, `set_timeout` and `list`.
* `commands.run` with streaming output, exit codes (a non-zero exit raises `CommandExitException`), background processes and stdin.
* The filesystem calls: read, write, list, stat, make directory, move and remove.
* `get_host(port)` for a port URL.
* The user a call names: `commands.run(..., user="user")` runs as E2B's `user` account (home `/home/user`, `sudo` without a password), `user="root"` as root, and files written for `user` belong to it. A call that names no user runs as root in `/home/user`. The e2b 1.x SDKs name `user` on every call, as on E2B.
* A sandbox made with `secure: false` (the e2b 1.x SDKs' default) takes envd and code-interpreter calls without the access token, as on E2B; a create from a 2.x SDK always needs it.
* A sandbox that is gone answers `404`: `kill()` returns `False` and `connect()` raises `NotFoundException`, so cleanup code can run twice. Plain HTTP callers get `410` with the reason and time the sandbox ended (see [errors](https://docs.styne.ai/errors.md)).
* The SDK's v2 calls: `GET /v2/sandboxes`, `POST /v2/sandboxes` and `POST /v2/sandboxes/{id}/connect` answer like the routes without `/v2`.
* Logs, metrics, templates and volumes: `get_metrics` (`GET /sandboxes/{id}/metrics`) and `GET /sandboxes/metrics?sandbox_ids=`, `GET /sandboxes/{id}/logs` and `GET /v2/sandboxes/{id}/logs`, the team metrics (`GET /teams/{teamID}/metrics` and `/metrics/max`, where the team id is the key's account id; one sample taken when asked), `Template.build` with its builds, status, logs and tags (`GET /templates/{id}/builds`, `/tags`, `/tags/count`, `/tags/exists`, `/tags/groups` and `/tags/{tag}/assignments`), `GET /v2/templates/{id}`, and volumes (`GET` and `POST /volumes`, `GET` and `DELETE /volumes/{id}`, `volumeMounts` on create).
* The E2B Code Interpreter SDK (`e2b-code-interpreter`): `Sandbox.create()` starts its default `code-interpreter-v1`, and `run_code` runs Python in a context that keeps its variables between calls, with `stdout`, `stderr`, the cell's result (text, HTML, images and matplotlib figures) and errors with their traceback. `create_code_context`, `list_code_contexts`, `restart_code_context` and `remove_code_context` work; `language="bash"` and `"js"` run each cell as a process of its own.
* Public port URLs: `https://<port>-<id>.<domain>` opens without a token, as on E2B. Create with `network.allowPublicTraffic: false` to make every port need the `trafficAccessToken`.
* The error shape: a code, a message and a request id.

Conformance is measured against the official `e2b` package, not against a hand-written client.

## What is different

* Templates are the Styne templates. `base` is the general Linux image (Debian 12) with Python 3 as `python` and `python3` (`pip install` works), Node 22, git, curl, wget, `sudo`, libatomic and the accounts `user` and `daytona` (see [sandboxes](https://docs.styne.ai/sandboxes.md#templates)); `code-interpreter-v1` starts `base`, and a template name that does not exist, such as `node`, answers `404`. `GET /templates/{id}` returns one template.
* A path that is not a route of this API answers `404` with `error_code` `unknown_route` and a message naming the path and this page, so the SDK raises with the reason.
* A fork is a Styne operation; see [fork](https://docs.styne.ai/fork.md). The SDK has no call for it: use HTTP.
* A browser session is a Styne product of its own; see [browsers](https://docs.styne.ai/browsers.md).
* A create field the API does not know is accepted and ignored. `region` and `class` are Styne fields, not E2B ones: an unknown region or a class that is not served is refused with `422`, and the SDKs choose the region with the `styne.region` metadata key (see [Regions](https://docs.styne.ai/regions.md)).
* Extra on Styne, outside the SDKs: [fork](https://docs.styne.ai/fork.md), [snapshots](https://docs.styne.ai/snapshots.md), [pause tiers](https://docs.styne.ai/pause-tiers.md), public [ports](https://docs.styne.ai/ports.md) and [signed URLs](https://docs.styne.ai/files.md), reached with plain HTTP, the CLI, or `curl`.

## Errors and limits

The SDK raises its own exceptions for the API's answers: `401` `AuthenticationException`, `404` `NotFoundException`, `503` `ServiceBusyException` (not a subclass of `SandboxException` in Python, catch it by name). Branch on `error_code` in the JSON body, not on the message: see [errors](https://docs.styne.ai/errors.md#the-e2b-sdks).

The limits of each plan are on [limits](https://docs.styne.ai/limits.md); `GET /v1/run/usage` shows what your account is held to.


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