# Migrate from E2B

Point the official E2B SDKs at onshore.sh with two environment variables, and learn what behaves differently.

onshore.sh speaks the E2B API. Your code keeps using the official `e2b` SDK, unmodified. You
change two environment variables.

## Switch in two variables

1. **Create an API key**

   In the console at [onshore.sh/app](https://onshore.sh/app/), create an API key. See
   [API keys](https://onshore.sh/docs/account/api-keys).

2. **Set the variables**

   ```bash
   export E2B_DOMAIN=onshore.sh
   export E2B_API_KEY=<your-ons-api-key>
   ```

   `<your-ons-api-key>` is the key you just created. It starts with `msb_`.

3. **Run your code**

   The SDK now calls `https://api.onshore.sh` and reaches each miniVM at
   `https://<port>-<sandbox-id>.onshore.sh`. Code that uses the `e2b` SDK needs no other change.

> **Warning:** Check two differences before you switch:
>
> - **Previews are never public.** A URL from `get_host` (`getHost`) answers only requests that carry
>   the miniVM's traffic token in the `e2b-traffic-access-token` header. You cannot share it as a
>   public link, and `allowPublicTraffic: true` is refused. See
>   [Ports need the traffic token](#ports-need-the-traffic-token).
> - **`e2b-code-interpreter` is not supported.** Only the `e2b` SDK works. Code that imports
>   `e2b_code_interpreter` or `@e2b/code-interpreter` does not run against onshore.sh.

### Python

```python
from e2b import Sandbox

sbx = Sandbox.create(timeout=300)
result = sbx.commands.run("uname -a")
print(result.stdout)
sbx.kill()
```

### JavaScript

```javascript
import { Sandbox } from 'e2b'

const sbx = await Sandbox.create({ timeoutMs: 300_000 })
const result = await sbx.commands.run('uname -a')
console.log(result.stdout)
await sbx.kill()
```

> **Note:** `ons` ignores `E2B_DOMAIN` and `E2B_API_KEY`. It reads `ONS_API_KEY`, or the key `ons login`
> saved. See [Install the CLI](https://onshore.sh/docs/install-cli).

## Supported SDK versions

We test every release with the official SDKs:

| SDK        | Package | Tested version | Runtime                |
| ---------- | ------- | -------------- | ---------------------- |
| Python     | `e2b`   | 2.64.0         | Python 3.11 or later   |
| JavaScript | `e2b`   | 2.64.0         | Node.js 22.19 or later |

```bash
pip install e2b==2.64.0
```

```bash
npm install e2b@2.64.0
```

`e2b-code-interpreter` is not supported yet.

What the test suite proves works: create, commands (stdout, stderr, exit codes, environment
variables, working directory), background commands, files (read, write, list, remove, watch),
PTY, ports through `get_host`, timeouts, metrics, list with metadata filters and paging,
pause and resume, kill, and the SDK's error types.

## What is different

onshore.sh is safer by default. Where it differs from E2B, it does so on purpose.

### Egress is closed by default

A miniVM reaches nothing on the internet until its template allows it. You list the domains a
template may reach in its `minisandbox.yaml`, by name or with presets (`github`, `npm`, `pypi`…).

`Sandbox.create()` with no template uses your organization's `base` template, which reaches the
package registries only (Ubuntu, PyPI, npm, crates.io): `pip install` works. Any other host, such
as GitHub, is refused until you add it at create. `allow_out` sets the miniVM's whole list, so
name the registries you still need too:

```python
sbx = Sandbox.create(network={"allow_out": [
    "pypi.org", "files.pythonhosted.org", "github.com", "api.github.com",
]})
```

See [Network access of the `base` template](https://onshore.sh/docs/guides/templates#network-access-of-the-base-template)
for `ons` and JavaScript, and how to see what was refused.

- `allow_internet_access: true` is refused with `400` when the template allows no egress and the
  create adds none.
- `allow_internet_access: false` closes all egress for that miniVM.
- `network.allowOut` takes domain names (and `*.domain`), at create and with `updateNetwork`
  (`PUT /sandboxes/{id}/network`, `204`). A name the template allows narrows the list. A name
  outside it is added, within your organization's ceiling.
- `network.denyOut` takes only `["0.0.0.0/0"]`: everything `allowOut` does not name is closed
  anyway. Alone, it closes egress.
- An `updateNetwork` without `allowOut` goes back to the template's list, and
  `allow_internet_access: false` closes it.
- IP addresses and CIDR blocks are refused with `400`: onshore.sh filters by name. So are
  `dnsServers`, `egressProxy` and `rules` when set.
- SMTP (ports 25, 465 and 587) and cloud metadata addresses are always blocked, whatever the
  template says.

See [Egress](https://onshore.sh/docs/guides/egress).

### Ports need the traffic token

Every port of a miniVM, other than the SDK's own, needs the `e2b-traffic-access-token` header.
`network.allowPublicTraffic: true` is refused with `400`. Send the `trafficAccessToken` of the
create answer with your requests, or use `ons forward`, which adds it for you. See
[Processes, files and ports](https://onshore.sh/docs/guides/processes-files-ports).

An `envdAccessToken` is always issued, whatever `secure` says.

### Pause and resume keep everything

`sbx.pause()` saves the miniVM's memory and disk. `Sandbox.connect(id)` resumes it with its
files and running processes as they were.

- A paused miniVM costs no compute, only storage.
- Paused miniVMs are kept 30 days, then deleted.
- A timeout change on a paused miniVM answers `409`: resume it first.
- `autoPause: true` pauses the miniVM instead of killing it at its timeout.
- onshore.sh adds `autoPauseIdle`: seconds without activity before the miniVM pauses.

See [Lifecycle](https://onshore.sh/docs/guides/lifecycle).

### Each key sees its own miniVMs

`Sandbox.list()` and `get_info` return only the miniVMs created with the calling API key. Another
key of the same organization sees its own. Use one key per developer or per service.

### Templates come from `minisandbox.yaml`

The E2B template build system (`e2b template build`, `Template.build` in the SDK) does not work
against onshore.sh. You describe a template in a `minisandbox.yaml` file and build it with
`ons template build`. Then pass its name as `template` to `Sandbox.create`, as before.

See [Templates](https://onshore.sh/docs/guides/templates) and the [`minisandbox.yaml` reference](https://onshore.sh/docs/reference/minisandbox-yaml).

### The user commands run as

A miniVM runs commands and file calls as the user its template declares (`user:` in
`minisandbox.yaml`, default `user`; `base` and `agents` use `user`). Like E2B, the SDKs send no
user by default, so the call runs as that user.

On a template with `user: root`, or with an account of its image such as `user: ubuntu`, there is
no `user` account, so passing `user="user"` fails and the error names the accounts the miniVM has:

```text
no such user "user" in this miniVM: drop the user argument to run as the template's user (root), or use one of: root, ubuntu
```

Drop the `user` argument to run as the template's user, or pass one of the accounts the error
lists. Templates built earlier also run as their template's user without a rebuild, but their
error reads `invalid username "user": no such user in the sandbox`: rebuild the template
(`ons template build`) to get the message above. A miniVM created before this change keeps its
earlier behaviour, even after a resume: create a new one to get it.

### Other differences

- **Logs.** `GET /sandboxes/{id}/logs` is always empty: the platform never sees your miniVM's
  output. Read it with the SDK's commands, or `ons proc logs`.
- **Metadata.** Keys starting with `msb.` are reserved and refused with `400`, except the ones
  onshore.sh documents (`msb.ai_account`, `msb.github_repos`, `msb.label.<key>`). Metadata
  `name` and `msb.label.<key>` set the miniVM's name and labels, which every member of your
  organization can see: an existing metadata `name` becomes the miniVM's name. See
  [Name and label miniVMs](https://onshore.sh/docs/guides/names-and-labels).
- **Unsupported fields.** A create field onshore.sh does not implement must be unset or at its
  default. The `400` message names it. `network` accepts `allowOut`, `denyOut` (above) and
  `allowPublicTraffic: false`.
  `autoPauseMemory: false` is refused: a pause always keeps memory.
- **Unsupported routes.** Team, node, template build and access-token management routes of the
  E2B API answer `404`.
- **Limits.** A request over your organization's limits is refused, never silently lowered.
  See [Quotas and limits](https://onshore.sh/docs/account/quotas-and-limits).

## Extensions you may want

Some features have no word in the E2B API. Use `ons` or the [`/v1` routes](https://onshore.sh/docs/reference/api):

- Create up to 50 miniVMs at once: `POST /v1/sandboxes/batch`, or `ons create --count`.
- Give a miniVM a credential it never sees: [egress credentials](https://onshore.sh/docs/guides/egress#egress-credentials).
- Run coding agents in miniVMs: [Agent runs](https://onshore.sh/docs/guides/agent-runs).

Markdown version: https://onshore.sh/docs/guides/migrate-from-e2b.md
