> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agentium.in/llms.txt
> Use this file to discover all available pages before exploring further.

# E2B sandbox adapter

> Run remote code with the versioned code-interpreter SDK and explicit cleanup.

`E2BSandbox` implements `CloudSandbox`. `E2BSandboxToolkit` exposes the same session through Agent tools. Import both from `@agentium/core/toolkits`.

```bash theme={null}
npm install @agentium/core@4.0.0 @e2b/code-interpreter@2.8.0
npm install --save-dev tsx
export E2B_API_KEY="your-key"
```

## Run code

This example creates a real remote sandbox when run. Save as `e2b.ts`, then use `npx tsx e2b.ts`.

```typescript e2b.ts theme={null}
import { E2BSandbox } from "@agentium/core/toolkits";

const sandbox = new E2BSandbox({
  lifetimeSeconds: 300,
  defaultTimeoutSeconds: 30,
  maxOutputBytes: 64 * 1024,
});
try {
  const result = await sandbox.run('print(6 * 7)', { language: "python" });
  if (result.exitCode !== 0) throw new Error(`Sandbox failed: ${result.output}`);
  console.log(result.output);
} finally {
  await sandbox.close();
}
```

Expect output containing `42`. The SDK import and sandbox creation are lazy; the first operation starts the session. Leave `template` unset to use the interpreter SDK's default language-capable template.

## Configure ownership

`lifetimeSeconds` bounds the remote session lifetime independently of each operation's timeout. Every sandbox created by this adapter is owned and killed during `close()`. Concurrent starts share one creation; close is terminal.

For Agent tools, create `E2BSandboxToolkit`, pass `getTools()` to your Agent, and close both the Agent and toolkit after active runs settle. Grant only the intended tool names in a harness.

## Handle uncertain work

Remote cancellation and client deadlines do not prove code stopped. Check for external effects before replaying. Missing files return null only for provider-specific not-found responses. Errors from code, authorization, or connectivity remain failures.

Output is bounded after the provider call; the provider SDK may buffer more internally. Account-level isolation and network policy are yours to configure. See [sandbox lifecycle](/features/sandbox-toolkits).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.