# Core Architecture

Source: https://runvero.dev/docs/architecture/
Documentation index: https://runvero.dev/llms.txt

RunVero runs AI agent tools inside a default-deny WebAssembly (WASI 0.2) sandbox host, enforcing capability-based access rules, instruction-level fuel budgets, and digest-verified package integrity. See [Security & Trust Model](https://runvero.dev/docs/security) for the full deployment boundary matrix and limitations.

```mermaid
flowchart TB
    Client(["Client / Agent<br/>CLI · Python SDK · MCP"])
    Gateway["HTTP & MCP Gateway<br/>Auth · Quotas · Task grants"]
    Host[["Control Plane Host<br/>Rust Wasmtime runtime"]]
    Title["Isolated WebAssembly Sandbox<br/>WASI 0.2 / Wasmtime"]

    subgraph Sandbox[" "]
        direction LR
        Wasi["Virtualized WASI<br/>No ambient I/O"]
        Gov["Fuel & memory limits<br/>Epoch deadlines"]
        Guest["Guest tool<br/>wasm32-wasip2"]
        Wasi --> Gov --> Guest
    end

    Broker{{"Credential Broker & Redactor<br/>Placement · SSRF guard · Audit"}}
    Output(["Redacted result<br/>Fuel telemetry · Signed record"])

    Client --> Gateway --> Host --> Title --> Sandbox
    Sandbox --> Broker --> Output
    class Title sandboxTitle
```

## Architectural Layers

### 1. HTTP & MCP Gateway Layer
The gateway exposes HTTP REST (`/v1/execute`) and MCP JSON-RPC (`/mcp`) endpoints:
* **Defensive Security Headers:** Enforces `X-Content-Type-Options: nosniff`, `X-Frame-Options: DENY`, and `Cache-Control: no-store`.
* **Bounded Admissions & Quotas:** Authenticates `rv_live_*` / `rv_test_*` keys, enforces narrow-only request ceilings, verifies optional `X-RunVero-Task-Grant` policies, and caps concurrent workers.
* **CORS Defense:** Blocks wildcard permissive CORS headers.

### 2. WASI 0.2 Component Sandbox
Built on Wasmtime, RunVero instantiates guest tools as single-use WebAssembly components:
* **No Ambient Filesystem:** File access is off by default; when enabled, guests see only quota-bounded virtual `/input`, `/tmp`, and `/output` trees.
* **No Ambient Networking:** Guest components cannot open raw sockets or perform ambient DNS resolution; outbound HTTP passes through a resolve-then-connect SSRF guard.
* **Dual Fuel & Epoch Interruption:** Deterministic instruction fuel bounds compute loops while an epoch ticker interrupts guests blocked in host I/O.

### 3. Host Credential Brokering & Redaction
Credentials (API tokens, webhook signing keys) remain in host memory rather than raw guest environment variables:
* Guest tools receive per-execution opaque placeholders (`rvsec_...`), or reference `signing-only` HMAC keys that are never substituted into wire bytes.
* Outbound HTTP hooks verify destination rules, task-grant `allowed_credentials`, and explicit request placement (`header`, `query`, or JSON `body` pointer) before injecting values.
* Exact secret strings and common token prefixes are scrubbed from responses, errors, and logs as defense-in-depth (see [Credential Protection](https://runvero.dev/docs/secrets-bolt) for redaction scope and limits).
