Everything, Everywhere
Verified Specification | Standardized Formulas | Instant Precision
Secure & Private (Zero Data Retention) Free Access • No Sign-Up
WebAssembly Component Model WASI 0.2 (Preview 2) Canonical ABI & WIT

WebAssembly Component Model & WASI 0.2 Studio

Master the next era of sandboxed serverless computing. Inspect Wasm Interface Types (WIT), model Canonical ABI memory lowering and lifting across isolated linear memories, and compose polyglot components with wasi:http serverless edge handlers.

1. Polyglot Component Composition Pipeline

Component A: Edge Ingress (Rust) wasi:http
Language: Rust (wasm32-wasip2)
Linear Memory: [0x0000..0xFFFF] (64 KB)
Exports: incoming-handler.handle
State: Ready
Component B: Anomaly Classifier (Python) wit:classifier
Language: Python (Componentize-Py)
Linear Memory: [0x0000..0x3FFFF] (256 KB)
Imports: tensor-types
State: Idle
Component C: Key-Value Cache (Go) wasi:keyvalue
Language: Go (TinyGo wasip2)
Linear Memory: [0x0000..0x1FFFF] (128 KB)
Exports: store.get / store.set
State: Idle

2. Canonical ABI Memory Marshalling & WIT Definition

package example:edge-service@0.2.0;

interface types {
  record request-payload {
    client-ip: string,
    user-agent: string,
    risk-score: f32,
  }
}

world edge-worker {
  import wasi:http/outgoing-handler@0.2.0;
  import wasi:keyvalue/store@0.2.0;
  
  export wasi:http/incoming-handler@0.2.0;
}
Click "Execute Request Pipeline" to trace how high-level types are lowered into Component A memory, transferred via host realloc, and lifted into Component B memory.

⚠️ 5 Fatal Traps in WebAssembly Component Model & WASI 0.2

1. Missing 'cabi_realloc' Export Causing Fatal Host Traps

When passing variable-length types (like strings or byte arrays) into a component, the host invokes the component's exported cabi_realloc function to allocate memory. If a custom toolchain fails to export cabi_realloc, the runtime immediately panics with a fatal unhandled trap.

2. Unintended Linear Memory Bloat Across Multiple Composed Runtimes

Composing a Rust component with a Python component (via Componentize-Py) embeds the entire CPython interpreter binary and garbage collector inside the Wasm binary (~15-20 MB). Developers assuming all Wasm components are lightweight can be surprised by massive memory consumption at high concurrency.

3. WIT Semantic Version Mismatches During Composition

If Component A expects wasi:http@0.2.0 while Component B was compiled with wasi:http@0.2.0-rc-1, the component composer (wac or wasm-tools compose) strictly refuses to link them. Semantic version constraints on WIT interfaces are exact and non-negotiable.

4. Blocking I/O Deadlocks on Async 'wasi:io/poll'

In WASI 0.2, network streams and subprocess pipes are non-blocking and yield pollable handles. If a component attempts a synchronous spin-loop read without yielding execution via wasi:io/poll.poll, it blocks the host thread and starves other serverless tasks.

5. Premature Resource Handle Dropping

In WIT interfaces, dropping a resource-drop handle before all downstream consumers finish reading triggers an instant host error. Complex pipelines must pass borrowed references (borrow<stream>) instead of owned resources to guarantee lifecycle safety.

Frequently Asked Technical Questions

What problem does the WebAssembly Component Model solve over raw core Wasm modules?+
Core WebAssembly (MVP) only supports low-level primitive types (i32, i64, f32, f64) across a single shared linear memory. Passing strings, complex structs, or objects required custom, error-prone manual memory serialization in raw bytes. The Wasm Component Model introduces a language-agnostic type system (WIT) and the Canonical ABI, enabling polyglot components (written in Rust, Python, Go, C) to import and export high-level data types, records, variants, and resource handles with strong isolation and zero shared memory data races.
What is WASI 0.2 (WASI Preview 2) and how does it replace legacy WASI Preview 1?+
WASI Preview 1 was modeled after legacy POSIX system calls (like fd_read and fd_write) and lacked modularity. WASI 0.2 is built directly on the Component Model and WIT. It decomposes system capabilities into composable interfaces: wasi:cli (command-line tools), wasi:filesystem (capability-based sandboxed directory access), wasi:sockets (non-blocking network sockets), and wasi:http (native HTTP request/response proxies). This enables serverless runtimes (such as Spin, Fastly Compute, and Wasmtime) to run edge microservices with sub-millisecond cold starts.
How does the Canonical ABI handle memory allocation during string or record passing?+
When Component A passes a string to Component B, Component A lowers the string into its own linear memory (emitting a pointer and UTF-8 byte length). The host runtime calls the Canonical ABI realloc function inside Component B to allocate the exact number of bytes in Component B's separate linear memory, copies the bytes across the memory boundary, and lifts the pointer/length into Component B's native string type. Neither component has direct access to the other's linear memory.
What are Resource Types and Borrowing in WIT interfaces?+
WIT resources represent stateful objects managed by a component or the host runtime (e.g. an open HTTP stream or a database transaction handle). Rather than passing raw memory pointers, the Component Model issues opaque 32-bit resource handles. The "borrow" semantic allows temporary read/write access to a resource during a function call without transferring ownership, preventing double-free and memory leak vulnerabilities across component boundaries.
Can a Wasm component written in Rust call a component written in Python or Go without network RPCs?+
Yes. The Bytecode Alliance tooling (wac and wasm-tools) allows statically or dynamically composing multiple distinct component binaries into a single unified .wasm artifact. Function calls between components execute as direct in-process jumps via the Canonical ABI at near-native speeds, eliminating the 2-5ms latency and JSON/Protobuf serialization overhead of traditional HTTP/gRPC microservice boundaries.
Sponsored Utility
While You're Here
Sponsored Recommendations
Advertisement