Getting Started
Vanilla JavaScript
Run plain JavaScript in an isolated AgentOS runtime.
Install the single AgentOS package:
pnpm add @rivet-dev/agentos
Import JavaScriptRuntime from the /javascript subpath. The submitted source
can be plain ECMAScript with no Node.js-specific APIs.
// Boot a fully virtualized runtime. Guest code runs inside the kernel
// isolation boundary - no host escapes.
const runtime = await JavaScriptRuntime.create();
try {
// evaluate() returns a JSON-serializable value and captures stdout/stderr.
const result = await runtime.evaluate<{ message: string; sum: number }>(`
(() => {
console.log("hello from Agent OS Exec");
return { message: "hello from Agent OS Exec", sum: 1 + 2 };
})()
`);
if (!result.success) throw new Error(result.error.message);
console.log("stdout:", JSON.stringify(result.stdout.trim()));
console.log("value:", result.value);
console.log("exitCode:", result.exitCode);
} finally {
// Tear down the VM and release the sidecar.
await runtime.dispose();
}
Use execute() when stdout is the result, evaluate<T>() when the guest should
return a JSON-serializable value, and spawn() for a live process. Continue to
Executing Code for those shared modes.