Skip to main content

EnclaveJS Streaming Runtime

EnclaveJS is a streaming runtime layer built on top of @enclave-vm/core that enables real-time code execution with tool orchestration, session management, and client SDKs for browser and React applications.

Architecture

A client sends a script to a broker over HTTP. The broker runs it in an @enclave-vm/core sandbox in its own process, runs the tools the script calls, and streams the events of the session back: @enclave-vm/runtime is not part of this picture: it holds building blocks of a separate runtime worker and does not execute scripts yet.

Packages

@enclave-vm/types

Protocol types and Zod schemas for the streaming runtime

@enclave-vm/stream

NDJSON streaming, reconnection helpers, and encryption primitives

@enclave-vm/broker

Tool broker with session management and HTTP API

@enclave-vm/client

Browser and Node.js client SDK

@enclave-vm/react

React hooks and components

@enclave-vm/runtime

Building blocks of a runtime worker; not a runnable service

Key Features

  • Real-time Streaming: NDJSON-based protocol that streams the events of a session (tool calls, progress, the result)
  • Tool Orchestration: Define tools with Zod schemas on the broker, which runs them when a script calls them
  • Session Management: Track execution sessions with limits, stats, and lifecycle management
  • Bring your own authentication: The broker does not authenticate callers or limit request rates; with its identify hook a session belongs to the caller that created it
  • Encryption Primitives: ECDH, HKDF and AES-256-GCM building blocks in @enclave-vm/stream. The client and broker do not encrypt: sessions are plain JSON protected by HTTPS
  • Automatic Reconnection: Built-in reconnection with sequence tracking and event buffering
  • React Integration: First-class React hooks for building interactive code execution UIs

Quick Start

Server Setup (Broker)

To serve sessions over HTTP for the client, register the broker’s routes on an Express app; see @enclave-vm/broker.

Client Setup (React)

Deployment

The broker runs the sandbox in its own process. There is no mode option: createBroker() takes enclave, limits, history and sessions.
A session runs on the broker’s thread. A script that computes without calling a tool holds that thread, and with it every other session, until it ends or reaches toolTimeoutMs. When you serve callers you do not trust, keep that limit low and run the broker in a process of its own, or give the sandbox the worker-pool adapter (enclave: { adapter: 'worker_threads' }). A deployment in which the broker hands execution to a separate runtime worker is not implemented: the broker has no option to connect to one, and @enclave-vm/runtime rejects an execute request with RuntimeNotImplementedError.

Stream Events

The streaming protocol emits these event types: The protocol also defines stdout and log events; the broker does not emit them. See Streaming Protocol.