e2b machine provider reaches a running E2B
sandbox, by ID, and the machine runtime runs captured programs in it. You create the sandbox from a template; Mirage only runs programs in
it. Python SDK, Node and browsers.
Installation
- Python
- TypeScript
ssh extra and ssh2 serve the workspace into the sandbox with
mount_type: ssh. Create the sandbox from a template that has what
connecting the workspace needs. Set api_key
in the config, as a value or a credential pointer,
or E2B_API_KEY.
Usage
captures defaults to @external:
every program Mirage does not have itself. Name @python to run
Python in the sandbox too.
- Python
- TypeScript
- YAML
Connecting the workspace
A program in the sandbox opens workspace files at the same paths as in Mirage, so the sandbox must see the mounts there.mount_type picks how:
ssh
- The template needs only
sshfs(below). No Mirage, keys or open port in the sandbox. sshandbothdo not work in browsers.- Each file call is a round trip to the workspace, about 150 ms for a small
file from a laptop; with
both, keep bulk data on the sandbox’s own mounts. - The sandbox shows one session’s view, the first that runs a line there. Give each agent its own sandbox.
- An sshfs still serving a path Mirage serves, another workspace’s or one of your own, is left alone and the line exits 1. Give each workspace its own sandbox.
- If the sandbox restarts, Mirage mounts the paths again. A line caught mid-restart exits 126 without running.
- The root mount and
/devare not served.
A template for ssh
Build a template withsshfs and pass its sandbox ID as sandbox_id:
- Python
- TypeScript
sudo for mountpoints such as
/data. On the default template, run sudo apt-get install -y sshfs
instead.
fuse
Base the template on the machine image, which carries Mirage andfuse3. Write the same mounts at the same paths
into sandbox.yaml, and start Mirage with it in the sandbox:
- This workspace’s rules do not reach those files, so a line is refused while the session’s permissions hide or narrow anything under them.
- If a path the sandbox mounted goes away, as on a restart, lines exit 126 until it is mounted again. Start Mirage from the image’s entrypoint so a restart mounts it again.
- Keep the sandbox’s paths in step with the host’s mounts yourself.
sandbox.yamlcan differ where it should, such as narrower credentials.
Runtime behavior
Notes
- Closing the workspace leaves the sandbox running.
- Output comes back as the program wrote it, binary included: the
sandbox base64-encodes it on the way out, so the image needs
ddandbase64(Debian, Ubuntu and Alpine images have both), and output takes about a third more to transfer. Without them a line runs nothing, prints why and exits 127. - Commands run concurrently, each with its own input and output. Without piped input, stdin starts closed.
- Templates, sizing, networking and lifecycle stay E2B settings.
- A Mirage timeout tries to kill the command; its child processes may survive.