Use @secure-exec/sandbox as a compatibility shim
main@rivet-dev/agentos-sandbox. It is intended to provide a bridge or compatibility layer for environments that require the AgentOS sandbox interface within the Secure Exec ecosystem.repository·main·Indexed 21 days ago
https://github.com/rivet-dev/secure-execA lightweight, high-performance code execution engine using V8 isolates to run untrusted code in a secure, deny-by-default environment. It provides Node.js compatibility and supports core modules (fs, child_process, http) and frameworks like Express, Hono, and Next.js without the overhead of containers or VMs. Features include a pluggable filesystem architecture with ObjectFs and ChunkedFs engines, and compatibility shims for AgentOS runtime, sandbox, sidecar, and TypeScript environments.
@rivet-dev/agentos-sandbox. It is intended to provide a bridge or compatibility layer for environments that require the AgentOS sandbox interface within the Secure Exec ecosystem.@rivet-dev/agentos-typescript. It is intended to provide the necessary interfaces or behaviors required by projects expecting the AgentOS TypeScript environment within the Secure Exec ecosystem.Secure Exec is designed for high-performance, isolated code execution in several scenarios:
Secure Exec and Cloudflare Workers both run untrusted JavaScript in V8, but they serve different architectural needs:
| Feature | Secure Exec | Cloudflare Workers |
|---|---|---|
| Form factor | Library you embed (secure-exec), runs where your app runs | Managed edge platform you deploy to |
| Isolation unit | Per runtime: each NodeRuntime.create() is its own VM and OS process | Per Worker isolate, scheduled by Cloudflare |
| Guest runtime | V8 isolate inside a virtualized POSIX kernel (filesystem, processes, sockets, PTYs) | V8 isolate with the workerd runtime |
| Permissions | Deny-by-default capability policy you configure per runtime | Platform-managed; no per-call capability policy |
| Subprocesses | Real node:child_process against kernel-managed processes | Not available |
| Filesystem | Full virtualized filesystem per runtime | Limited in-memory node:fs surface, ephemeral |
| Operation | You operate it (your process, your machine) | Cloudflare operates it |
Choose Cloudflare Workers for managed, globally distributed deployment of your own code. Choose Secure Exec to run untrusted or AI-generated code inside your own application with a hard, self-placed isolation boundary, a real virtualized filesystem, and a controllable capability policy.
@secure-exec/browser serves as a compatibility shim for @rivet-dev/agentos-runtime-browser. It is intended to provide a consistent interface or bridge for environments that require compatibility with the AgentOS runtime within a browser context.@secure-exec/sidecar package serves as a compatibility shim for @rivet-dev/agentos-sidecar. It is designed to provide a consistent interface or bridge for sidecar-related functionality within the Secure Exec ecosystem, ensuring compatibility with the AgentOS sidecar implementation.Code Mode is a pattern that allows an AI agent to use a single code-execution tool instead of many individual Model Context Protocol (MCP) tools. Instead of making multiple round-trips to call isolated tools, the LLM writes JavaScript that orchestrates multiple operations (loops, branching, Promise.all) in a single execution. This code is run safely within a Secure Exec V8 sandbox.
Key Benefits:
globalThis.__return(), which the host decodes as result.value.Secure Exec provides a bridged environment that supports most Node.js core modules and web frameworks.
Most core modules are bridged to real host capabilities rather than being stubbed, including:
fs (Filesystem)child_process (Subprocesses)http / net (Networking)dnsprocessosYou can run web servers and frameworks out of the box, such as:
Secure Exec virtualizes all VM networking to ensure guest code cannot access the real host network. The networking model is built on several isolation principles:
fetch(), node:http, and raw sockets) is routed through a virtualized kernel socket table rather than the host network.network permission.loopbackExemptPorts.A common pattern is to check the exitCode and use stderr to provide diagnostic information when a guest fails:
const { stderr, exitCode } = await rt.exec(code);
if (exitCode !== 0) throw new Error(`guest exited ${exitCode}: ${stderr}`);For processes that are intended to stay alive (like development servers), use spawn() instead of exec() or run(). spawn() returns a live NodeRuntimeProcess handle which provides:
onStdout / onStderr streaming hooks.writeStdin(data) to send data to the guest.kill() to terminate the process.wait() to await the process exit.Secure Exec classifies its resource limit constants into three distinct categories. Understanding these classes helps you distinguish between hard system constraints and configurable security policies:
invariant: Hard limits that are fundamental to the system's stability or correctness. These cannot be changed by users or policies (e.g., MAX_SYMLINK_DEPTH, MAX_PATH_LENGTH).policy: Configurable limits that define the security boundary of an execution environment. These are typically used to restrict resource consumption (e.g., DEFAULT_PYTHON_MAX_OLD_SPACE_MB, MAX_WASM_MODULE_FILE_BYTES).policy-deferred: Limits that are part of the policy system but may be evaluated or applied at a different stage of the execution lifecycle (e.g., DEFAULT_PROCESS_TIMEOUT_MS).The architecture provides two primary filesystem engines depending on your use case:
ObjectFs (Direct Mapping)Maps paths directly to object keys. Best when external tools need to interact with the same bucket layout.
rename is a copy-and-delete; hard links are unsupported; symlinks are marker objects; partial writes rewrite the entire object.ChunkedFs (Managed POSIX)A managed filesystem designed for performance and deduplication.
blake3(content)). Identical chunks are deduplicated automatically.