WasiPy is a Python interpreter that runs in WebAssembly using RustPython, enabling Python code execution in sandboxed environments.
This project consists of two main components:
- executor: A WebAssembly module that contains the Python interpreter (RustPython)
- server: A Rust server that loads and executes the WebAssembly module to run Python code
First, build the Python interpreter as a WebAssembly module:
cargo build --target wasm32-wasip2 -p executor --releaseThis creates target/wasm32-wasip2/release/executor.wasm.
The server will load the WebAssembly module and execute Python code. This will mount the current directory as read-only.
cargo run --release -p server -- -m .:.:ro -c "import os; print('Current directory contents:'); [print(f' {item}') for item in os.listdir('.')]"Now try it again without the -m flag.