Runtime
Filesystem
A short overview of the Agent OS Exec filesystem.
Executed code sees the VM’s POSIX filesystem. Standard Node.js and Python file APIs use it without reaching the host filesystem.
import { JavaScriptRuntime } from "@rivet-dev/agentos/javascript";
// Boot a fully virtualized VM. The guest filesystem lives entirely inside the
// kernel - writes never touch the host disk.
const rt = await JavaScriptRuntime.create();
try {
// Guest code runs as an ES module inside the VM. It writes and reads files
// using the standard node `fs` module, backed by the kernel's virtual
// filesystem.
const { stdout, stderr, exitCode } = await rt.execute(`
import { mkdirSync, writeFileSync, readFileSync, readdirSync } from "node:fs";
mkdirSync("/workspace", { recursive: true });
writeFileSync("/workspace/hello.txt", "hello from the VM");
const message = readFileSync("/workspace/hello.txt", "utf8");
const entries = readdirSync("/workspace");
console.log("read back from VM:", message);
console.log("/workspace contents:", JSON.stringify(entries));
`);
console.log("exitCode:", exitCode);
if (stderr.trim()) console.log("guest stderr:", stderr.trim());
console.log("guest stdout:");
console.log(stdout.trim());
} finally {
await rt.dispose();
}
Seed files with the runtime’s files option or use runtime.vm for host-side
file operations and mounts. See AgentOS Filesystem for the
full API and mount backends.