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

# E2B

> Run captured command lines in an existing E2B sandbox.

`E2BRuntime` connects to a live [E2B](https://e2b.dev) sandbox by id. Create
it with E2B's CLI or SDK. Programs accessing Mirage mounts as ordinary files
require Mirage and FUSE inside the sandbox, with mounts at the same paths
as the host workspace. Sandbox creation and cleanup remain with your application.

See the [Sandbox overview](/typescript/runtime/sandbox) for the shared image and
matching mount-prefix setup. The in-sandbox mount is served by the Python
Mirage build for both SDKs.

## Install

```bash theme={null}
pnpm add e2b
```

## Configure

```yaml theme={null}
runtimes:
  - name: e2b
    captures: ["python3", "pip"]
    config:
      sandboxId: ${E2B_SANDBOX_ID}
      apiKey: ${E2B_API_KEY}
  - workspace
```

`apiKey` is optional in Node when `E2B_API_KEY` is set. The runtime connects on the
first captured line and reuses the sandbox client until the workspace closes.
Closing the workspace leaves the sandbox running.

The same configuration in application code is:

```ts theme={null}
import { E2BRuntime } from '@struktoai/mirage-node'

const runtime = new E2BRuntime({
  captures: ['python3', 'pip'],
  config: { sandboxId: 'sandbox-id' },
})
```

Node and browser share the async implementation in `mirage-core`, with
independent stdin and output for concurrent commands.

For browsers, import the runtime explicitly and pass `apiKey`:

```ts theme={null}
import { E2BRuntime } from '@struktoai/mirage-core/runtime/sandbox/e2b/runtime'
```

This import also registers `e2b` for workspace configuration. Keep account keys
out of shared frontend bundles; use your backend to authenticate and authorize
access in a shared web app.

Use the native E2B SDK runtime for E2B commands. SSH remains useful for
general remote hosts and persistent MCP stdio connections.

Templates, CPU and memory sizing, networking, and lifecycle controls remain
E2B settings.

## Standard input

Piped input goes directly to stdin, followed by EOF. Commands without input
start with stdin closed.

<Warning>
  Cancellation and command timeouts attempt to kill the E2B command and
  disconnect its output stream. Descendant processes may survive. E2B
  also applies its SDK command timeout, currently 60 seconds by default, to
  both runaway and legitimate long-running commands. See
  [Resource limits](/typescript/runtime/sandbox#resource-limits).
</Warning>


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