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

EnclaveJS provides a distributed architecture for executing AI-generated code with streaming results:

Packages

@enclave-vm/types

Protocol types and Zod schemas for the streaming runtime

@enclave-vm/stream

NDJSON streaming, encryption, and reconnection handling

@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

Standalone deployable runtime worker

Key Features

  • Real-time Streaming: NDJSON-based protocol for streaming stdout, logs, and tool calls
  • Tool Orchestration: Define tools with Zod schemas, handle tool calls during execution
  • Session Management: Track execution sessions with limits, stats, and lifecycle management
  • End-to-end Encryption: Optional ECDH + AES-256-GCM encryption for sensitive workloads
  • 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)

Client Setup (React)

Deployment Modes

Embedded Mode

The broker runs the sandbox directly (simplest setup):

Extracted Mode

The broker connects to a separate runtime worker via WebSocket (for isolation/scaling):

Stream Events

The streaming protocol emits these event types: