Skip to main content
This guide shows how to build a real-time code execution interface using React and the EnclaveJS streaming SDK.

What You’ll Build

A code editor with:
  • Real-time syntax highlighting
  • Live execution with streaming output
  • Tool call visualization
  • Error display
  • Execution statistics

Prerequisites

  • React 18+
  • Node.js server running EnclaveJS broker
  • Basic React/TypeScript knowledge

Project Setup

Architecture

Step 1: Configure EnclaveJS Client

Step 2: Create the Provider

Step 3: Create Execution Hook

Step 4: Build the Editor Component

Step 5: Build Output Panel

Step 6: Build Tool Calls Panel

Step 7: Build Stats Panel

Step 8: Assemble the Main Component

Step 9: Add Styles

Step 10: Wire It Up

Using the Official React Package

The @enclave-vm/react package provides pre-built hooks:

Best Practices

  1. Debounce execution - Don’t run on every keystroke
  2. Show loading states - Indicate when code is running
  3. Handle disconnections - Reconnect automatically
  4. Limit output - Cap console output to prevent memory issues
  5. Sanitize display - Escape HTML in output
  6. Mobile support - Handle touch events for mobile editors