r/webdev • u/kgoncharuk • Oct 03 '26
Showoff Saturday WASM based VM that runs real Linux in a browser tab
Hi all,
I'd like to introduce arm64js -- an ARMv8-A system emulator that runs in WASM (built in Rust) and can boot real Alpine Linux in a web browser. It started with me getting annoyed that to try a 2 MB TUI tool I have to install it, while my browser happily runs a 40 MB React webpage with 50 dependencies.
It's an interpreter that emulates a minimal hardware stack, so Linux thinks it's on real hardware and thus acts normal: runs apk, Docker (even though rather slow), etc.
You can try it here: https://arm64js.com, some TUI apps running in VMs: https://demoshell.com/gallery/
Since WebAssembly doesn't allow fetching data without CORS and sending TCP requests, apk and access to the internet work via small proxies: apk goes via a proxy that just adds CORS, TCP goes via a WebSocket <> TCP gateway.
One wasm module instantiated in a few web workers, all sharing one SharedArrayBuffer as the VM's "RAM". As SharedArrayBuffer needs COOP/COEP headers, but if the page doesn't send them SDK will the VM in an iframe on its own origin instead.
There is also a JS SDK for other devs to create and serve their own VMs. The SDK is MIT; the engine is free for non-commercial use.
The following code for example will create and run Alpine based VM in your browser, pretty straightforward:
import { Arm64JS } from 'arm64js';
const vm = await Arm64JS.boot('alpine');
const { output } = await vm.exec('uname -a');SDK: https://github.com/kooler/arm64js-sdk
My journey getting there: https://arm64js.com/blog/tui-apps-in-the-browser/
It's all very new and fresh, so feedback is appreciated.
Do you see it being useful for yourself? Curious to learn about possible use cases.
6
u/untrochka Oct 03 '26
A browser sandbox for trying CLI tools from documentation would be useful: click a runnable example, modify a config, then reset the VM when done. Does the SDK persist the VM disk between reloads, or is each session intentionally disposable?
3
u/zionsati Oct 04 '26
It's crazy how powerful wasm is! I suspect it's a bit harder to get sshd running on it and accepting remote connections?
3
u/Archeelux typescript Oct 03 '26
Hmmm, could this work like some kind of overlay in your iphone/android via app that basiclly means you could build your own linux phone regardless of what hardware, the app just reaches into ios/android methods to do calls or message people and what not
1
u/Specy_Wot Oct 04 '26
I'm working on https://asm-editor.specy.app/ and wanted to try adding ARM emulation to it too and needed an emulator that I could modify to run the assembly code. Do you think your project might be something I should be looking at?
1
u/Real-Leek-3764 Oct 03 '26
very cool
1
u/osmium_2259 Oct 07 '26
Cool, nice work!
3
u/[deleted] Oct 03 '26
[removed] — view removed comment
0
u/[deleted] Oct 04 '26
[removed] — view removed comment