Secure Exec — Secure Node.js execution without a sandbox - Rivet

Rivet

5 min read Original article ↗

Run untrusted code with one function call.

Run untrusted scripts against host functions you define. Your credentials stay in your process.

Benchmarks

V8 isolates vs. sandboxes.

Give your AI agent the ability to write and run code safely.

No infrastructure required

No Docker daemon, no hypervisor, no orchestrator. Runs anywhere Node.js, Bun, or an HTML5 browser runs. Deploy to Lambda, a VPS, or a static site — your existing deployment works.

Node.js & npm compatibility

fs, child_process, http, dns, process, os — backed by the virtual OS, not stubbed. Run Express, Hono, Next.js, and any npm package.

Built for AI agents

Give your AI agent the ability to write and run code safely. Works with the Vercel AI SDK, LangChain, and any tool-use framework.

Deny-by-default permissions

Nothing reaches the host unless you allow it. The network is denied until you opt in, and the host filesystem exposes nothing until you mount it. Permissions are set per scope: fs, network, child processes, env.

Configurable resource limits

CPU time budgets and memory caps. Runaway code is terminated deterministically with exit code 124 — no OOM crashes, no infinite loops, no host exhaustion.

Powered by V8 isolates

The same isolation primitive behind Cloudflare Workers for Platforms and every browser tab. Battle-tested at scale by the infrastructure you already trust.

Runs the Node.js libraries and CLIs your agent already reaches for, unmodified.

A sandboxed operating system, as a library

A bare V8 isolate can only compute. Secure Exec adds a virtual operating system inside the library, so Node.js gets everything it expects from a real machine. None of it touches the host unless you allow it.

Filesystem

  • Virtual POSIX filesystemnode:fs works as usual; writes never reach the host disk
  • Mount anythingS3, Archil, a host directory, or a custom backend at a guest path
  • Read & write filesvm.filesystem moves individual files in and out — no mount needed

Networking

  • Outbound requestsfetch, node:http, node:net, and DNS over a virtual network stack
  • Serversguest code listens on a virtual port; the host sends requests in
  • Token injectioncredentials attached at the boundary, never in guest code

Processes

  • Process treeschild_process spawns guest processes, never host ones
  • Shell and coreutilsa real sh, so npm scripts and CLIs like git behave
  • Pipes and PTYspiped commands and interactive programs work

Packages & runtime

  • npm installpackages install into the VM's own filesystem
  • TypeScriptexecute, evaluate, and type-check it
  • Contextskeep variables between calls like a REPL, several in parallel

Permissions

  • Deny by defaultthe network is denied until you allow it — everything, or only named hosts
  • Per-scope policyfs, network, childProcess, process, env, and host functions
  • Host functionsbindings run in your process; the guest sees only inputs and outputs

Resource limits

  • Timeoutsrunaway code returns timed_out instead of hanging your process
  • Memory capsbound the V8 heap per VM
  • Kernel limitsprocesses, file descriptors, sockets, filesystem bytes, output buffers

Secure Node.js that works the way agents need it

Every other way to run untrusted JavaScript makes you trade something away. Secure Exec keeps the V8 isolate and puts a virtual OS kernel behind it.

ApproachFull Node.js APIs & npm packagesWhat guest code gets: a virtual filesystem behind node:fs, networking through fetch, node:http and node:net, child processes with a real shell and coreutils, pipes and PTYs, and npm install into the VM's own filesystem.

That is what lets unmodified packages and CLIs — Next.js, webpack, esbuild, git — run as they expect.

Securely run untrusted codeThe bar: code you did not write, and its dependencies, cannot reach your filesystem, your network, or your processes, cannot read another VM's state, and cannot exhaust the host.

Secure Exec treats the guest as actively hostile: every syscall is serviced by the kernel, the network is denied by default, and CPU and memory are bounded.

Security model →

LightweightPer execution: ~17.9 ms to first code running and ~3.4 MB of memory, against seconds and a ~256 MB floor for a container or microVM.

It is a library, so there is no daemon, no hypervisor, no vendor account, and no egress fee. It deploys wherever your code already deploys.

Raw Node.jsnode:vm, child_process✓✗Node's own documentation states that node:vm is not a security mechanism: guest code can escape the context and reach the host realm. child_process spawns real host processes with your permissions.✓
Raw V8 isolate / QuickJSa bare JS engine✗A bare engine is only the JavaScript language. There is no fs, no net, no child_process, so most npm packages and every CLI fail.–An isolate is a language boundary, not a complete security boundary. Embedded natively in your process it shares an address space with your secrets, so it carries real attack surface: speculative-execution side channels such as Spectre, resource exhaustion (CPU spin, heap and stack exhaustion) that takes the host down with it, and engine bugs that escape straight into your process.

Containing that takes more than the isolate itself — mediated syscalls, resource accounting, and process separation.

How Secure Exec handles it →

✓
Container sandboxmicroVMs, Docker✓✓✗Cold starts run to seconds, the memory floor is about 256 MB, and you need a vendor account, API keys, and per-GB egress — per execution.
Secure ExecV8 isolate + virtual OS✓✓✓

How the security compares

Secure Exec uses the same architecture as Cloudflare Workers and Chromium, so untrusted code gets the security you would expect.

Raw Node.js

Untrusted code runs on the host with full access to your operating system.

Your processGuest codeuntrustednode:vm · child_process — not a security boundaryNO BOUNDARYHOSTFilesystemNetworkShellProcesses

Raw V8 isolate / QuickJS

A naive architecture runs untrusted code inside your process, with subtle vulnerabilities and denial of service.

Your processV8 isolate · QuickJSGuest codeuntrustedNO APIHOSTFilesystemNetworkShellProcesses

Secure Exec

Process isolation, Spectre mitigations, and resource limits run code securely.

Your processSECURITY BOUNDARYsyscallsSidecar processseparate from yoursV8 isolateGuest codeuntrustedVirtual OS kernelVirtual filesystemSocket tableProcess tablePipes · PTYs · DNSHOSTOPT-IN ONLYMountsNetwork allowlistBindings

FAQ

For those about to execute, we salute you.

Install Secure Exec, create a runtime, and execute untrusted code. All in a few lines of TypeScript.

Read the DocsView on GitHub