Skip to main content
Execution

Bash

Run shell commands and arbitrary argument-vector operations through the agentOS execution lifecycle with controlled input, output, and exit status.

Run bash inside the VM. Shell commands are the simplest agentOS execution surface, and share the same execution lifecycle as JavaScript, TypeScript, Python, and package workflows.

  • Hosted v1.process.run takes an executable and an argument array. Run sh with -c for pipes, redirects, and globs.
  • Library process.exec() runs a bash command line, and process.execFile() runs an executable whose arguments are never parsed by a shell.
  • In-VM only: Commands run inside the VM, never in the host shell.

For multi-step work, consider JavaScript or Python instead. One call returns real data structures instead of a chain of shell calls.

Run commands

Background and interactive work

spawn starts a long-lived process and returns a handle. From there you get stdin, a PTY, output replay, signals, and waiting.

Files and software

Shell commands see the same filesystem as JavaScript and Python. Common POSIX commands ship by default; more is projected through the software registry.

Host functions

Host functions appear as commands, so pipelines use trusted host capabilities without putting credentials inside the VM. Host functions are library-only.

import { AgentOs } from "@rivet-dev/agentos-core";
import { z } from "zod";

// The handler runs on the host, so the API key never enters the VM.
const vm = await AgentOs.create({
	hostFunctions: {
		weather: {
			forecast: {
				inputSchema: z
					.object({ city: z.string() })
					.describe("Get the weather forecast for a city"),
				execute: async ({ city }) => {
					const res = await fetch(
						`https://api.weather.example/forecast?city=${city}&key=${process.env.WEATHER_API_KEY}`,
					);
					return res.json();
				},
			},
		},
	},
});

try {
	// The collection is projected into the VM as an `agentos-weather` command,
	// so it composes with pipes and redirects like any other program.
	const result = await vm.process.exec(
		"agentos-weather forecast --city Paris > /tmp/forecast.json && wc -c < /tmp/forecast.json",
		{ output: { capture: "all" } },
	);
	console.log(result.outcome === "succeeded" ? result.stdout : result.error);
} finally {
	await vm.dispose();
}

Permissions, limits, and timeouts

Every command inherits the VM permission policy and resource limits.

import { AgentOs } from "@rivet-dev/agentos-core";

const runtime = await AgentOs.create();

try {
	// timeoutMs is a wall-clock deadline. It expires into a result rather than
	// throwing; a denied operation gets the normal POSIX error.
	const result = await runtime.process.exec("sleep 10", { timeoutMs: 1_000 });
	console.log(result.outcome); // "timed_out"
} finally {
	await runtime.dispose();
}

Embedded API

The library examples use AgentOs.create(). The host owns dispose(), and files only outlive the VM when its root filesystem is stored in SQLite; see Persistence.

Read more in the embedded API quickstart.