What is WebAssembly? Wasm and WASI, explained
WebAssembly (Wasm) is a portable, sandboxed binary format that runs near native speed in browsers and servers. How it works, what WASI adds, and a 41-byte demo.

WebAssembly (Wasm) is a compact binary instruction format that compilers for languages like C, C++, Rust and Go can target, so the same compiled module runs in any browser, and outside the browser in a standalone runtime, at close to native speed inside a memory-safe sandbox. The official definition is short: “a binary instruction format for a stack-based virtual machine” (webassembly.org). WASI, the WebAssembly System Interface, is the set of standard APIs that lets those modules talk to files, clocks, sockets and HTTP when they run on a server instead of a web page.
Where did WebAssembly come from?
The W3C made the WebAssembly Core Specification a Recommendation on December 5, 2019, with a line that gets quoted a lot: “Following HTML, CSS and JavaScript, WebAssembly becomes the fourth language for the Web.” It was designed so browsers could run compiled code safely in the same engines that already run JavaScript.
The language has kept growing. Wasm 3.0, released September 17, 2025, added 64-bit memory addresses, multiple memories per module, garbage collection managed by the runtime, typed function references, tail calls, native exception handling and relaxed SIMD. Garbage collection matters most for reach: the announcement lists Java, OCaml, Scala, Kotlin, Scheme and Dart as languages targeting Wasm GC, which means they no longer have to ship their own garbage collector inside every module.
How does WebAssembly work?
The design goals explain most of it:
- Efficient and fast. The stack machine “is designed to be encoded in a size- and load-time-efficient binary format” and aims to “execute at native speed by taking advantage of common hardware capabilities.” The engine validates the module and compiles it to machine code for the host CPU.
- Safe. Wasm “describes a memory-safe, sandboxed execution environment.” A module gets a linear block of memory and cannot address anything outside it. It cannot call the operating system. It can only call functions the host explicitly passes in as imports. In a browser, it also obeys “the same-origin and permissions security policies of the browser.”
- Open and debuggable. Every binary has a text format (WAT) you can read.
“Stack-based” is the key phrase. Instructions push and pop values on an operand stack instead of naming registers. Here is a function that adds two 32-bit integers, in the text format:
(module
(func (export "add") (param i32 i32) (result i32)
local.get 0
local.get 1
i32.add))
What does a WebAssembly module look like in bytes?
Small enough to write by hand. This Python script builds that exact module byte by byte, decodes its sections, and runs its code body on a toy stack machine that handles the three opcodes it uses. Standard library only.
# wasm_add.py: hand-build a real .wasm module that exports add(i32, i32) -> i32,
# then decode its sections and run its code body on a toy stack machine. Stdlib only.
import struct
def section(sid, payload): # section = id byte + LEB128 size + payload (sizes < 128 here)
return bytes([sid, len(payload)]) + payload
wasm = (b"\0asm" + struct.pack("<I", 1) # magic + version 1
+ section(1, bytes([1, 0x60, 2, 0x7F, 0x7F, 1, 0x7F])) # type: (i32, i32) -> i32
+ section(3, bytes([1, 0])) # function 0 uses type 0
+ section(7, bytes([1, 3]) + b"add" + bytes([0, 0])) # export "add" = func 0
+ section(10, bytes([1, 7, 0, 0x20, 0, 0x20, 1, 0x6A, 0x0B]))) # code: local.get 0, local.get 1, i32.add, end
open("/tmp/batch14/add.wasm", "wb").write(wasm)
print(len(wasm), "bytes:", wasm.hex(" "))
NAMES = {1: "type", 3: "function", 7: "export", 10: "code"}
i, sections = 8, {}
while i < len(wasm):
sid, size = wasm[i], wasm[i + 1]
sections[sid] = wasm[i + 2:i + 2 + size]
print(f"section {sid:>2} {NAMES[sid]:<8} {size} bytes")
i += 2 + size
def run(body, args): # a stack machine for the three opcodes we used
stack, pc = [], 0
while body[pc] != 0x0B:
op = body[pc]
if op == 0x20: stack.append(args[body[pc + 1]]); pc += 2 # local.get
elif op == 0x6A: b, a = stack.pop(), stack.pop(); stack.append((a + b) & 0xFFFFFFFF); pc += 1 # i32.add
print(f" pc={pc:<2} stack={stack}")
return stack.pop()
body = sections[10][3:] # skip: 1 function, body size 7, 0 locals
print("add(40, 2) =", run(body, [40, 2]))
Output (Python 3.13.11):
41 bytes: 00 61 73 6d 01 00 00 00 01 07 01 60 02 7f 7f 01 7f 03 02 01 00 07 07 01 03 61 64 64 00 00 0a 09 01 07 00 20 00 20 01 6a 0b
section 1 type 7 bytes
section 3 function 2 bytes
section 7 export 7 bytes
section 10 code 9 bytes
pc=2 stack=[40]
pc=4 stack=[40, 2]
pc=5 stack=[42]
add(40, 2) = 42
The file is 41 bytes: the magic \0asm, version 1, then four sections. The type section declares the signature, the function section assigns it, the export section names it, and the code section holds five opcodes. The toy interpreter is only for seeing the stack move. The add.wasm file it writes is a real module: loaded into Node 24 with WebAssembly.instantiate, add(40, 2) returned 42. In a browser, loading it is two lines of JavaScript:
const { instance } = await WebAssembly.instantiateStreaming(fetch("/add.wasm"));
console.log(instance.exports.add(40, 2)); // 42
Notice what the module cannot do. It has no imports, so it cannot print, read a file or open a socket. That is the sandbox: a Wasm module’s power is exactly the set of functions the host hands it.
What is WASI?
Outside a browser there is no JavaScript to hand a module its imports, so a standard set was needed. WASI is “a group of standards-track API specifications for software compiled to the W3C WebAssembly (Wasm) standard.” Its security model is the one the sandbox implies: “a Wasm module or component starts with no ambient authority and can only do what the host explicitly grants.” A runtime gives a module a specific directory, not the filesystem; a specific socket, not the network.
There have been three milestone releases, 0.1, 0.2 and 0.3, sometimes called Preview 1, 2 and 3. Per the WASI roadmap, 0.2.0 “shipped in January 2024”; the WASI Subgroup voted to launch it on January 25, 2024, and with it, per the Bytecode Alliance, “WASI is now officially based on the Wasm component model.” The Component Model is “a specification for Wasm applications that are interoperable and composable”: components describe typed interfaces and can be linked across languages. 0.2 shipped two worlds, wasi-cli (which “roughly corresponds to POSIX”) and wasi-http, “an HTTP proxy world.” 0.3.0 shipped on June 11, 2026 and added “native async support” to the Component Model, with async func, stream and future types. No date is set for 1.0.
WebAssembly vs JavaScript: which should you use?
They are partners, not rivals. JavaScript owns the DOM and is the glue; Wasm cannot touch the DOM directly and goes through JavaScript to do so. Wasm wins when you already have a large codebase in another language (an image codec, a physics engine, a database, a PDF renderer) or when the work is CPU-bound and predictable. JavaScript wins for UI and for anything that is mostly calls into browser APIs, because every crossing between JS and Wasm has a cost.
A useful heuristic: if the hot loop is in your code, Wasm can help. If the hot path is the network or the DOM, it will not. For most UI work, the bigger wins are in what you ship at all, the argument behind React Server Components and htmx.
Why does WebAssembly matter outside the browser?
Three reasons, and the first is the one I care about.
Sandboxing untrusted code. From a data-platform seat, the recurring problem is running code you did not write next to data you must protect: user-defined functions, plugins, customer transforms. The usual answers are containers or separate processes. Wasm gives you a sandbox at the function level, with no ambient authority, that starts fast. The same logic now applies to code that agents write, which I covered in sandboxing AI agents and in code execution with MCP.
Portability. One compiled artifact runs on any CPU architecture and OS that has a runtime. For plugins, that removes the per-platform build matrix.
Embedding. Databases, proxies and editors embed a Wasm runtime so users can extend them safely in the language of their choice. It plays a similar role in user space that eBPF plays in the kernel: verified, sandboxed code loaded into a host that does not trust it.
Where does WebAssembly break?
The boundary is the bottleneck. Passing strings or objects between JavaScript and Wasm means copying through linear memory. Chatty APIs that cross the boundary on every call can be slower than plain JavaScript.
Debugging and tooling vary by language. Rust and C/C++ toolchains are mature. Others are catching up, and Wasm GC is recent enough that support differs between runtimes.
Binary size for some languages. Languages that bring a large runtime ship it in every module, though Wasm GC reduces this for managed languages.
The sandbox is only as tight as the imports. If the host grants a module the whole filesystem or an unrestricted HTTP client, the capability model protects nothing. The security work is in deciding what to grant.
WASI is still moving. Three milestone releases in a few years, with 1.0 unscheduled. Pin your runtime and WASI version and expect upgrades to touch interface code.
What I would do
In the browser, I would reach for Wasm only to port an existing native library or to speed up a measured CPU hot spot, and I would design the API so data crosses the boundary in big batches, not per item.
On the server, I would consider Wasm first for plugin systems and for running untrusted user or agent code, where a capability-scoped sandbox that starts in milliseconds is a real advantage over a container. I would grant each module the smallest set of imports that works, log every host call it makes, and target the Component Model so the plugins are not tied to one language.
I would not rewrite a working service in Wasm for portability alone. Containers already solve that well.
FAQ
Is WebAssembly faster than JavaScript?
For CPU-heavy, predictable work it often is, because it is compiled ahead of time with fixed types. For DOM-heavy or I/O-bound code, it usually is not, and crossing between JS and Wasm adds overhead.
Is WebAssembly a programming language?
It is a compilation target with a binary format and a readable text format (WAT). People rarely write it by hand; they compile Rust, C, C++, Go, Kotlin and others to it.
What is the difference between WebAssembly and WASI?
WebAssembly is the instruction format and sandbox. WASI is a set of standard APIs (files, clocks, sockets, HTTP) that a host can grant to a module running outside the browser.
Is WebAssembly secure?
The sandbox is memory-safe and a module can only call what the host imports into it. Bugs inside a module, such as a buffer overflow in compiled C, can still corrupt that module’s own memory; they just cannot escape it.
Can WebAssembly access the DOM?
Not directly. It calls JavaScript functions that the page imports into the module, and those touch the DOM. Toolchains generate that glue for you.
Sources
- WebAssembly home page and design goals, accessed October 31, 2026
- W3C, WebAssembly becomes a W3C Recommendation, December 5, 2019
- WebAssembly, Wasm 3.0 completed, September 17, 2025
- Bytecode Alliance, WASI 0.2 launched, January 2024
- WASI and the WASI roadmap, accessed October 31, 2026