The kernel
The Kernel owns a box's durable state — the filesystem, process table, virtual network, ports, and boot-time setup.
The Kernel is the bottom of the stack — the object that owns everything
persistent about a box. Sandbox.create() builds one for you, but you can also
construct a Kernel directly for lower-level use.
import { Kernel } from "@lifo-sh/core";
const kernel = new Kernel(/* optional persistence backend */);What the kernel owns
vfs— the virtual filesystem, an in-memory tree with pluggable providers.processRegistry— the process table (PIDs, status, abort controllers).networkStack— the virtual network: interfaces, sockets, DNS, routes, tunnels.portRegistry— aMap<number, handler>of listening ports; how an in-VM server is reached (and how previews find it).portBridge— routes virtual requests to the handler registered for a port.persistence— aPersistenceManagerthat saves the VFS to a backend (IndexedDB in the browser, in-memory otherwise).serviceManager— a systemd-lite that runs unit files (systemctl).
Boot-time setup
Constructing a kernel lays down a believable base system:
- Mounts synthetic providers:
/proc(process info) and/dev. - Writes
/etc/motd,/etc/hostname(lifo),/etc/profile, and~/.liforc(Lifo's.bashrc). - Seeds
/etc/hostsand loads it into the network stack's DNS resolver. - Installs a set of sample files.
When persistence is enabled, the kernel watches the VFS and schedules a save on every change, so a box's disk survives a page reload.
Note
The kernel is intentionally thin. It holds state and wires subsystems together; the behavior lives in the shell, the commands, and the Node runtime that run on top of it.
Requests and handlers
The kernel exposes a small request/response contract used by the network and preview layers:
VirtualRequest/VirtualResponse— a minimal HTTP-like message pair.VirtualRequestHandler— what a listening port registers so incoming requests reach it.
This is the seam the service worker bridge and tunnels plug into to expose an in-VM port to the outside world.