Skip to main content
Operating System

Processes & Shells

Execute commands, manage long-running processes, replay their output, and open interactive shells.

Every guest process is an entry in the VM’s kernel process table, never a host process.

HostedLibrary
Run to completion with an argument arrayv1.process.run({ command, args })process.execFile(file, args)
Run a shell command linev1.process.run({ command: "sh", args: ["-c", line] })process.exec(line)
Start a long-running processv1.process.spawn({ command, args }) returns { generation, pid }process.spawn(command, args) returns { pid }

Process arguments are passed as individual argv entries. An empty string is a valid argument; it is not dropped or treated as an omitted argument. Empty commands or working directories are invalid input.

Manage running processes

OperationHostedLibrary
Write and close stdinv1.process.stdin.write, v1.process.stdin.closeprocess.writeStdin, process.closeStdin
Send a signalv1.process.signalprocess.signal, process.kill
Resize a PTYv1.process.pty.resizeprocess.resizePty
Wait for exitv1.process.waitprocess.wait
Inspectv1.process.get, v1.process.list, v1.process.treeprocess.get, process.list, process.tree

Hosted operations take the process handle { generation, pid }; library operations take the pid. A hosted handle from before a v1.vm.restart fails with stale_generation.

get and list report startedAtMs as a Unix timestamp in milliseconds. tree includes guest child processes as well as processes launched through the API, so it can show more than you started. Use the returned handle or pid rather than reconstructing one from a node; guest children that were not launched through the API have no hosted process handle.

A process wait returns an exit only after agentOS observes a guest exit. A rejected launch or lost exit observation rejects the wait instead of inventing an exit code. An observation failure does not prove the guest has stopped; inspect the VM or recreate it before assuming it is safe to retry work.

Output events and replay

Process output can be replayed after the fact, even after the process has exited or a live event was missed. Hosted VMs retain output for every spawned process; in the library, pass output: { retainEvents: true } to spawn. Then page through retained output with a sequence cursor.

Pass the last cursor as after to read the next page. A replay page reports nextCursor, hasMore, and truncated. Live events are low-latency hints: process.output and process.exit on a hosted connection, or vm.onProcessOutput and vm.onProcessExit in the library. Retention is bounded; see Resource Limits for the defaults.

Interactive shells

Interactive terminals allocate a kernel PTY and start a shell attached to it.

OperationHostedLibrary
Openv1.terminal.openterminal.open, returns a shellId
Write inputv1.terminal.stdin.writeterminal.write
Resizev1.terminal.pty.resizeterminal.resize
Wait and closev1.terminal.wait, v1.terminal.closeterminal.wait, terminal.close
Outputterminal.output and terminal.exit events, v1.terminal.output.read replayvm.onShellData, vm.onShellStderr, vm.onShellExit

Hosted VMs also list open terminals with v1.terminal.list.