wasi runs CPython in WebAssembly, with the standard library available
subject to the restrictions below. Programs can access workspace files
under the same permissions as shell commands, but cannot access host files
or the network. Python SDK only.
Installation
home, or MIRAGE_WASI_HOME, at the unzipped directory.
Usage
- Python
- YAML
Memory
max_memory caps the memory one run may grow to:
MemoryError. CPython starts at about 40M, so
a cap below that fails every run. There is no cap by default.
Python compatibility
Examples assume a writable/data mount. Mount modes and permissions still apply.
open()
Modes and modifiers are listed separately; for example, rb combines r and b.
Example: append to a workspace file
Example: append to a workspace file
Limitations
Limitations
File objects
Reads fetch ranges from the mount as the program asks for them.Example: write, read and truncate a file
Example: write, read and truncate a file
Limitations
Limitations
os
File operations
os.read() and os.pread() fetch ranges from the mount as the program asks.
Directory operations
Metadata and links
Environment and working directory
Example: list a workspace directory
Example: list a workspace directory
Limitations
Limitations
os.path
Example: check a workspace path
Example: check a workspace path
pathlib
Example: create and inspect a workspace file
Example: create and inspect a workspace file
Limitations
Limitations
sys
Example: read arguments and piped input
Example: read arguments and piped input
time and datetime
The clocks start at the workspace’s system time
when it sets one, and files the program writes are stamped from the same
clock. time.monotonic() and time.perf_counter() measure elapsed time.
Example: print today's date
Example: print today's date
Limitations
Limitations
json
Example: write and read workspace JSON
Example: write and read workspace JSON
glob
Example: find workspace text files
Example: find workspace text files
shutil
Example: move a workspace file
Example: move a workspace file
Limitations
Limitations
subprocess
Process creation is unavailable in this runtime.
Limitations
Limitations
socket
Network connections are unavailable in this runtime.
Limitations
Limitations
Notes
- Each command starts with fresh Python state. Files saved to workspace mounts persist between commands.
- Exit codes are limited to 0–255.
- Empty-path behavior depends on the Python build. Use
.for the current directory. - A workspace mount at
/libor any path starting with/lib/pythonmakespython3exit 126 to protect the interpreter’s standard library. Other paths under/lib, such as/lib/app, are fine.