Skip to content

E2B

The @beachside/e2b package runs Beachside sandboxes on E2B through the pinned e2b@2.63.0 client. Install it with npm install beachside @beachside/e2b; it is a supported provider. Use Node 22.19+ or Bun; e2b@2.63.0 requires Node 22.19 or newer.

import { Beachside } from "beachside";
import { e2bAdapter } from "@beachside/e2b";
const client = await Beachside.connect({
adapter: e2bAdapter,
credentials: { apiKey: process.env.E2B_API_KEY! },
config: { lifecycle: { lifetimeSeconds: 600 } },
});
try {
const box = await client.sandboxes.create();
try {
await box.exec(["/bin/sh", "-c", "printf ready"]);
await box.renew();
} finally {
await box.destroy();
}
} finally {
await client.close();
}

Set E2B_API_KEY on the server. E2B_API_ID is not required and is not a team ID. connect verifies the key with an authenticated read (or the team, when teamId is set). Each E2B key belongs to one project and E2B authorizes every call with it, so saved references name only the E2B service and sandbox ID: they keep working after you rotate the key.

The package also exports e2b(), which takes credentials and config in one object and returns an adapter you pass straight to Beachside.connect: Beachside.connect(e2b({ apiKey })). It is the same setup; use whichever reads better.

Setting Default Notes
apiKey required E2B API key.
teamId none Team ID for template lookups and builds, verified at connect. Not needed to reopen saved references.
templateId base E2B’s public base template, or an owned template ID or name. Names must be untagged or use :default; other tags and public aliases are unsupported.
network internet blocked or internet, mapped to E2B’s internet-access setting, or { allow: [...] } for only those hosts and IPv4 ranges (allowlists). Deprecated alias: networkPolicy (set one, not both). See network and previews.
lifecycle.lifetimeSeconds 900 Initial lifetime and default renew() window, up to 86,400 seconds; values under 60 become 60. E2B kills the sandbox when it expires. create({ lifecycle }) can override it per sandbox. Deprecated alias: timeoutSeconds (set one, not both).
lifecycle.suspension none { preserve: Preserve.FILESYSTEM } pauses and resumes from disk only, so resume always cold-boots. Default Preserve.FILESYSTEM_AND_MEMORY keeps memory and processes.
snapshots none { preserve: Preserve.FILESYSTEM } captures disk only and restores with fresh processes. Default Preserve.FILESYSTEM_AND_MEMORY captures memory too.
preview.access public public opens the sandbox to inbound traffic. protected keeps it closed, and preview() returns E2B’s traffic token as a header.
resources none Minimum { vcpus, memoryMiB }. OCI images are built at that size; a prepared template must already meet it, so base is rejected.

create({ env }) sets E2B’s sandbox environment, which applies to every command and process, including after reopening; per-call env overrides a name. Values are not saved in recovery references and are redacted from E2B error text. labels are stored as E2B metadata; Beachside’s reserved keys reject INVALID_ARGUMENT. A per-call environment (image) overrides templateId for that call, and an invalid or unavailable override never falls back to base. region and mounts reject UNSUPPORTED.

Feature Support Live tested
Sandbox lifecycle Create, inspect and destroy. Yes
Reconnect later get(reference) reopens the same sandbox without waking or extending it. Yes
Lifetime renewal renew() resets the deadline, 60 to 86,400 seconds. Yes
Pause and resume Memory pause keeps files, memory and processes; sockets drop. Yes
Commands argv and Bash scripts, cwd, env, binary output up to 1 MiB per stream. Yes
Streaming and terminals processes.start() text and byte streams, incremental input, SIGTERM/SIGKILL, PTYs and resize. Yes
Command input Finite stdin up to 1 MiB, staged as a file under /tmp. No
Files Binary read, overwrite and no-clobber writes; byte streams for large files. Yes
Directories List, stat, mkdir, remove, copy, move, walk and text lines. Yes
HTTP previews Public URLs, or protected URLs with an e2b-traffic-access-token header. Public only
Images Owned templates and OCI builds; get, list and delete templates. No
Network controls blocked, internet or an allowlist; blocking is not reliable. Failed
Snapshots Filesystem, memory and process capture; restore into new compute; inspect and delete. Yes
Fork box.fork() copies a running sandbox’s memory, files and processes into new compute. No
Volumes and mounts Volume create, inspect, list and delete (E2B private beta). Mounts not supported. No
Listing sandboxes and images Sandboxes created by this Beachside scope; all team templates. No

Live results cover the tested image, region and network setting; see Provider support.

network: "blocked" sets E2B’s internet access off. Do not rely on it for isolation: in the live test a blocked sandbox resolved no hostnames but could still open a direct IPv4 TCP connection (to 1.1.1.1:443). Restored snapshots keep the same weakness. See select a network policy.

network: { allow: [...] } sends the entries as E2B’s allowOut with everything else in denyOut, and the adapter checks both lists on the created sandbox and on every restore. Host entries match HTTP on port 80 and TLS on port 443 only; other ports and UDP (QUIC/HTTP3) need an IPv4 range. The allowlist has not been live-tested. See allow only some destinations.

Previews are public by default. A public sandbox accepts inbound traffic from the moment it is created or restored, before you call preview(), and anyone with the URL https://<port>-<sandbox-id>.e2b.app can reach that port. preview() requires running compute with auto-resume off.

With preview.access: "protected", sandboxes are created closed to inbound traffic and preview() returns { access: "protected", url, headers }, where the header is e2b-traffic-access-token. Requests without it get 403. E2B returns that token only from its connect call, so preview() checks that the sandbox is running, private and has auto-resume off, then connects with the sandbox’s observed remaining lifetime as the timeout, so the lifetime stays as it was. If the sandbox paused between the check and the call, E2B resumes it with that remaining lifetime and preview() fails with CONFLICT instead of returning access; inspect it and ask again. The token is a credential. Protected mode has not been live-tested. See preview access.

Shell scripts run under Bash. Exec’s deadlineSeconds defaults to 300 and sets E2B’s RPC timeouts: it limits how long Beachside waits, not how long the command runs, so a command can continue after the deadline. An abort signal also stops only local waiting. Neither kills the process nor changes the sandbox lifetime; see execution and waiting timeouts. Process termination does not guarantee that child processes stop.

Files were live-tested in /home/user on base; an overwrite directly in the sticky /tmp directory failed, so check other paths and custom templates yourself. Buffered reads and writes work at any size; files over 16 MiB stream underneath. Your template needs:

  • GNU ln -T and hard-link support for no-clobber writes.
  • Linux and Python 3 for directory listing, stat and race-safe removal. The adapter installs nothing.
  • Linux libc renameat2 for no-clobber moves.
  • envd 0.5.7 or newer for streamed uploads, and 0.5.2 or newer for incremental process input.

See files and output.

Renewal, pause and resume need running compute that Beachside created with kill-on-timeout and auto-resume off. If that policy is missing or was changed outside Beachside, they reject UNAVAILABLE. renew() sets a new deadline from now; it is not additive and can shorten a longer one. E2B enforces lower plan limits itself (Hobby allows one hour). Reopening never applies the connection’s lifetime unless you call renew().

suspend() uses E2B’s memory pause, or a filesystem-only pause with lifecycle.suspension: { preserve: Preserve.FILESYSTEM }. Paused sandboxes are kept indefinitely, so destroy them explicitly. resume() restarts the clock with the current connection’s configured lifetime. get(), inspect(), exec and files never resume a paused sandbox. Sandboxes with E2B volume mounts cannot be suspended (UNSUPPORTED). Suspending an already paused sandbox or resuming a running one rejects CONFLICT. See suspend and resume.

snapshot() uses E2B’s native capture and needs envd 0.5.0 or newer. By default it captures memory: it briefly pauses the source, which drops active connections, then resumes it. Configure snapshots: { preserve: Preserve.FILESYSTEM } for a filesystem-only capture; restored sandboxes then boot fresh. A call requirement that differs from the configured depth rejects before anything changes. Restore uses the exact captured build, never a newer default build. Each snapshot lives in its own E2B template; deleting it removes that template after checking that nothing else shares it. See snapshots and volumes.

Destroy each sandbox, then close the client; the native timeout is only a fallback. Snapshot templates and templates built from OCI images survive sandbox destruction and need snapshots.delete() or images.delete(). images.delete() only removes a private template with one build, no other alias, no snapshot and no listed sandbox using it; anything else rejects CONFLICT before E2B is called.

box.fork() uses E2B’s native fork. E2B pauses the source to checkpoint its memory, which drops its open connections, then resumes it with the same ID and expiry. The fork continues the source’s processes with its files. lifetimeSeconds sets the fork’s timeout and defaults to the configured lifetime. The fork inherits the source’s labels, which therefore also match it in sandboxes.list() and beachside gc --label; E2B cannot set new labels on a fork, so labels are refused before anything changes.

The fork carries its source’s metadata, including the markers Beachside uses to recognise its own sandboxes. Its reference names the source’s creation and differs by sandbox ID, and sandboxes.list() returns it next to its source. Beachside hands back a fork only when E2B returns a new sandbox ID whose record carries the source’s creation markers (operation and submission) and the same public-traffic setting, taken from the source or, when E2B omits it, from the connection’s preview setup; anything else is reported unknown, so a protected source never yields a public fork unnoticed. The fork’s reported template is not compared, because it has not been checked against a live fork. If reading the fork fails with an authentication error, recover the operation from a connection with valid credentials. If a fork’s response is lost, its outcome stays unknown: list sandboxes and compare IDs. See Fork a running sandbox.

  • network: "blocked" did not stop direct IPv4 connections in the live test.
  • Protected previews have not been live-tested.
  • No region selection and no Beachside volume mounts. Live volume creation was refused (HTTP 403) for the tested account.
  • sandboxes.list() returns only sandboxes this binding created, so a page can hold fewer items than limit. Paused sandboxes list as suspended. Image listings cover all team templates with unknown ownership.
  • Saved references hold no credentials. Any valid key for the same E2B project reopens them, whatever the default template.
  • A refused create maps HTTP 400 to INVALID_ARGUMENT, 401 to UNAUTHENTICATED, 403 to FORBIDDEN, 404 to NOT_FOUND and 429 (including the concurrent sandbox limit) to RATE_LIMIT; nothing was created. Server errors, lost responses and refusals after an OCI build (the template remains) are OUTCOME_UNKNOWN; see recovery.

See E2B sandbox lifecycle, persistence, snapshots, volumes and the compiled suspend/resume example.