Skip to content

Repository files navigation


An image that changes based on the user's light or dark mode preference.

Enclave

Secure sandbox runtime for AI agents

npm ast-guardnpm @enclave-vm/core
npm @enclave-vm/brokernpm @enclave-vm/clientnpm @enclave-vm/react
NodeLicense

Documentation | Live Demo | FrontMCP Framework


Why Enclave?

  • Extensive security testing - See security audit for details
  • Defense in depth - 6 security layers for LLM-generated code
  • Streaming runtime - Real-time event streaming with tool call support
  • Zero-config - Works out of the box with sensible defaults
  • TypeScript-first - Full type safety and excellent DX

Install

Core Packages

npm install @enclave-vm/core # Secure JS sandbox
npm install ast-guard # AST security validation

Streaming Runtime

npm install @enclave-vm/broker # Tool broker & session management
npm install @enclave-vm/client # Browser/Node client SDK
npm install @enclave-vm/react # React hooks & components

Packages

PackageDescription
@enclave-vm/coreSecure JavaScript sandbox with 6 security layers
@enclave-vm/brokerTool registry, secrets management, session API
@enclave-vm/clientBrowser & Node.js client for streaming sessions
@enclave-vm/reactReact hooks: useEnclaveSession, EnclaveProvider
@enclave-vm/runtimeDeployable runtime worker (Lambda, Vercel, etc.)
@enclave-vm/typesTypeScript types & Zod schemas
@enclave-vm/streamNDJSON streaming, encryption, reconnection
ast-guardAST-based security validator

Quick Start

import{Enclave}from'@enclave-vm/core';constenclave=newEnclave({securityLevel: 'SECURE',toolHandler: async(name,args)=>{if(name==='getUser')return{id: args.id,name: 'Alice'};thrownewError(`Unknown tool: ${name}`);},});constresult=awaitenclave.run(` const user = await callTool('getUser', { id: 123 }); return { greeting: 'Hello, ' + user.name };`);if(result.success){console.log(result.value);// { greeting: 'Hello, Alice' }}enclave.dispose();

React Integration

import{EnclaveProvider,useEnclaveSession}from'@enclave-vm/react';functionApp(){return(<EnclaveProviderbrokerUrl="https://your-server.com"><CodeRunner/></EnclaveProvider>);}functionCodeRunner(){const{ execute, state, result, stdout }=useEnclaveSession();construnCode=()=>execute(` const data = await callTool('fetchData', { id: 123 }); return data; `);return(<div><buttononClick={runCode}disabled={state==='running'}>{state==='running' ? 'Running...' : 'Run Code'}</button>{stdout&&<pre>{stdout}</pre>}{result&&<pre>{JSON.stringify(result,null,2)}</pre>}</div>);}

Architecture

See README-ARCHITECTURE.md for detailed architecture documentation covering:

  • Deployment scenarios (embedded vs extracted runtime)
  • Streaming protocol (NDJSON)
  • Tool broker pattern
  • Reference sidecar & auto-ref
  • Security & encryption

Demos

Enclave Demo (basic sandbox)

npx nx serve enclave-demo

A CLI script that demonstrates core sandbox features: arithmetic, loops, tool calls, and security blocking of disallowed operations.

Streaming Demo (full architecture)

npx nx demo streaming-demo

Starts a 3-server architecture with a web UI, covering embedded, lambda, and direct execution modes:

  • Client (port 4100) — Web UI
  • Broker (port 4101) — Tool execution & session management
  • Runtime (port 4102) — Sandboxed code execution

Read the full documentation →


License

Apache-2.0

About

A secure JavaScript sandbox designed for safe AI agent code execution. Protects against code injection, prototype pollution, and sandbox escapes. The security layer that makes AI-generated code safe to run.

Topics

Resources

Code of conduct

Security policy

Stars

6 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages