Skip to main content
This page is for code that creates E2B sandboxes and runs commands, code and files in them. Most calls keep their shape: the TypeScript SDK uses the same Sandbox object, and the Python SDK uses a Client. Read the gaps first if your code uses run_code results, file watching, or sandboxes that delete themselves after a timeout.

What maps to what

Move your code

1

Install the SDK and set the key

Create a key on API keys in the dashboard, with machines:write and machines:delete. To bring your E2B template (below), also give it images:read and images:write. Full access covers all of them. See API keys.
2

Create the machine

E2B creates a sandbox that lives for its timeout. An InstaBox machine lives until you delete it, and pauses after idle minutes on its own. create waits until the machine runs.
The default template, agent-browser, has Linux, Python 3, Node.js, a desktop and a browser. To start from your own image, see Use your E2B template.
3

Run commands and code

In Python, exec returns a non-zero exit code in r.exit_code. In TypeScript, commands.run throws on it, as E2B does. A command stops after timeout seconds (60 by default, 600 at most).
4

Move files

Paths are absolute. Use /data/home where your E2B code used /home/user. Files under /data survive a stop.
5

Give a port a URL

E2B’s get_host(port) returns a host name. On InstaBox, publish the port once. The result has the URL, https://<port>-<machine id without m_>.<domain>. A port is public by default, as on E2B.
Ports 1024 to 65535 can be published, up to 16 per machine. For a URL only people with a link can open, publish it private: sbx.ports.publish(8000, { access: 'private' }) in TypeScript, or "access": "private" in the Python request. A private port’s plain url answers 401. Share the response’s tokenUrl instead, the URL with the token as ?_token=. Only the publish that creates or rotates the token returns tokenUrl, so keep it, or publish again with rotateToken: true for a new one. See Public and private ports.
6

Pause, resume and delete

Use your E2B template

An E2B template is built from a Dockerfile. Build the same Dockerfile with Docker, push it to a registry, and import it as a snapshot. The import needs a key with images:write, and creating from the snapshot by name needs images:read, as well as the machine scopes from the first step.
Then create machines from the snapshot. It is a snapshot, not a template: in Python, look it up by name and pass its ID. In TypeScript, Sandbox.create takes the snapshot name and looks it up.
Only linux/amd64 images work. The image’s ENV reaches every command, and its CMD runs as a service. See Custom images.

What has no direct equivalent

Migrate with your coding agent

Paste this prompt into your coding agent in the repository that uses E2B:
Migration prompt

Troubleshooting

INSTABOX_API_KEY is not set in the process that runs the code. E2B’s E2B_API_KEY is not read.
Each workspace may start only a set number of machines a minute; the free plan allows the fewest. A create counts, and so does a resume, including Sandbox.connect and ensure_running on a paused machine. Code that created many short-lived E2B sandboxes in a loop hits this first. Retry only when the error’s code is rate_limited: wait a minute and retry, or reuse one machine across jobs instead of creating one per job. Another 429, such as quota_exceeded, does not clear by waiting, so do not retry it. See Limits.
The key lacks a scope the call needs. snapshot import needs images:write, and creating from a snapshot by name (or client.snapshots.list()) needs images:read. Create a key with those scopes added, or with Full access. See API keys.
An imported image is a snapshot, not a template. In Python pass snapshot_id=snap.id, not template=. See Use your E2B template.
The free plan creates only from some templates. A machine from your own imported snapshot is not limited. See Pricing.
502: nothing listens on the port yet, or the server listens on 127.0.0.1 only. Listen on 0.0.0.0. 503: the machine is paused or stopped. A visit wakes a machine that paused itself.
The home directory is /data/home. Change the path, or use paths relative to HOME in commands.

SDK quick start

Every TypeScript call, with curl.

Python SDK

Every Python call and error.