> ## 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.

# Runtimes

> Choose where Python, JavaScript and other programs run and which files they can access.

A runtime runs the programs in a line. Mirage's own commands (`grep`, `cat`, pipes, redirects) run in the workspace itself; `python3`, `node` and any other program go to the machine that captures them, and the runtime on it runs them. Each runtime reaches the workspace's files its own way.

![Monty, WASI, Pyodide and QuickJS access workspace files directly. Host programs use a FUSE folder. Machines connect through SSH or FUSE.](https://mintcdn.com/struktoai/DFcmqNyceJW-5m2z/images/runtime-light.svg?fit=max\&auto=format\&n=DFcmqNyceJW-5m2z\&q=85\&s=c80ddf8b7c3cda1efb8ec7e85c38d8f9)

| Runtime | Runs | Machine | SDK |
| - | - | - | - |
| [Monty](https://docs.mirage.strukto.ai/home/setup/runtime/monty.md) | `python3`, a Python subset | `provider: worker`, worker processes Mirage starts (`in_process` on Cloudflare Workers) | both |
| [WASI](https://docs.mirage.strukto.ai/home/setup/runtime/wasi.md) | `python3`, CPython in WebAssembly | `provider: in_process`, `runtime: wasi` | Python |
| [Pyodide](https://docs.mirage.strukto.ai/home/setup/runtime/pyodide.md) | `python3`, CPython in WebAssembly | `provider: in_process`, `runtime: pyodide` | TypeScript |
| [QuickJS](https://docs.mirage.strukto.ai/home/setup/runtime/quickjs.md) | `node` and `js`, with Node.js's common APIs | `provider: in_process`, `runtime: quickjs` | both |
| [Host](https://docs.mirage.strukto.ai/home/setup/runtime/host.md) | host programs such as `python3`, `node` or `tsx`, confined by a `sandbox` on Linux | `provider: host` | Python, Node |
| [Machine](https://docs.mirage.strukto.ai/home/setup/machine/overview.md) | native programs | a container, VM, cloud sandbox or SSH host: `provider: docker`, `ssh`, `e2b` and the rest | Python, Node; E2B also in the browser |

## Routing

`machines` is ordered: the first machine whose `captures` name a program runs
it, and Mirage runs the rest itself. Without the key, `python3`, `node` and
`js` answer `command not found` (exit 127) until a machine captures them.
[Cloudflare Workers](https://docs.mirage.strukto.ai/typescript/cloudflare-quickstart.md) runs no QuickJS.

```yaml theme={null}
machines:
  py:
    provider: worker
  box:
    provider: docker
    container: my-sandbox
    mount_type: ssh
```

Each entry names its `provider`: `in_process` with the `runtime` it runs,
`worker` for Monty, `host` for the host's own programs, or a
[machine provider](https://docs.mirage.strukto.ai/home/setup/machine/overview.md). An `in_process` runtime is
one Mirage ships, one you registered in code, or a `./file.py:Class`
(Python) or `./file.mjs:Class` (TypeScript) reference to
[your own runtime](https://docs.mirage.strukto.ai/home/setup/runtime/custom.md). The entry's other keys are its
settings, snake\_case in YAML for both SDKs; a key it does not take is
refused.

To choose a machine for each command line, see [Route Machine](https://docs.mirage.strukto.ai/home/policy/route-machine.md).

## Captures

`captures` lists the programs a machine takes:

| Entry | Takes |
| - | - |
| A name, such as `python3` or `ffmpeg` | That program |
| `@python`, `@js` | `python3` and `python`, or `node` and `js` |
| `@external` | Every program Mirage does not have itself, such as `gcc`, `ffmpeg`, `perl` or a vendor CLI |
| `@line` | The whole line, Mirage's own commands included (any machine that runs a shell line) |

| Machine | Default `captures` |
| - | - |
| Monty, WASI, Pyodide, `host` | `@python` |
| QuickJS | `@js` |
| `host` with a `sandbox`, a machine provider | `@external` |

* Mirage's own commands (`cat`, `grep`, `sha1sum`), pipes and redirects stay
  in Mirage. Name `cat`, `grep`, `ps` or `kill` to run it on a machine
  instead; `cd`, `export`, `echo`, `ln`, functions and installed CLIs stay
  in Mirage even when named.
* `@external` does not take `python`, `python3`, `node` or `js`: Mirage has
  those itself and gives them to the Python or JavaScript machine in the list.
  Name them, or `@python` or `@js`, to send them somewhere else. A tool such
  as `pip` is an ordinary program: capture it on the same machine when
  packages must land there, as in `captures: ["@python", "pip", "pip3"]`.
* Monty, WASI, Pyodide and QuickJS take only their own interpreter's
  names; naming another program on one is refused when the workspace is
  built. A `host` machine and a machine provider take any name.
* Mirage matches the program each command really runs, after expanding its
  words, so `python3` is captured in `$P x`, `env python3 x`,
  `timeout 5 python3 x`, `sh -c 'python3 x'` and `xargs python3`. Each command
  on a line matches on its own, so `cat a.txt | python3 x` sends only `python3`.
* `nice`, `nohup`, `stdbuf`, `ionice` and `setsid` run their program where
  it runs alone: `nice gcc x.c` where `gcc` is taken, `nice grep` in Mirage.
  On a machine the wrapper goes with it, and permission rules and a
  `pre_command` route answer for the program.
* An absolute path Mirage has no file for, such as `/usr/bin/ffmpeg`, goes to
  the `@external` machine. A profile's `commands.allow` refuses it, since the
  list can only name what it can read.
* On a `host` machine or a machine provider, a program a captured program
  starts runs there: `make` running `gcc`, or a script calling `subprocess`. Capture the
  launcher on the same machine as the tool. A Pyodide script's `subprocess`
  calls go back through Mirage's routing like any other command.
* An alias is captured as the word it expands to, once `shopt -s
  expand_aliases` is on and the alias was defined on an earlier line.
* If two machines take the same name or group, the first wins and Mirage
  logs a warning.
* A program no machine takes exits 127, `command not found`.
* A `workspace` machine, `provider: in_process` with no `runtime`, with
  `captures` runs only those mount commands itself:
  another mount command, such as `ls`, exits 126, `no runtime accepted this
  line`, and an unknown program exits 127. The shell's own words (`cd`,
  `export`, `echo`) still run.
* A name only `@external` takes has no file, so `which`, `command -v` and
  `type` report it missing; running it still works.
* Globs expand against the workspace first (`python3 job.py *.csv` runs
  `python3 job.py a.csv b.csv`), and permission rules judge that argv.

```yaml theme={null}
machines:
  box:
    provider: docker
    container: my-sandbox
    captures: ["@python", "@external"]
```

Here `python3 job.py | grep error` runs `python3` in the container and
`grep` in Mirage, and `ffmpeg -i a.mp4 b.webm` runs in the container.

## Files

| Where | Reaches the workspace through | Outside the workspace |
| - | - | - |
| Monty, WASI, QuickJS | directly | no host files or network |
| Pyodide | directly | Browser programs retain JavaScript and network access; `init_module` enables host access. See [containment](https://docs.mirage.strukto.ai/typescript/runtime/python.md#containment). |
| `host` | a [FUSE folder](https://docs.mirage.strukto.ai/home/setup/fuse.md) you mount | the host's disk and network; under a `sandbox`, only the paths you grant |
| A machine provider | SFTP and `sshfs` with `mount_type: ssh` (`docker`, `e2b`, `cloudflare_container`, `ssh`, `kubernetes`, `smolvm`, `apple_container`, `microsandbox`), or a Mirage inside the machine | that machine's disk and network |

Mount modes, profiles and policies apply to every file call that reaches the
workspace. A `host` machine or a machine provider's also has its own files and network,
which they do not cover. Pyodide has its own containment limits; use a machine
with a process and kernel boundary for hostile code.

### Verify workspace file access

Run these lines inside Mirage's shell after configuring a writable `/data`
mount visible to the runtime capturing `python3`. They check that Python can
read a workspace file and write one back:

```bash theme={null}
(
  scratch=$(mktemp /data/mirage-check.XXXXXX) || exit
  trap 'rm -f -- "$scratch"' EXIT
  printf 'hello\n' > "$scratch" &&
  MIRAGE_CHECK_FILE="$scratch" python3 -c 'import os; from pathlib import Path; path = Path(os.environ["MIRAGE_CHECK_FILE"]); text = path.read_text(); path.write_text(text.upper()); print(text, end="")' &&
  cat "$scratch"
)
# hello
# HELLO
```

Monty, WASI, Pyodide and QuickJS access workspace files automatically.
For a `host` machine, first mount a [FUSE folder](https://docs.mirage.strukto.ai/home/setup/fuse.md).
For a machine, finish its provider page's **Connecting the workspace** steps
first.

## Resource limits

`command_limits` apply to a runtime's programs as to any command: a line past
its `@line` entry's `timeout_seconds` exits 124 (`line: timed out after Ns`), and
`max_bytes` and `max_lines` cap a program's output.

```yaml theme={null}
command_limits:
  "@line":
    timeout_seconds: 30
```

The deadline also stops the run in Monty, WASI, Pyodide, QuickJS, on a `host`
machine and on a machine provider's; see [machine timeouts](https://docs.mirage.strukto.ai/home/setup/machine/overview.md#timeouts)
for what a machine needs.

If a `host` machine or a machine provider cannot enforce the session's file restrictions,
Mirage refuses to launch the program as a policy refuses a command:
`<provider>: Permission denied`, exit 126, naming a `host` machine by its own name. See
[machine file permissions](https://docs.mirage.strukto.ai/home/setup/machine/overview.md#ssh)
for restrictions that affect runtime selection.


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