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

# WASI

> Run Python in WebAssembly with access to workspace files, in the Python SDK.

What to install and a runnable Python example. The settings, how the workspace connects and the notes are on [WASI](https://docs.mirage.strukto.ai/home/setup/runtime/wasi.md), shared by both SDKs.

## Usage

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

ws = Workspace(
    {"/data": RAMVFS()},
    mode=MountMode.EXEC,
    machines={"py": WasiRuntime(config={"home": "/path/to/build"})},
)
await ws.shell("python3 -c 'print(1 + 1)'")
```

## In the Python SDK

Install the extra:

```bash theme={null}
pip install "mirage-ai[wasi]"
```

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.


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