Differences from the TypeScript SDK
- Monty:
os.chdir()works and lasts for the run, andos.stat()returns a real named tuple, sost[6]andlen(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
stdandos. The first run compilesqjs-wasi.wasmand cachesqjs-wasi.cwasmbeside 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
homenorMIRAGE_LOCAL_HOME,python3is the interpreter running Mirage. - Machines:
mount_type: sshneedspip install 'mirage-ai[ssh]'on the host. Thesshmachine matcheshostagainst~/.ssh/config. - WASI is in the Python SDK only; Pyodide is in the TypeScript SDK only.
WASI
Install the extra:WasiRuntime(...) raises ImportError.
- A read-only mount, or a session narrowed to read, refuses a write at
open()withOSError: 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’scwd. - A script runs as in CPython:
__file__is absolute, tracebacks quote its lines, andsys.path[0]is its directory (-Pand-Ileave it off). - The first run compiles
python.wasmand cachespython.cwasmbeside 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.