agent-sandbox
A secure, embeddable, WASM-based sandbox for AI agents. 80+ built-in CLI tools, a full shell interpreter, a JavaScript runtime, safe HTTP networking, <13ms startup, no Docker/VMs required.
Installation
Rust
Node.js
Prebuilt binaries are available for macOS (arm64, x64), Linux (x64, arm64), and Windows (x64).
Quick Start
Rust
use ;
let config = SandboxConfig ;
let sandbox = new?;
let result = sandbox.exec.await?;
println!;
// Execute JavaScript inside the sandbox
let js_result = sandbox.exec_js.await?;
// HTTP fetch with SSRF protection
let response = sandbox.fetch.await?;
println!;
Node.js
import from "@parassharmaa/agent-sandbox";
const sandbox = ;
const result = await sandbox.;
console.log;
// Execute JavaScript inside the sandbox
const jsResult = await sandbox.;
// HTTP fetch
const response = await sandbox.;
console.log;
// curl interception — routed through the safe client
const curlResult = await sandbox.;
const changes = await sandbox.;
await sandbox.;
Features
- 80+ tools: cat, grep, find, sed, awk, jq, git, tar, zip, curl, seq, md5sum, and more
- Full shell interpreter (
sh/bash) with pipes, redirections, variables, loops, functions, and command substitution - Built-in JavaScript runtime (Boa engine) via
nodecommand orexecJs()API - Safe HTTP networking with SSRF protection, domain policies, and rate limiting
fetch()available in JS runtime, as a direct API, and viacurlcommand interception- Filesystem sandboxing with path traversal prevention
- Resource limits: fuel, timeout, memory
- Change tracking via filesystem snapshots
- AOT precompiled WASM — <13ms cold start, ~55us cached
- Node.js bindings (NAPI)
Networking
The sandbox provides safe HTTP access via agent-fetch, with built-in SSRF protection, domain allowlists/blocklists, DNS rebinding prevention, and rate limiting.
Networking is disabled by default. Enable it by providing a fetchPolicy:
const sandbox = ;
Three ways to make HTTP requests:
// 1. Direct fetch API
const res = await sandbox.;
// 2. curl command (intercepted and routed through the safe client)
await sandbox.;
// 3. fetch() inside the JS runtime
await sandbox.;
JavaScript Runtime
The sandbox includes a built-in JavaScript engine (Boa) that runs entirely inside the WASM sandbox. Use it via the node command or the execJs() convenience method.
// Inline evaluation
await sandbox.;
// Evaluate and print result
await sandbox.; // stdout: "14"
// Run a script file (from /work)
await sandbox.;
await sandbox.;
// Convenience method
await sandbox.;
// fetch() is available when networking is enabled
await sandbox.;
Supported JS features: ES2023+ (variables, arrow functions, destructuring, template literals, Promises, Map/Set, JSON, Math, RegExp, Array methods, and more).
Shell Interpreter
The sandbox includes a full shell interpreter accessible via sh or bash. It supports most common shell constructs, all running entirely inside the WASM sandbox.
Pipes and Redirections
// Pipes
await sandbox.; // stdout: "2"
await sandbox.;
// Output redirection
await sandbox.;
await sandbox.; // append
// Input redirection
await sandbox.;
Variables and Expansion
// Variable assignment and expansion
await sandbox.; // "hello world"
// Default values
await sandbox.; // "fallback"
await sandbox.; // "default\ndefault"
// String length
await sandbox.; // "5"
// Command substitution
await sandbox.;
await sandbox.;
// Arithmetic
await sandbox.; // "11"
// Special variables
await sandbox.;
Control Flow
// if/elif/else
await sandbox.;
// for loops
await sandbox.;
// while loops
await sandbox.;
// case statements
await sandbox.;
Functions
await sandbox.;
// stdout: "Hello, World!\nHello, Agent!"
Command Chaining
// AND chain — runs second only if first succeeds
await sandbox.;
// OR chain — runs second only if first fails
await sandbox.;
// Semicolons — always runs both
await sandbox.;
Real-World Agent Examples
// Install dependencies and run tests (typical CI pattern)
await sandbox.;
// Process data pipeline
await sandbox.;
// Generate a report
await sandbox.;
Available Commands
Text Processing: cat, head, tail, grep, rg, sed, sort, uniq, cut, tr, wc, awk, tac, rev, nl, paste, comm, join, fold, column, expand, unexpand, strings, od
Search & Files: find, tree, ls, mkdir, cp, mv, rm, du, ln, stat, touch, tee, readlink, rmdir, split, file
Data & Hashing: jq, diff, patch, base64, sha256sum, sha1sum, md5sum, xxd
Archives: tar, gzip, zip
Code & Version Control: git
Shell & Utilities: sh, bash, echo, printf, env, xargs, basename, dirname, seq, sleep, which, whoami, hostname, printenv, date, expr, true, false, test, [
Networking: curl (intercepted through safe client)
JavaScript Runtime: node
Limitations
- JS runtime has no Node.js built-in modules (fs, http, etc.) —
fetch()is the only network API - Single-threaded execution (pipes run sequentially via temp files)
- Shell does not support job control, signal handling, or process spawning
- Same-architecture precompiled binary
Best for: file-manipulation agents (code analysis, refactoring, git ops), sandboxed JS evaluation, safe API calls, multi-step shell scripts. Not for: databases, GPU, long-running servers.
License
MIT