WASI & Beyond the Browser
WebAssembly was designed for the browser — but its properties (safe sandboxing, near-native speed, and language-agnostic portability) make it equally valuable on servers, edge nodes, embedded devices, and plugin systems. The key that unlocks all of these environments is WASI — the WebAssembly System Interface.
Why run Wasm outside the browser?
Section titled “Why run Wasm outside the browser?”In the browser, the JavaScript engine is the host. It provides the runtime environment, handles memory, and exposes browser APIs. Outside the browser there is no JavaScript engine, no DOM, no fetch. A Wasm module that wants to read a file, write to stdout, or open a network socket needs a different host to supply those capabilities.
WASI is the standardised answer: a set of POSIX-like system-call definitions expressed as Wasm imports. Any runtime that implements WASI can run the same .wasm binary — on Linux, macOS, Windows, or a tiny microcontroller.
The host–runtime–module relationship
Section titled “The host–runtime–module relationship”flowchart LR H["Host\n(OS / Edge Platform)"] R["WASI Runtime\n(wasmtime / wasmer)"] M["Wasm Module\n(.wasm binary)"] H -->|"grants capabilities\n(dirs, sockets, env vars)"| R R -->|"exposes WASI imports\n(fd_write, path_open …)"| M M -->|"calls imports to\nread/write/execute"| R
The diagram shows the three-layer model:
- Host — the operating system or cloud platform. It decides which resources (directories, sockets, environment variables) the runtime may pass through.
- WASI Runtime — a standalone executable such as
wasmtimeorwasmer. It implements the WASI spec as Wasm import functions and enforces capability grants. - Wasm Module — the compiled binary. It imports WASI functions the same way it would import any other Wasm import. It never calls the OS directly.
Lessons in this module
Section titled “Lessons in this module”| # | Lesson | What you will learn |
|---|---|---|
| 1 | This overview | The why and the architecture |
| 2 | WASI Deep Dive | Capability security, Preview 1 vs 2, compiling Rust to WASI |
| 3 | wasmtime & wasmer | Running and embedding Wasm binaries with real runtimes |
| 4 | Component Model, SIMD & Threads | WIT interfaces, SIMD v128, and threads overview |
| 5 | Use Cases & When to Use Wasm | Plugins, edge, sandboxing, portable CLIs, and trade-offs |