SandboxMove from E2B

Move from E2B

This guide maps E2B calls to Tangle Sandbox, shows the same program in both, and covers the E2B-compatible REST routes for HTTP code you keep unchanged.

What maps to what

E2BTangle Sandbox (TypeScript)Python
E2B_API_KEYAn sk-tan- key from id.tangle.tools/app/keys, passed as apiKeyapi_key
Sandbox.create()client.create()client.create(), then wait_for(SandboxStatus.RUNNING)
Sandbox.connect(id)client.get(id)client.get(id)
sandbox.commands.run(cmd)box.exec(cmd)box.exec(cmd)
commands.run(cmd, { background: true })box.process.spawn(cmd)client.fetch("POST", f"/v1/sandboxes/{box.id}/runtime/process/spawn", json={"executable": "python3", "args": [...]})
onStdout and onStderr callbacksproc.stdout() and proc.stderr() on a spawned processNot available
sandbox.files.write(path, data)box.write(path, data) or box.fs.writebox.write(path, data)
sandbox.files.read(path)box.read(path)box.read(path)
sandbox.getHost(port)box.previewLinks.create(port)client.fetch("POST", f"/v1/sandboxes/{box.id}/runtime/preview-links", json={"port": port})
sandbox.setTimeout(ms)maxLifetimeSeconds and idleTimeoutSeconds on createmax_lifetime_seconds, idle_timeout_seconds
Pause and resumebox.stop() and box.resume()box.stop(), box.resume()
sandbox.kill()box.delete()box.delete()
TemplatesEnvironments, templates and snapshots; see Templates and imagesenvironment=, template_id=, from_snapshot= with from_sandbox_id=
PTYbox.terminals; see Shells and terminalsNot available

Two differences change how you write code:

  • Timers stop a sandbox; they do not delete it. A stopped sandbox keeps its files until you delete it or deleteAfterStoppedSeconds passes. Delete in a finally block.
  • Every sandbox has a coding agent. box.prompt() gives it a task, so you do not need to install one. Pass agent: false for plain compute.

The same program on Tangle

Create a sandbox, write a file, run it, share a port and delete the sandbox:

from-e2b.mts
import { Sandbox } from "@tangle-network/sandbox";
 
const client = new Sandbox({
  apiKey: process.env.TANGLE_API_KEY!,
  baseUrl: "https://sandbox.tangle.tools",
});
 
const box = await client.create({ idleTimeoutSeconds: 600 });
try {
  await box.write("/tmp/hello.py", "print('hello from Tangle')\n");
  const run = await box.exec("python3 /tmp/hello.py");
  console.log(run.exitCode, run.stdout);
 
  const server = await box.process.spawn("python3 -m http.server 8000");
  const link = await box.previewLinks.create(8000);
  const { url } = await box.previewLinks.waitUntilReady(link.previewId);
  console.log(url);
  await server.kill();
} finally {
  await box.delete();
}

exec does not throw on a non-zero exit; read exitCode. Errors carry a code you can branch on; see Error codes.

Call the E2B-compatible REST routes

If your code calls E2B’s REST API over HTTP, point it at https://sandbox.tangle.tools/e2b and send your Tangle key in X-API-Key:

curl -s https://sandbox.tangle.tools/e2b/templates \
  -H "X-API-Key: $TANGLE_API_KEY"
 
curl -s -X POST https://sandbox.tangle.tools/e2b/sandboxes \
  -H "X-API-Key: $TANGLE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"templateID": "<templateID from /e2b/templates>", "timeout": 600}'
RouteDoes
GET /e2b/templatesLists one template per coding agent. Pass its templateID to create.
POST /e2b/sandboxesCreates a sandbox and answers once it runs. timeout is the lifetime in seconds.
GET /e2b/sandboxes, GET /e2b/sandboxes/{sandboxID}Lists sandboxes, or reads one.
DELETE /e2b/sandboxes/{sandboxID}Kills the sandbox and answers after it is removed.
GET, POST, DELETE /e2b/sandboxes/{sandboxID}/files, GET .../files/listReads, writes, deletes and lists files.
POST /e2b/sandboxes/{sandboxID}/processesRuns a command to completion and answers with its exit code and output.
GET, DELETE /e2b/sandboxes/{sandboxID}/processes/{pid}Reads or kills a process.
POST /e2b/sandboxes/{sandboxID}/timeoutAnswers 501. Set lifetimes on create instead.
⚠️

These routes serve plain HTTP callers. The E2B SDK’s commands and files calls connect to the sandbox directly, not to these routes, so port SDK code to the Tangle SDK as shown above.

The full request and response shapes are in the E2B-compatible routes reference. Upload limits are in Limits and timeouts.

Next steps