Browser vs Node
What stays the same and what changes when a box runs in a browser tab versus server-side in Node.
The same @lifo-sh/core runs in a browser tab and in Node. The kernel, shell,
commands, and Node layer are environment-agnostic — only the bottom "host bridge"
differs.
What's identical
- The Sandbox API, shell, commands, and the Node runtime behave the same.
os.platform()returns"lifo"in both, so code can detect the VM and branch on it (a sanctioned pattern for template code that must work with or without Lifo).
What differs
| Concern | Browser | Node |
|---|---|---|
| Persistence | IndexedDB (persist: true) | in-memory by default; host FS via mounts |
| Live previews | service worker at `/_sw/<boxId>/<port>/` | reach ports directly or via a tunnel |
| Outbound HTTP | CORS proxy for non-CORS hosts | direct (no CORS restriction) |
| Terminal | xterm.js via a container/selector | any ITerminal, or headless |
| Host filesystem | not available | mounts maps real directories in |
Mounting the host filesystem (Node)
In Node, the mounts option backs a subtree of the VFS with a real directory, so
a box reads and writes files on your machine:
const sandbox = await Sandbox.create({
mounts: [
{ virtualPath: "/workspace", hostPath: "/Users/me/project" },
{ virtualPath: "/readonly", hostPath: "/etc", readOnly: true },
],
});This uses NativeFsProvider under the hood; you can supply a custom
NativeFsModule if you're not on node:fs.
Headless runs (Node)
Without a terminal, a box runs headless — ideal for scripting and tests. There's
no TTY (so interactive prompts don't fire unless you feed stdin) and no CORS
restriction (outbound fetch works directly). This is the fastest way to drive
the VM in a test:
const sandbox = await Sandbox.create(); // no terminal
const { stdout, exitCode } = await sandbox.commands.run("node build.js");Tip
Because behavior is shared, the fastest way to debug a VM issue is headless in Node (a stack trace, no browser round-trip). Only reach for a real browser when the bug is specific to the service worker or IndexedDB.
On the roadmap
Choosing the filesystem backend explicitly (IndexedDB/OPFS in the browser, the
host FS via the CLI, or purely volatile) and a standalone lifo binary that runs
isolated boxes on a host are on the roadmap.