1
Switch
Set these in the process that runs your code:The SDK then calls The
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: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.
3
Adapt what differs
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,pauseandresume,get_info,set_timeoutandlist.commands.runwith streaming output, exit codes (a non-zero exit raisesCommandExitException), 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’suseraccount (home/home/user,sudowithout a password),user="root"as root, and files written foruserbelong to it. A call that names no user runs as root in/home/user. The e2b 1.x SDKs nameuseron 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()returnsFalseandconnect()raisesNotFoundException, so cleanup code can run twice. Plain HTTP callers get410with the reason and time the sandbox ended (see errors). - The SDK’s v2 calls:
GET /v2/sandboxes,POST /v2/sandboxesandPOST /v2/sandboxes/{id}/connectanswer like the routes without/v2. - Logs, metrics, templates and volumes:
get_metrics(GET /sandboxes/{id}/metrics) andGET /sandboxes/metrics?sandbox_ids=,GET /sandboxes/{id}/logsandGET /v2/sandboxes/{id}/logs, the team metrics (GET /teams/{teamID}/metricsand/metrics/max, where the team id is the key’s account id; one sample taken when asked),Template.buildwith its builds, status, logs and tags (GET /templates/{id}/builds,/tags,/tags/count,/tags/exists,/tags/groupsand/tags/{tag}/assignments),GET /v2/templates/{id}, and volumes (GETandPOST /volumes,GETandDELETE /volumes/{id},volumeMountson create). - The E2B Code Interpreter SDK (
e2b-code-interpreter):Sandbox.create()starts its defaultcode-interpreter-v1, andrun_coderuns Python in a context that keeps its variables between calls, withstdout,stderr, the cell’s result (text, HTML, images and matplotlib figures) and errors with their traceback.create_code_context,list_code_contexts,restart_code_contextandremove_code_contextwork;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 withnetwork.allowPublicTraffic: falseto make every port need thetrafficAccessToken. - The error shape: a code, a message and a request id.
e2b package, not against a hand-written client.
What is different
- Templates are the Styne templates.
baseis the general Linux image (Debian 12) with Python 3 aspythonandpython3(pip installworks), Node 22, git, curl, wget,sudo, libatomic and the accountsuseranddaytona(see sandboxes);code-interpreter-v1startsbase, and a template name that does not exist, such asnode, answers404.GET /templates/{id}returns one template. - A path that is not a route of this API answers
404witherror_codeunknown_routeand a message naming the path and this page, so the SDK raises with the reason. - A fork is a Styne operation; see fork. The SDK has no call for it: use HTTP.
- A browser session is a Styne product of its own; see browsers.
- A create field the API does not know is accepted and ignored.
regionandclassare Styne fields, not E2B ones: an unknown region or a class that is not served is refused with422, and the SDKs choose the region with thestyne.regionmetadata key (see Regions). - Extra on Styne, outside the SDKs: fork, snapshots, pause tiers, public ports and signed URLs, 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.
The limits of each plan are on limits; GET /v1/run/usage shows what your account is held to.