Runtime Architecture
The Runra Runtime is the open-source orchestration layer that connects AI agents to sandbox infrastructure. It provides a unified interface for agents to create sandboxes, execute code, and receive structured observability events — regardless of which agent, LLM, or sandbox provider you use.
Design Philosophy
Section titled “Design Philosophy”Runra Runtime is built on three principles:
- Agent-agnostic: Works with any AI coding agent (Claude Code, Codex, OpenCode, custom).
- Provider-pluggable: Swap sandbox providers, LLM backends, and observability exporters without changing agent code.
- Event-driven: All operations emit typed events that flow to your observability stack.
Architecture Layers
Section titled “Architecture Layers”┌─────────────────────────────────────────┐│ Your Application ││ (Next.js, Express, CLI tool, Worker) │└───────────────┬─────────────────────────┘ │┌───────────────▼─────────────────────────┐│ Agent Adapters ││ Claude Code │ Codex │ OpenCode │ Custom│└───────────────┬─────────────────────────┘ │┌───────────────▼─────────────────────────┐│ Runra Runtime ││ ┌─────────────────────────────────────┐ ││ │ Orchestrator │ ││ │ - Sandbox lifecycle management │ ││ │ - Tool execution dispatch │ ││ │ - Event bus │ ││ └─────────────────────────────────────┘ ││ ┌──────────────┬──────────────────────┐ ││ │ Sandbox │ Observability │ ││ │ Provider │ Exporters │ ││ │ Interface │ Interface │ ││ └──────────────┴──────────────────────┘ │└───────────────┬─────────────────────────┘ │┌───────────────▼─────────────────────────┐│ Sandbox Providers ││ Runra Sandbox │ CubeSandbox │ Docker ││ E2B │ Custom │└─────────────────────────────────────────┘App Layer
Section titled “App Layer”Your application code. This is where you instantiate the Runra runtime, configure providers, and start agents. The runtime exposes a simple top-level API:
import { Runra } from "@runra/runtime";
const runra = new Runra({ sandbox: { provider: "runra-sandbox", apiKey: "..." }, agent: { provider: "claude-code", model: "claude-sonnet-4-20250514" }, observability: { provider: "axiom", token: "..." },});
await runra.start({ prompt: "Build a React todo app" });Agent Adapter Layer
Section titled “Agent Adapter Layer”Agent adapters translate between Runra’s tool interface and each agent’s native protocol. See Agent Adapters for details.
Orchestrator (Runtime Core)
Section titled “Orchestrator (Runtime Core)”The core runtime manages:
- Sandbox lifecycle: Create, pause, resume, terminate sandboxes through the configured sandbox provider.
- Tool dispatch: When an agent requests a tool (e.g.,
bash,edit,read), the orchestrator routes it to the sandbox. - Event bus: Every operation (sandbox created, command executed, file written) emits typed events.
- Concurrency: Manages parallel sandbox operations with configurable limits.
Provider Interfaces
Section titled “Provider Interfaces”The runtime defines two key interfaces:
Sandbox Provider Interface
Section titled “Sandbox Provider Interface”interface SandboxProvider { create(config: SandboxConfig): Promise<SandboxHandle>; get(id: string): Promise<SandboxHandle>; list(opts?: ListOptions): Promise<SandboxHandle[]>; pause(id: string): Promise<void>; resume(id: string): Promise<void>; terminate(id: string): Promise<void>; execute(id: string, command: string, opts?: ExecuteOptions): Promise<ExecuteResult>; writeFile(id: string, path: string, content: string): Promise<void>; readFile(id: string, path: string): Promise<string>;}Observability Exporter Interface
Section titled “Observability Exporter Interface”interface ObservabilityExporter { export(events: RuntimeEvent[]): Promise<void>; flush(): Promise<void>;}Any implementation of these interfaces can plug into the runtime. See Sandbox Providers and Observability for built-in and custom implementations.
Event System
Section titled “Event System”All runtime operations emit typed events. Events flow from the orchestrator to all configured observability exporters.
Event Schema
Section titled “Event Schema”Every event has a common envelope:
interface RuntimeEvent { id: string; // UUID timestamp: string; // ISO 8601 type: string; // Event type discriminator sandboxId: string; // Which sandbox runId: string; // Which agent run data: Record<string, unknown>; // Type-specific payload}Event Types
Section titled “Event Types”| Event Type | Description | Key Data Fields |
|---|---|---|
sandbox.created | Sandbox provisioned | image, resources |
sandbox.paused | Sandbox paused | runtimeDurationMs |
sandbox.resumed | Sandbox resumed | pausedDurationMs |
sandbox.terminated | Sandbox destroyed | totalRuntimeMs |
exec.completed | Command finished | command, exitCode, stdout, stderr, durationMs |
exec.streamed | Command output chunk | stream, content |
file.created | File written | path, sizeBytes |
file.read | File read | path |
file.deleted | File removed | path |
port.exposed | Port exposed | port, url |
port.closed | Port closed | port |
agent.thinking | Agent reasoning | thought |
agent.tool_call | Tool request | tool, args |
agent.tool_result | Tool response | tool, result |
cost.runtime | Resource usage cost | cost, durationMs |
Pluggable Design
Section titled “Pluggable Design”Every component is pluggable. See the dedicated pages:
- Agent Adapters — Claude Code, Codex, OpenCode, custom
- LLM Providers — OpenAI, Anthropic, Gemini, local
- Sandbox Providers — Runra, Docker, E2B, custom
- Observability — Axiom, OpenTelemetry, JSONL, custom
Integration Flow
Section titled “Integration Flow”A typical agent run through the runtime:
1. Application calls runra.start({ prompt: "..." })2. Orchestrator creates a sandbox via SandboxProvider3. Agent adapter starts the agent with the prompt4. Agent requests a tool (e.g., "run bash command")5. Orchestrator dispatches to SandboxProvider.execute()6. Result returned to agent7. Agent processes output, requests next tool8. Events emitted to ObservabilityExporters9. Agent completes; sandbox paused or terminatedNext Steps
Section titled “Next Steps”- Agent Adapters — connect AI agents
- Sandbox Providers — choose infrastructure
- Observability — export structured events
- Configuration Reference — all options