Skip to content

Migrate from E2B

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

  1. Create an API key

    In the console at onshore.sh/app, create an API key. See API keys.

  2. Set the variables

    Terminal window
    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.

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

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
Terminal window
pip install e2b==2.64.0
Terminal window
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.

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

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:

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

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

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.

An envdAccessToken is always issued, whatever secure says.

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.

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.

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 and the minisandbox.yaml reference.

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:

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.

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

Some features have no word in the E2B API. Use ons or the /v1 routes:

  • 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.
  • Run coding agents in miniVMs: Agent runs.