CORE BUILDING BLOCKS

Host Gateway

Understand the trust boundary between isolated Sandboxes and the host — how Service Bridge enforces identity and schemas, and how Model Gateway keeps API keys off containers.

TRUSTED HOSTHolds secrets, Services & run logsYour Harness• Control loop & rules• Role Profiles• Custom Service logicRuntime• Agent registry & slots• Input & file logs• Lifecycle event streamoutputDir/<runtimeId>/• runtime.json / evidence.jsonl• service-calls.jsonl• model-trace/ & archivesService Bridge (HTTP)• Per-agent token → verified agentId• Checks permissions & input pre-call, output post-call• Forwards to in-process or HTTP Service & repliesModel Gateway• Per-agent revocable bearer token• Injects upstream API keys strictly on host• Optional per-request lease check & abortService dispatch / replyservice logslease gatemodel tracesHOST / SANDBOX TRUST BOUNDARY · KEYS ON HOSTISOLATED SANDBOX· OpenSandbox sandbox & private workspaceWorker Supervisor• Stages prompt · pauses writers on sync• Stops executor & streams archivesmanagesPi, Codex, or custom executor• Local file & shell tools (isolated /workspace/project)• Calls swarm CLI & model endpointspublicUrl/bridgeauth · req / respublicUrl/model/<alias>auth · streamed SSE

Every Agent runs inside an isolated container without upstream model keys or direct access to host Service credentials. Host Gateway is the trusted host boundary handling all model and Service traffic, composed of Service Bridge and Model Gateway (shown above).

1. Service Bridge: authenticated cross-sandbox calls

When an Agent calls a Service through a native tool, a code proxy or swarm service invoke, the request passes through the host Service Bridge, which enforces four checks before calling your Service and returning the reply:

  1. Verified caller identity: each Agent receives a unique per-Agent bearer token at spawn time. The Bridge resolves the real caller.agentId, caller.profile, and optional caller.binding — an Agent can never spoof another member in JSON input.
  2. Permission enforcement: verifies that the Agent is currently allowed to call that operation (combining Profile.services and any live runtime.access updates).
  3. Pre-call input and post-call output JSON Schema checks: Ajv (draft-07 or 2020-12, with no coercion or default injection) validates inputs before dispatching — malformed requests are blocked before touching business state. Outputs are validated after the adapter returns (for writes, a SERVICE_OUTPUT_INVALID error means the side effect may already have occurred — inspect Service state before retrying).
  4. Automatic audit ledger: logs every input, timing, result, and error to service-calls.jsonl, powering cross-Agent handoffs in Trace Viewer.

2. Model Gateway: keeping API keys off containers

Inside a sandbox, the executor sends model requests only to the host Model Gateway using a revocable per-Agent token:

  • Host-only credentials: your upstream API keys stay in createRuntime({ models }) on the host and never enter sandbox environment variables.
  • Instant revocation: calling stop(), encountering a fatal error, or detecting an unexpected exit immediately revokes the Agent’s token and aborts active streams.
  • Optional lease gating (modelAccessPolicy): harnesses like TaskPool can check a synchronous permit before every model request and immediately abort inference if a task lease expires.
  • Full model tracing: raw forwarded Responses or Chat Completions requests and streamed responses (as well as custom trusted ModelTransport handlers) are archived under model-trace/ for token auditing and debugging.
  • Single callback origin: set connection.publicUrl to a sandbox-reachable HTTP(S) URL (including any reverse-proxy path prefix). Runtime routes /bridge and /model/<alias-hash> through one listener while keeping Service Bridge and Model Gateway tokens, permissions, and budgets independently verified and streaming model responses directly through.

3. Egress allowlists and per-Agent credentials

When your OpenSandbox deployment has administrator-configured dns+nft packet filtering enabled, declare egressMode: 'dns+nft' on the sandbox connection. Profiles can then allowlist exact non-loopback IPv4 HTTP(S) origins, and Runtime automatically includes its callback target before creating the sandbox:

network: { allow: ['http://172.17.0.1:3000'] }

Only the listed IP and TCP port are permitted — other ports on the same IP remain blocked. Domain-plus-port rules are not supported and fail before allocation, as do DNS-only deployments. Management-endpoint authentication and sandbox egress restrictions are verified independently.

To inject member-scoped application credentials (such as a per-Agent Gitea token) without sharing them across a Profile, pass them via runtime.spawn({ secretEnv }).


Next: learn how to build and connect your own shared Services in Services & Permissions.

Inspect model failures from the Host

Subscribe to Runtime events before starting work. A modelDiagnostic event identifies a failed or unknown model request through requestId and error.diagnostic. The diagnostic can contain the observed upstream HTTP status, a safe upstream request identity, rejection kind and a bounded Retry-After hint. Its facts distinguish local dispatch, an observed upstream terminal, protocol checks and downstream delivery. The original request and result remain in the Run directory after Runtime closes.

A request observation carries its own identity. An exclusive Harness input failure can additionally identify its input request and accepted receipt. SDK, Harness completion, foreground output and RPC retain recognized framework diagnostics. MODEL_INTERRUPTED identifies an executor-confirmed aborted outcome. Inspect the original stop/interrupt receipt for confirmation of a particular Host control. Old Run records can have fewer fields, and missing facts remain unknown.