{"slug": "pi-e-in-a-box-running-pi-on-risk-v-inside-a-vm-inside-tinyemu-inside-wasm", "title": "Pi(e) in a box: running pi on risk-v inside a VM inside TinyEmu inside WASM", "summary": "A developer built pi-box, an Electron app that wraps the AgentVM sandbox to boot directly into the pi coding agent with a single download and no extra dependencies. AgentVM, built on container2wasm, emulates a RISC-V 64 Linux VM via TinyEmu compiled to WebAssembly, using a pre-initialized kernel snapshot for roughly one-second shell startup and a JavaScript userland TCP/IP stack for networking. The project is aimed at secure, portable agent sandboxing and learning about WASM and virtualization, though the developer notes it remains slow for heavy workloads.", "body_md": "*(Written by a human, for the AI slop please check out the code on [GitHub](https://github.com/deepclause/pi-box))*\n\nA few months ago I started working on [AgentVM](https://github.com/deepclause/agentvm): an npm installable, almost dependency-free sandbox built on [container2wasm](https://github.com/container2wasm/container2wasm). Since I felt like revisiting the project (and also try out deepseek v4 pro along the way) I decided to make a few little improvements to it and build something useful with it. \n\nThe result is [pi-box](https://github.com/deepclause/pi-box): an electron app that wraps AgentVM and automatically boots into the pi coding agent, giving you a fully sandboxed agent with one download. Thanks to WASM, no extra dependencies are needed and we don’t have to care about hardware virtualization being supported etc. \n\nThis is what it looks like:\n\nAfter a (kind of slowish :-) startup the VM starts a tmux session with pi already running. It mounts a workspace folder on your host so that your pi config stays permanent. You can create different workspaces for your projects with different pi and tmux configs, as well as a customized start up script. Once you enter your LLM provider credentials in the usual way you are ready to go!\n\n**How does this work?**\n\ncontainer2wasm is a fascinating piece of technology. It basically works like this:\n\n1. Compile an emulator into WASM (you can choose between Bochs, TinyEmu and qemu)\n2. Cross-compile a kernel, libc and runc into whatever architecture you’re emulating.\n3. Package that together with the rootfs of whatever container you want to run and compile it into one big WASM module (either as a WASI image for e.g. wasmtime or using emscripten so that i can run in the browser).\n4. When the module starts, the emulator boots the kernel and then starts the container using runc (Don’t worry, future versions will add even more layers and indirection).\n\nClearly, this is not going to run very fast :-)\n\nThere are some tweaks that make this work fast enough for basic agentic work though (where we mostly wait for tokens to stream in anyways).\n\n1. container2wasm uses a pre-initialized snapshot from right after the kernel has finished booting. This is done using wizer and the result is that the VM has a shell ready within about 1 second depending on how fast your machine is.\n2. Choosing Risk-V 64 together with TinyEmu (that seems to have lower overhead than x86_64 apparently)\n3. Running node with —single-threaded-gc so that pi startup does not take forever. It still takes about 30secs sometimes, but it’s bearable. Normal shell, python work etc. seems ok. Anything involving numpy will probably be comically slow.\n\n**What about networking and host mounts?**\n\nThe original container2wasm supports networking using browser-side fetch or some gVisor thing that I am not really familiar with. Since I wanted the project to be almost dependency free and as portable as possible I decided to do something crazy (or stupid) and let first Gemini 3 Pro, then Opus 4.5 and later deepseek-v4 work out a userland TCP/IP stack written in Javascript. Most of the project time was then spent on debugging the network stack and making it more stable (that’s where I really lack experience, so that was rather annoying/sobering). Similarly, the AgentVM JS code also implements all the hooks necessary to get a filesystem mount going without a “proper” WASM runtime.\n\nIt’s all a bit shaky, but after a few millions (billions?) tokens spent on models of the last two/three generations it feels stable now. You can even start your VM (it’s based on alpine) run “apk update”, “apk add”, “pip install…” and it will (mostly) work.\n\n**What is this useful for?**\n\nI can imagine a bunch of use cases:\n\n1. Learning about WASM and virtualization\n2. Giving normal people an out of the box and secure coding agent experience.\n3. Easy and portable (albeit slow) drop in sandbox for agents and harnesses\n\n**It’s too slow for me! It sucks!**\n\nWell, you don’t have to like it or use it, but in any case I think it’s quite amazing to see what we can achieve these days. Even more so as a single developer with very little low level / systems programming experience (I had a course on virtualization a long time ago in college but that was it).\n\n**TODOs:**\n\n- More networking: Firewall, port forwarding, on/off toggle (guess I am rebuilding docker in wasm now…)\n- Overlay FS for better persistence\n- …", "url": "https://wpnews.pro/news/pi-e-in-a-box-running-pi-on-risk-v-inside-a-vm-inside-tinyemu-inside-wasm", "canonical_source": "https://deepclause.substack.com/p/pie-in-a-box-running-pi-on-risk-v", "published_at": "2026-09-14 04:43:06+00:00", "updated_at": "2026-09-14 04:57:08.008803+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "ai-infrastructure"], "entities": ["pi-box", "AgentVM", "container2wasm", "TinyEmu", "pi", "Electron", "WebAssembly", "GitHub"], "alternates": {"html": "https://wpnews.pro/news/pi-e-in-a-box-running-pi-on-risk-v-inside-a-vm-inside-tinyemu-inside-wasm", "markdown": "https://wpnews.pro/news/pi-e-in-a-box-running-pi-on-risk-v-inside-a-vm-inside-tinyemu-inside-wasm.md", "text": "https://wpnews.pro/news/pi-e-in-a-box-running-pi-on-risk-v-inside-a-vm-inside-tinyemu-inside-wasm.txt", "jsonld": "https://wpnews.pro/news/pi-e-in-a-box-running-pi-on-risk-v-inside-a-vm-inside-tinyemu-inside-wasm.jsonld"}}