Runtime
Networking
A short overview of Agent OS Exec networking.
Guest fetch(), Node.js sockets, and Python networking all use the VM’s socket
table and permission policy.
import { JavaScriptRuntime } from "@rivet-dev/agentos/javascript";
// Guest program: start a loopback HTTP server, then fetch it. Both the listen
// and the fetch go through the kernel socket table.
const GUEST = `
import http from "node:http";
const server = http.createServer((_req, res) => {
res.writeHead(200, { "content-type": "text/plain" });
res.end("network-ok");
});
await new Promise((resolve, reject) => {
server.once("error", reject);
server.listen(0, "127.0.0.1", resolve);
});
const { port } = server.address();
const response = await fetch("http://127.0.0.1:" + port + "/");
const body = await response.text();
console.log("status:", response.status);
console.log("body:", body);
await new Promise((resolve) => server.close(resolve));
`;
// 1. Network allowed. This matches the high-level API default, but spelling it
// out makes the example's policy intent clear.
const allowed = await JavaScriptRuntime.create({
permissions: { network: "allow" },
});
try {
const result = await allowed.execute(GUEST);
console.log("[network allowed] exitCode:", result.exitCode);
console.log(
"[network allowed] stdout:",
JSON.stringify(result.stdout.trim()),
);
console.log(
"[network allowed] stderr:",
JSON.stringify(result.stderr.trim()),
);
} finally {
await allowed.dispose();
}
Networking defaults to allow. Set an explicit deny or allowlist before running untrusted code. See AgentOS Networking & Previews for egress rules, VM loopback, host-to-guest requests, and exposed ports.