Skip to main content
Operating System

Processes & Shell

Run commands, start long-lived processes, and open interactive shells inside agentOS VMs with controlled environment and lifecycle management.

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

Use exec to run a command and wait for completion. Returns stdout, stderr, and exit code.

Spawn a long-running process

Use spawn for processes that run in the background. Call connect() and subscribe to native processOutput and processExit events, filtering their pid in application code.

Write to stdin

Send input to a running process.

Process lifecycle

Interactive shells

Open an interactive shell with PTY support. Subscribe to native shellData, shellStderr, and shellExit events, filtering their shellId in application code.

Embedded API

Process and terminal methods are identical except for actor-only shell listing and replay. Embedded output and exit callbacks are already scoped to one VM and one host process.

// One-shot execution
const result = await vm.process.exec("ls -la /home/agentos");
console.log(result.stdout);

// Long-running process with portable output and exit subscriptions.
await vm.filesystem.writeFile(
	"/tmp/server.mjs",
	'import http from "http"; http.createServer((req, res) => res.end("ok")).listen(3000); console.log("listening");',
);
const { pid } = await vm.process.spawn("node", ["/tmp/server.mjs"]);

vm.onProcessOutput(pid, (event) =>
	console.log(event.stream, new TextDecoder().decode(event.data)),
);
vm.onProcessExit(pid, (event) => console.log("exited:", event.exitCode));

// Write to stdin
await vm.process.writeStdin(pid, "some input\n");

// Stop or kill
await vm.process.signal(pid, "SIGTERM");

Read more in the embedded API quickstart.