
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.
Give your AI agent secure code execution
Expose secure-exec as a tool with the Vercel AI SDK. Your agent can execute arbitrary code without risking your infrastructure.
import { generateText, stepCountIs, tool } from "ai";
import { anthropic } from "@ai-sdk/anthropic";
import { NodeRuntime, createNodeDriver, createNodeRuntimeDriverFactory } from "secure-exec";
import { z } from "zod";
// Create a sandboxed runtime
const runtime = new NodeRuntime({
systemDriver: createNodeDriver({
permissions: {
fs: () => ({ allow: true }),
network: () => ({ allow: true }),
},
}),
runtimeDriverFactory: createNodeRuntimeDriverFactory(),
memoryLimit: 64,
cpuTimeLimitMs: 5000,
});
// Expose as an AI SDK tool
const { text } = await generateText({
model: anthropic("claude-sonnet-4-6"),
prompt: "Calculate the first 20 fibonacci numbers",
stopWhen: stepCountIs(5),
tools: {
execute: tool({
description: "Run JavaScript in a secure sandbox. Assign the result to module.exports to return data.",
inputSchema: z.object({ code: z.string() }),
execute: async ({ code }) => runtime.run(code),
}),
},
});
console.log(text);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 — bridged to real host capabilities, not stubbed. Run Express, Hono, Next.js, and any npm package.
Compatibility matrix →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
Filesystem, network, child processes, and env vars are all blocked unless explicitly allowed. Permissions are composable functions — grant read but not write, allow fetch but block spawn.
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.
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

Secure Exec vs. Sandboxes
Not every workload needs a full OS. Secure Exec gives you V8-level isolation for code execution — no container required.
Run untrusted code (Node.js, Python) inside your backend process
Spin up a full OS with root access, system packages, and persistent disk
Need a full sandboxed operating system? We've got that too.
Run coding agents in sandboxes. Control them over HTTP.
Supports Claude Code, Codex, OpenCode, Amp, and Pi.
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.