Skip to content
agentfrontPublic

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

Latest commit

 

History

145 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Enclave logo

Enclave

A sandbox for JavaScript written by AI agents

npm @enclave-vm/core npm @enclave-vm/ast npm @enclave-vm/browser License: Apache-2.0

Documentation | Live demo

Enclave runs AgentScript, the subset of JavaScript that a language model writes to call your tools, under your control. A script is checked statically, rewritten so that the runtime can enforce limits, and executed in a sandbox where it reaches nothing but the globals and tools you give it. The packages cover the sandbox for Node.js and for the browser, and a streaming layer that runs scripts behind HTTP routes.

Packages

Package What it is
@enclave-vm/core The sandbox for Node.js: validation, transformation, a reduced realm, limits, an optional worker pool
@enclave-vm/ast The static layer: validator, presets, pre-scanner and transforms
@enclave-vm/browser The sandbox for browsers, in nested sandboxed iframes
@enclave-vm/broker Tool registry, secrets, sessions and their HTTP routes (bring your own authentication)
@enclave-vm/client Browser and Node.js client for broker sessions (plain JSON over HTTP; use HTTPS)
@enclave-vm/react React provider and hooks around the client: EnclaveProvider, useEnclaveSession
@enclave-vm/types TypeScript types and Zod schemas of the streaming protocol
@enclave-vm/stream NDJSON streaming, reconnection helpers, and encryption primitives the other packages do not use
@enclave-vm/runtime Building blocks of a separate runtime worker; it does not execute scripts yet

Quick Start

npm install @enclave-vm/core
import { Enclave } from '@enclave-vm/core';

const enclave = new Enclave({
  securityLevel: 'SECURE',
  toolHandler: async (name, args) => {
    if (name === 'getUser') return { id: args.id, name: 'Alice' };
    throw new Error(`Unknown tool: ${name}`);
  },
});

const result = await enclave.run(`
  const user = await callTool('getUser', { id: 123 });
  return { greeting: 'Hello, ' + user.name };
`);

if (result.success) {
  console.log(result.value); // { greeting: 'Hello, Alice' }
} else {
  console.error(result.error);
}

enclave.dispose();

To run scripts for clients over HTTP, register your tools with @enclave-vm/broker and connect with @enclave-vm/client or @enclave-vm/react. To run scripts in the user's browser, use @enclave-vm/browser.

How the Layers Fit Together

  • Static layer (@enclave-vm/ast): the pre-scanner checks the source text, and the AgentScript preset accepts only an allowlist of syntax, globals and property keys. Its presets are filters on source text, not a boundary on their own.
  • Node.js runtime (@enclave-vm/core): runs a validated script in a realm that holds only the allowed globals, behind a membrane, with limits on time, iterations, tool calls and memory. The memory limit is the enclave's own estimate of the operations that make data grow, not a limit of the heap: the default VM adapter does not count object literals, Maps, Sets or copies of arrays (see What memoryLimit Counts). It checks at run time what a static rule cannot decide, such as a property name built while the script runs. An optional worker pool adds a heap limit per worker and a hard stop; the heap limit does not guarantee that the host process survives, since Node.js may still abort the process. It is not process isolation: tenants that must not share a process need a process or container each.
  • Browser runtime (@enclave-vm/browser): runs a validated script in two nested iframes with sandbox="allow-scripts" and a strict Content Security Policy. Inside the frame, the validator is what keeps a script from the document it runs in.
  • Streaming layer (@enclave-vm/broker, client, react, types, stream): runs the Node.js sandbox in the broker's process and streams events to clients. It has no authentication, rate limiting or encryption of its own.

Each package's README states what its layer does and does not guarantee. README-ARCHITECTURE.md describes the streaming architecture, what is implemented and what is design. SECURITY-TESTS.md lists the security invariants by layer and the ones that are still open.

Demos

npx nx serve enclave-demo     # CLI: arithmetic, loops, tool calls, refused operations
npx nx demo streaming-demo    # Web UI with three servers: client (4100), broker (4101), runtime (4102)

The three servers of the streaming demo are written for the demo, on @enclave-vm/core and @enclave-vm/types. They are not the @enclave-vm/broker and @enclave-vm/runtime packages: the runtime package does not execute scripts yet.

Development

The repository is an Nx monorepo and needs Node.js 22 or later (.nvmrc pins the version used in development) and Yarn 4.

yarn install
yarn build
yarn test
yarn lint
yarn format:check

The security tests live in a private submodule (security-tests/); see SECURITY-TESTS.md.

Contributing and Security

Issues and pull requests are welcome on GitHub. Participation is governed by the Code of Conduct.

Please do not report vulnerabilities in public issues. Use the private channels described in SECURITY.md (GitHub Security Advisories preferred).

License

Apache-2.0. See LICENSE.

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