Skip to main content
Setup and behavior of every runtime are on the Runtimes pages. This page covers what is specific to the Python SDK.

Differences from the TypeScript SDK

  • Monty: os.chdir() works and lasts for the run, and os.stat() returns a real named tuple, so st[6] and len(st) work. Runs execute on Monty’s worker pool, so the event loop stays free and cancelling a run halts the interpreter. Every workspace in the process shares one pool of four workers; a run waiting on workspace I/O holds one, and a run past the four waits for one to free up.
  • QuickJS: the real quickjs-ng std and os. The first run compiles qjs-wasi.wasm and caches qjs-wasi.cwasm beside it. A write shows to other commands once the file is closed or the run ends, and a timeout stops the run.
  • Local: with neither home nor MIRAGE_LOCAL_HOME, python3 is the interpreter running Mirage.
  • Machines: mount_type: ssh needs pip install 'mirage-ai[ssh]' on the host. The ssh machine matches host against ~/.ssh/config.
  • WASI is in the Python SDK only; Pyodide is in the TypeScript SDK only.

WASI

Install the extra:
Without it, WasiRuntime(...) raises ImportError.
  • A read-only mount, or a session narrowed to read, refuses a write at open() with OSError: errno 30 on the host and Monty, or preview1 errno 69 under WASI.
  • The CPython build is read-only in the run. A mount at / coexists with it: each mount wins under its prefix.
  • A run starts in the shell’s working directory; a missing one fails before any code runs. A direct execute() runs in its context’s cwd.
  • A script runs as in CPython: __file__ is absolute, tracebacks quote its lines, and sys.path[0] is its directory (-P and -I leave it off).
  • The first run compiles python.wasm and caches python.cwasm beside it; later runs start in milliseconds. A timeout stops the run.

Managing runtimes in code

Workspace(runtimes=[...]) takes names and runtime objects, and adds workspace when the list leaves it out. On a live workspace, add_runtime appends an entry (one that runs on a machine goes after the last such entry, else ahead of Monty and QuickJS), remove_runtime takes one out, and runtimes() lists them:
python3 moves to the new runtime at once. A running line finishes before its removed runtime closes, a removed instance cannot be added again, and workspace cannot be removed. register_runtime(name, cls) makes your own runtime class available by name in YAML.

Child processes

A host application starts a program through the same admitted entry point as the shell.