Skip to content

Run Linux in Your Browser with Unkernel

An illustrated penguin steps through a browser window with a yellow terminal cursor.

Too long, didn’t read. Start Linux in this page and try uname -smr. You’ll get aarch64 from a kernel running as WebAssembly. Unkernel builds the kernel for the browser and gives programs like BusyBox an emulated Arm64 processor.

Linux terminal

Boots locally. Kernel download 12.7 MB before compression.

Explore Linux

Press Start Linux in the terminal . When you see the / # prompt, try these commands one at a time.

  1. Check the kernel. This build reports Linux 7.3.4+ aarch64.

    uname -smr
  2. Look around. The shell starts at /. Try looking inside /bin for commands, /etc for configuration or /proc for details about running processes.

    ls /
  3. See what’s running. Look for busybox init at the top and sh -i, your interactive shell, further down.

    ps

Use cd to move around and pwd to see where you are. Full screen gives you more room. This demo boots the small BusyBox system included with Unkernel.

How Linux becomes WebAssembly

aarch64 is the Linux machine name for Arm64. The file this page downloads is unkernel.wasm. How does a kernel built for a browser run a program built for an Arm processor?

During the release build, Unkernel patches and compiles the Linux source and packages it as unkernel.wasm. When you click Start Linux, the Web Worker loads that file, boots Linux and opens a shell.

The compilation happens when Unkernel builds its release. The build first patches the Linux source. The patches add arch/wasm, a port that grew out of Joel Severin’s linux-wasm work. It gives Linux WebAssembly-specific code for low-level operations such as switching between tasks. Notes on the Linux port · Task switching

Clang compiles the patched kernel to WebAssembly (Wasm), a binary instruction format the browser can run. A patched linker, wasm-ld, combines the kernel with kwemu, Unkernel’s Arm64 emulator written in Zig. Kernel build

The build bundles that module with a small boot filesystem into unkernel.wasm. That filesystem contains BusyBox compiled for Arm64, so when Linux starts it, kwemu executes its Arm64 instructions. Bundle contents · Guest filesystem

Memory is one part that needs adapting. On an Arm64 machine, the processor reads page tables set up by Linux to translate a program’s virtual addresses into locations in physical memory. A Wasm module works with linear memory, a block of bytes it accesses by offset.

Unkernel puts the guest’s memory in that block. When BusyBox uses a virtual address, kwemu looks up the corresponding location in Linux’s page tables. It can then reach those bytes at the right offset in the Wasm module’s memory. Memory model

What Start Linux does

When you press Start Linux, the page creates a Web Worker, where JavaScript can run separately from the page’s main thread. Inside the worker, Unkernel downloads the already-built unkernel.wasm, starts the kernel and opens a shell. Unkernel’s JavaScript runtime supplies services the kernel needs from its host, such as a clock. Host interface

On the published site, the worker gets the pinned Unkernel build from jsDelivr. The guest runs on your device with no external network connection, and its changes last until the session ends. Unkernel source and licenses

Follow uname through the worker

Type uname -smr and press Enter. JavaScript forwards the keystrokes to the worker, and the shell runs BusyBox’s uname on kwemu. uname makes a system call, a request to the kernel for information about the running system. kwemu hands that request to the Linux code already running as Wasm. System call handling

BusyBox prints the result and the worker sends it back to the terminal on the page.

The page sends keystrokes to the worker. The Linux shell inside the worker runs uname, and the worker sends the output back to the page.

That aarch64 is the machine BusyBox sees. The same guest can report it even when the computer running the browser has a different processor.