Skip to main content
Runtime

Output Capture

Capture and stream stdout and stderr from Agent OS Exec processes.

import { JavaScriptRuntime } from "@rivet-dev/agentos/javascript";

const rt = await JavaScriptRuntime.create();

try {
	const { stdout, stderr, exitCode } = await rt.execute(`
		console.log("hello from the VM");
		console.error("oops from the VM");
		process.exit(3);
	`);

	console.log("exitCode:", exitCode);
	console.log("stdout:", JSON.stringify(stdout));
	console.log("stderr:", JSON.stringify(stderr));
} finally {
	await rt.dispose();
}

execute(), evaluate(), and CodeProcess.wait() return complete UTF-8 stdout and stderr strings. Pass onStdout or onStderr to receive the same text incrementally without disabling final capture.

Output is bounded by the VM’s configured limits. For the underlying stream, buffer, and process behavior, see AgentOS Processes & Shell and Resource Limits.