Migrate from E2B

Move an E2B sandbox integration to Sandal: call-by-call mapping (TypeScript), a before/after, and what Sandal does not have yet.


E2B and Sandal both give each sandbox its own microVM, so most code moves one call at a time. The biggest differences: a Sandal create needs no template (the project default is used), and a preview URL is either keyed (expose) or a share link (share).

1. Install and sign in#

Follow the quickstart steps 1 and 2: install the CLI and SDK, then sandal login. The SDKs read that profile; in CI set SANDAL_API_KEY (the key alone is enough; organization and project ids are optional overrides).

2. API mapping#

E2BSandal
Sandbox.create() / Sandbox.create("tpl")sandal.createSandbox() / createSandbox({ template })
Sandbox.connect(id)sandal.sandbox(id)
sandbox.commands.run(cmd)sb.exec(cmd) (exitCode, stdout, stderr)
commands.run(cmd, { background: true })sb.startCommand(cmd)
sandbox.files.write(path, data) / files.read(path)sb.writeText(path, text) / sb.readText(path) (writeBytes / readBytes for binary)
sandbox.getHost(port)sb.expose(port) (needs your key) or sb.share(port) (link, no key)
sandbox.betaPause() / resume on connectsb.pause() / sb.resume()
sandbox.setTimeout(ms)sb.extend(...) (CLI: sandal extend <id> --for 12h)
sandbox.kill()sb.delete()
e2b template buildtemplate builds (sandal templates build) or a setup script (sandal create --setup-file)
Code Interpreter runCode() (Jupyter kernel)sb.exec("python3 script.py"), or the code interpreter with persistent contexts on projects that have it enabled

3. Before and after#

Before

import { Sandbox } from "e2b";

const sandbox = await Sandbox.create();
try {
  await sandbox.files.write("/home/user/main.py", "print(6 * 7)");
  const r = await sandbox.commands.run("python3 /home/user/main.py");
  console.log(r.exitCode, r.stdout);
  await sandbox.commands.run("python3 -m http.server 8000", { background: true });
  console.log("https://" + sandbox.getHost(8000));
} finally {
  await sandbox.kill();
}

After

import { Sandal } from "@sandal-dev/sdk";

const sandal = new Sandal();
const sb = await sandal.createSandbox();
try {
  await sb.writeText("/workspace/main.py", "print(6 * 7)");
  const r = await sb.exec("python3 /workspace/main.py");
  console.log(r.exitCode, r.stdout);
  await sb.startCommand("python3 -m http.server 8000");
  console.log((await sb.share(8000)).url);
} finally {
  await sb.delete();
}

The working directory is /workspace (E2B: /home/user). Python: the same names in snake_case (create_sandbox, write_text, start_command), see the Python SDK.

What Sandal does not have yet#

Said plainly, so you can plan around it (no dates promised):

  • Root in the guest. On the default template commands run as uid 2000 without sudo; exec as root (sandal exec --root, user: "root") is refused with 422 capability_unavailable. A root + FUSE template is in preview; no root-capable template is generally offered yet.
  • FUSE and S3 mounts. The default template has no /dev/fuse, so s3fs / mountpoint-s3 cannot run there, and there is no native bucket mount. Use persistent volumes or copy objects in and out, or ask for the root + FUSE preview template.
  • Memory snapshots. Not offered: pause/resume keeps memory on the same sandbox only; snapshots and forks are disk-only.
  • Region choice. Sandal runs in the EU only (Germany, Finland, Luxembourg).
  • Outbound IPv6. IPv4 only today.
  • Volume snapshots and OpenTelemetry export are not offered yet.