Skip to main content
wasi_snapshot_preview1 for WebAssembly modules, shaped like Node’s node:wasi. WebAssembly itself is the standard global (MDN).
Nothing is patched globally. Create a WASI, pass its imports to WebAssembly.instantiate, then start() a command or initialize() a reactor.

WASI

constructor


Creates one WASI environment. A host directory outside data/ needs the filesystem permission and must exist.

getImportObject


The imports to pass to WebAssembly.instantiate. wasi.wasiImport is the same syscall table on its own, for merging with your own imports.

start


Runs a command: calls _start() and returns the exit code (0 when _start returns). Call start() or initialize() once per WASI.
With returnOnExit: false, proc_exit throws an Error with exitCode.

initialize


Sets up a reactor (a module without _start): calls _initialize() if it’s exported. Then call its exports yourself.

dispose


Closes every file the guest opened. Happens on unload anyway. alive is false afterwards, and using disposes at the end of the block.

Guest environment


Example

Run a WASI command from data/app.wasm.