
Secure Node.js Execution Without a Sandbox
A lightweight library for secure Node.js execution.
No containers, no VMs — just npm-compatible sandboxing out of the box.
Powered by the same tech as Cloudflare Workers.
Run untrusted code with one function call.
Run untrusted scripts against host functions you define. Your credentials stay in your process.
import { evaluate } from "secure-exec";
import { crm } from "./crm";
import { z } from "zod";
const result = await evaluate<{ accounts: number; openTickets: number }>(
`
const accounts = await customers.findAccounts({ industry: "fintech" });
const tickets = await customers.openTickets({ account: accounts[0].id });
return { accounts: accounts.length, openTickets: tickets.length };
`,
{
hostFunctions: {
customers: {
findAccounts: { inputSchema: z.object({ industry: z.string() }), execute: ({ industry }) => crm.findAccounts(industry) },
openTickets: { inputSchema: z.object({ account: z.string() }), execute: ({ account }) => crm.openTickets(account) },
},
},
},
);Benchmarks
V8 isolates vs. sandboxes.

Cold startWhat's measured: Time from requesting an execution to first code running.
Why the gap: Secure Exec spins up a V8 isolate inside the host process. No container, no VM, no network hop. Sandboxes must boot an entire container or microVM, allocate memory, and establish a network connection before code can run.
Sandbox baseline: e2b, the fastest provider on ComputeSDK as of March 18, 2026.
Secure Exec: Median of 10,000 runs (100 iterations × 100 samples) on Intel i7-12700KF.
Our benchmarks →
Lower is better
Memory per instanceWhat's measured: Memory footprint added per concurrent execution.
Why the gap: V8 isolates share the host process and its V8 engine. Each additional execution only adds its own heap and stack (~3.4 MB). Sandboxes allocate a dedicated container with a minimum memory reservation, even if the code inside uses far less.
What this means: On a 1 GB server, you can run ~210 concurrent Secure Exec executions vs. ~4 sandboxes.
Sandbox baseline: 256 MB, the smallest minimum among popular providers (Modal, Cloudflare Containers) as of March 18, 2026.
Secure Exec: 3.4 MB, the converged average per execution under sustained load.
Our benchmarks →
Lower is better
Cost per execution-secondWhat's measured: server price per second ÷ concurrent executions per server
Why it's cheaper: Each execution uses ~3.4 MB instead of a 256 MB container minimum. And you run on your own hardware, which is significantly cheaper than per-second sandbox billing.
Sandbox baseline: Cloudflare Containers, the cheapest sandbox provider benchmarked. Billed at $0.0000025/GiB·s with a 256 MB minimum (March 18, 2026).
Secure Exec: 3.4 MB baseline per execution, assuming 70% utilization. Select a hardware tier above to compare.
Our benchmarks → · Full cost breakdown →
Lower is better

Why Secure Exec
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.
npm
Package manager
Next.js
Framework
React
UI library
Astro
Framework
TypeScript
Language
webpack
Bundler
esbuild
Bundler
Git
Version control
Express
HTTP server
Hono
HTTP server
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.
| Approach | Full 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.
Untrusted code runs on the host with full access to your operating system.
A naive architecture runs untrusted code inside your process, with subtle vulnerabilities and denial of service.
Process isolation, Spectre mitigations, and resource limits run code securely.
FAQ
npm install secure-exec is all you need. It has zero infrastructure dependencies: no Docker daemon, no hypervisor, no orchestrator, no sidecar. It runs anywhere Node.js or Bun runs.- AI agent code execution and tool use
- User-facing dev servers (Express, Hono, Next.js)
- MCP tool-code execution
- Sandboxed plugin / extension systems
- Interactive coding playgrounds
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.