Skip to content

About

A whole Linux machine in a Cloudflare Durable Object: unkernel (Linux compiled to wasm), Alpine, SQLite disk, outbound networking

Resources

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

linux-please

A whole Linux machine inside a Cloudflare Durable Object.

Each Durable Object runs unkernel (a real Linux 7.x kernel compiled to WebAssembly) and boots Alpine Linux. The root disk lives in the Durable Object's SQLite, so the machine keeps its files across restarts. Guest TCP goes out through Cloudflare's connect() sockets, so apk add, curl and wget work.

One Durable Object per name gives you one machine per name: box=alice, box=ci-1234, box=agent-7.

demo@cloudflare-do $ uname -a
Linux unkernel 7.3.4+ ... aarch64 Linux                     [250 ms]
demo@cloudflare-do $ sudo apk add -q jq curl && echo installed
installed                                                   [5.7 s]
demo@cloudflare-do $ echo '{"n":[1,2,3]}' | jq '.n|add'
6                                                           [291 ms]
demo@cloudflare-do $ curl -sI https://github.com | head -1
HTTP/2 200                                                  [1.2 s]

Inspired by postgres-please, which runs Postgres (pglite) in a Durable Object with SQLite as its disk. This does the same one level down.

Numbers (measured on Cloudflare, 2026-11-29)

Bundle (kernel + Alpine image) 8.8 MB gzipped (fits the paid plan's 10 MB limit)
New machine, end to end (cold start, disk setup, boot, first command) 1.4 to 2.1 s
Command on a running machine about 0.2 to 0.5 s round trip
Restart from a saved disk under 1 s, files intact
Guest RAM 64 MiB default, up to 128 MiB tested

What you can do with it

  • A throwaway Linux box per agent, test run or user, created by naming it.
  • A persistent scratch machine that keeps installed packages and files between sessions.
  • Run ordinary CLI tools (jq, curl, wget, the busybox set) next to your Worker without containers.
  • Restart a machine with ?reset=1: it reboots from its SQLite disk with your files intact.

How it works

  • Kernel: unkernel runs Linux as wasm with a real MMU and emulates aarch64 user programs. Workers block compiling wasm at runtime, so its JIT is off and user code runs on its interpreter.
  • Disk: a small BlockDevice stores 4 KiB blocks as rows in the Durable Object's SQLite. Alpine's read-only base image is bundled; your changes go to the SQLite disk through overlayfs.
  • Network (src/net.mjs): each guest TCP connection becomes a connect() socket. Workers have no UDP, so DNS answers with placeholder addresses (198.18.0.0/15) and the socket is opened by hostname. Cloudflare refuses raw TCP to port 80, so plain HTTP is parsed and sent through fetch() instead.

Two fixes were needed

  1. Clock. In workerd a setTimeout can fire before performance.now() reaches its deadline. The guest's timers then never expire (sleep 1 hangs). scripts/setup.mjs patches the SDK to move its virtual clock forward when a timer fires early.
  2. Disk writes. Writing each block to SQLite from inside the kernel's block path froze the kernel (most likely the Durable Object's input gate). Writes go to a dirty map and are saved once a second in one transactionSync.

Limits

  • CPU. Heavy work in one request can hit Cloudflare's CPU limit, which resets the Durable Object (the disk survives). Installing from Alpine's community repo did this; main is fine.
  • Clock. Cloudflare only advances time on I/O, so guest timestamps during busy CPU work are off.
  • Network. No UDP, ICMP, IPv6 or inbound connections. Hosts behind Cloudflare's own proxy can't be reached over HTTPS (Cloudflare blocks sockets to them).
  • Durability. Up to 1 s of guest writes can be lost if the Durable Object dies.
  • Cost. A running machine keeps its Durable Object in memory, billed for duration. No hibernation yet.
  • Shared isolates. Several Durable Objects can share one isolate, so all VM state is kept on the instance, not in module scope.

Run it

Needs Node 24+ and a Cloudflare account on the paid Workers plan.

npm install                      # also fetches Alpine and patches the SDK
npx wrangler secret put BOX_TOKEN   # pick a long random token
npm run deploy

Then open a shell (the token can also go in a .box_token file):

BASE=https://linux-please.<your-subdomain>.workers.dev BOX_TOKEN=... node console.mjs mybox
BASE=... BOX_TOKEN=... node console.mjs demo --demo     # a short tour first

Or one command at a time:

curl -G -H "Authorization: Bearer $BOX_TOKEN" "$BASE/run" \
  --data-urlencode box=mybox --data-urlencode "cmd=cat /etc/os-release"

Every request needs the token: a box is a real machine with outbound internet on your account. For local development, put BOX_TOKEN=... in .dev.vars and run npm run dev.

Credits and license

The code in this repository is MIT licensed.

About

A whole Linux machine in a Cloudflare Durable Object: unkernel (Linux compiled to wasm), Alpine, SQLite disk, outbound networking

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages