Mozilla’s WASI takes WebAssembly beyond the browser

WASI promises a standard interface for WebAssembly to access system resources like file systems and network connections.

Serdar Yegulalp Mar 29th 2019

Mozilla has announced a new standardization effort to provide a consistent way for WebAssembly applications to interact with any operating system they run on.

Dubbed WASI, or WebAssembly System Interface, the currently experimental project provides WebAssembly applications with a set of abstractions for performing tasks such as reading and writing files and network I/O. Each WebAssembly host implements WASI for the platform it runs on.

Another key element of WASI is that these behaviors are sandboxed. One example given by Mozilla is file access. A WASI-managed call to open a file would only work for the directories the application has explicit permission to read from or write to. Those permissions could also be limited per module.

Using WASI will require recompiling existing WebAssembly to work correctly, but WebAssembly is still early enough in its development that a change like this isn’t likely to be disruptive. Right now, two of the major toolchains for writing WebAssembly apps, Rust and C/C++, support WASI. Both leverage LLVM’s ability to generate WebAssembly code to achieve this.

To run WASI-enabled apps, you currently need more than stock WebAssembly support in the browser. One method is to use a browser-based polyfill, in much the same way that experimental features of JavaScript can be used. Another is by way of wasmtime, a standalone WebAssembly runtime that doesn’t use a browser. A third is yet another standalone runtime, Lucet, built by way of Mozilla's Cranelift code generation system. Mozilla hopes that in time browsers will support WASI natively.