Skip to main content
Node.js

Runtime & Platform

Configure the JavaScript process environment and use the underlying AgentOS VM.

Agent OS Exec runs JavaScript on the AgentOS Node-compatible runtime. ESM, top-level await, process, Buffer, supported node:* builtins, child processes, and mounted npm modules are available inside the VM.

const runtime = await JavaScriptRuntime.create();

try {
	const result = await runtime.evaluate<{
		filename: string;
		digest: string;
	}>(`(async () => {
		const { createHash } = await import("node:crypto");
		const { join } = await import("node:path");
		return {
			filename: join("/workspace", "report.json"),
			digest: createHash("sha256").update("agentos").digest("hex"),
		};
	})()`);

	if (!result.success) throw new Error(result.error.message);
	console.log(result.value);
} finally {
	await runtime.dispose();
}

Runtime defaults

Set runtime defaults with cwd, env, and files; override cwd or env per execution. runtime.vm exposes the underlying AgentOS filesystem, shell, HTTP, bindings, and mounts when the language-focused methods are not enough.

See JavaScript Runtime and Node.js Runtime for the underlying platform details.