> ## 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 Machine in Python

> Run captured programs in an E2B cloud sandbox.

Runs programs in an E2B cloud sandbox. Settings and notes: [E2B](https://docs.mirage.strukto.ai/home/setup/machine/e2b.md).

## Install

```bash theme={null}
pip install 'mirage-ai[e2b,ssh]'
```

## Usage

`captures` defaults to [`@external`](https://docs.mirage.strukto.ai/home/setup/machine/overview#captures):
every program Mirage does not have itself. Name `@python` to run
Python in the sandbox too.

```python theme={null}
from mirage import RAMVFS, MountMode, Workspace

ws = Workspace(
    {"/data": RAMVFS()},
    mode=MountMode.EXEC,
    machines={
        "box": {
            "provider": "e2b",
            "sandbox_id": "sandbox-id",
            "mount_type": "ssh",
            "captures": ["@python", "@external"],
        }
    },
)
await ws.shell("python3 -c 'print(1 + 1)'")
```

## Connecting the workspace

Pick a [`mount_type`](https://docs.mirage.strukto.ai/home/setup/machine/overview#connecting-the-workspace). `ssh`, `mirage` and `both` do not work in browsers. Under
`ssh` each file call is about 150 ms for a small file from a laptop; under
`mirage`, files on `ram` and `sql` mounts stay cached in the sandbox once
read, unless a policy judges the session's file calls, and E2B's `base`
template is enough: it has `fuse3` and `npm`, and Mirage installs
[`mirage-fuse`](https://docs.mirage.strukto.ai/home/setup/machine/overview#mirage) there the first time. With `own`,
base the template on [the machine image](https://docs.mirage.strukto.ai/home/setup/machine/overview.md#the-machine-image)
and run `mirage workspace create /tmp/sandbox.yaml` in the sandbox.

### A template for ssh

Build a template with `sshfs` and pass its sandbox ID as `sandbox_id`:

```python theme={null}
from e2b import AsyncSandbox, Template

Template.build(Template().from_base_image().apt_install("sshfs"), "mirage-sshfs")
sandbox = await AsyncSandbox.create("mirage-sshfs", timeout=3600)
print(sandbox.sandbox_id)
```


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