Operating System
Processes & Shell
Run commands with one-shot exec, spawn long-running processes with streaming stdout/stderr and stdin, manage their lifecycle (stop, kill, wait, inspect), open interactive PTY-backed shells, and inspect the process tree across all VM runtimes.
One-shot execution
Section titled “One-shot execution”Use exec to run a command and wait for completion. Returns stdout, stderr, and exit code.
import { createClient } from "@rivet-dev/agentos/client";import type { registry } from "./server";
const client = createClient<typeof registry>({ endpoint: "http://localhost:6420" });
const result = await client.vm.getOrCreate("my-agent").exec("echo hello && ls /home/agentos");console.log("stdout:", result.stdout);console.log("stderr:", result.stderr);console.log("exit code:", result.exitCode);Spawn a long-running process
Section titled “Spawn a long-running process”Use spawn for processes that run in the background. Output is streamed via processOutput and processExit events.
import { createClient } from "@rivet-dev/agentos/client";import type { registry } from "./server";
const client = createClient<typeof registry>({ endpoint: "http://localhost:6420" });const agent = client.vm.getOrCreate("my-agent");const conn = agent.connect();
// Subscribe to process outputconn.on("processOutput", (data) => { const text = new TextDecoder().decode(data.data); console.log(`[pid ${data.pid}] ${data.stream}: ${text}`);});
conn.on("processExit", (data) => { console.log(`[pid ${data.pid}] exited with code ${data.exitCode}`);});
// Spawn a dev serverconst { pid } = await agent.spawn("node", ["/home/agentos/server.js"]);console.log("Started process:", pid);Write to stdin
Section titled “Write to stdin”Send input to a running process.
import { createClient } from "@rivet-dev/agentos/client";import type { registry } from "./server";
const client = createClient<typeof registry>({ endpoint: "http://localhost:6420" });const agent = client.vm.getOrCreate("my-agent");
const { pid } = await agent.spawn("cat", []);
// Write to stdinawait agent.writeProcessStdin(pid, "hello from stdin\n");
// Close stdin when doneawait agent.closeProcessStdin(pid);
// Wait for the process to exitconst exitCode = await agent.waitProcess(pid);console.log("exit code:", exitCode);Process lifecycle
Section titled “Process lifecycle”import { createClient } from "@rivet-dev/agentos/client";import type { registry } from "./server";
const client = createClient<typeof registry>({ endpoint: "http://localhost:6420" });const agent = client.vm.getOrCreate("my-agent");
const { pid } = await agent.spawn("node", ["/home/agentos/server.js"]);
// List all processes tracked by the VMconst processes = await agent.listProcesses();for (const p of processes) { console.log(p.pid, p.command, p.args.join(" "), p.running ? "running" : "exited");}
// Inspect a specific process by pidconst info = await agent.getProcess(pid);console.log(info.running, info.exitCode);
// Graceful stop (SIGTERM)await agent.stopProcess(pid);
// Force kill (SIGKILL)await agent.killProcess(pid);Interactive shells
Section titled “Interactive shells”Open an interactive shell with PTY support. Shell data is streamed via shellData events.
import { createClient } from "@rivet-dev/agentos/client";import type { registry } from "./server";
const client = createClient<typeof registry>({ endpoint: "http://localhost:6420" });const agent = client.vm.getOrCreate("my-agent");const conn = agent.connect();
// Subscribe to shell outputconn.on("shellData", (data) => { const text = new TextDecoder().decode(data.data); process.stdout.write(text);});
// Open a shellconst { shellId } = await agent.openShell();
// Write commands to the shellawait agent.writeShell(shellId, "ls -la /home/agentos\n");
// Resize the terminalawait agent.resizeShell(shellId, 120, 40);
// Close the shell when doneawait agent.closeShell(shellId);