Sandbox SDK
Providers

E2B

Run E2B hosted sandboxes through the normalized SDK API.

E2B provides hosted Linux sandboxes with files, processes, authenticated previews, and template snapshots.

Installation

Terminal
bun add @opencoredev/sandbox-sdk e2b

Authentication

Set E2B_API_KEY, or pass apiKey to e2b().

Run a command

e2b.ts
import { withSandbox } from "@opencoredev/sandbox-sdk";
import { e2b } from "@opencoredev/sandbox-sdk/e2b";

await withSandbox({ provider: e2b() }, async (sandbox) => {
  const result = await sandbox.run("node --version");
  console.log(result.stdout);
});

Run an agent

Export one provider instance and pass it to AI SDK, HarnessAgent, Eve, or Mastra.

agent-provider.ts
import { e2b } from "@opencoredev/sandbox-sdk/e2b";

export const agentSandboxProvider = e2b();

Files and processes

workspace.ts
await sandbox.files.write("index.mjs", `console.log("ready")`);
const process = await sandbox.processes.start("node index.mjs");

for await (const event of process.output()) {
  console.log(event.stream, event.data);
}

E2B supports background processes, stdin, cancellation, and separate stdout and stderr streams.

Ports and snapshots

Restricted previews keep the E2B access token inside preview.request(). Creating and deleting template snapshots is normalized; restoring one creates a new native sandbox and stays on sandbox.raw.

preview.ts
const preview = await sandbox.ports.expose(3000);
const response = await preview.request!("/");

Options

OptionTypeDefaultBehavior
apiKeystringE2B_API_KEYAuthenticates E2B requests.
templatestringE2B defaultCreates the sandbox from a named template.
timeoutnumberCreation timeoutOverrides the creation timeout in milliseconds.

Behavior

  • Requires Node.js 20.18.1 or newer and an E2B account.
  • Files are ephemeral unless captured in an E2B template snapshot.
  • Managed resume keeps the live sandbox reference in the current process.
  • PTY, templates, and native network controls remain available through sandbox.raw.

See Ports, compare exact modes in Compatibility, or connect E2B to HarnessAgent.

On this page