Skip to content

HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.

All-in-one container, and a licensing correction

richard-epsilla0ba0cb64d84f
diff --git a/.env.example b/.env.example
new file mode 100644
index 00000000..8f7e6f2e
--- /dev/null
+++ b/.env.example
@@ -0,0 +1,28 @@
+# ── Bring your own key ────────────────────────────────────────────────────────
+# Provider credentials are read from the environment at start-up and are NEVER written to
+# the image or to git. The secret store reads env before disk, so a key exported here is
+# used but not persisted.
+#
+# A connection is one JSON value naming a provider and its credential. Define at least one.
+
+# Anthropic — for the claude-code backend
+HR_SECRET_GLOBAL_HARNESS_CONN_ANTHROPIC={"name":"anthropic","provider":"anthropic","api_key":"sk-ant-REPLACE_ME"}
+
+# OpenAI — for the codex backend
+# HR_SECRET_GLOBAL_HARNESS_CONN_OPENAI={"name":"openai","provider":"openai","api_key":"sk-REPLACE_ME"}
+
+# Any OpenAI-compatible endpoint (aggregators, local models, self-hosted inference)
+# HR_SECRET_GLOBAL_HARNESS_CONN_CUSTOM={"name":"custom","provider":"openai-api","api_key":"REPLACE_ME","base_url":"https://api.example.com/v1"}
+
+# Which connection each backend uses by default.
+HR_SECRET_GLOBAL_HARNESS_POLICY_CLAUDE={"chain":["anthropic"]}
+# HR_SECRET_GLOBAL_HARNESS_POLICY_CODEX={"chain":["openai"]}
+# HR_SECRET_GLOBAL_HARNESS_POLICY_HERMES={"chain":["openai"]}
+
+# ── Optional ──────────────────────────────────────────────────────────────────
+# PORT=3000
+# HR_DATA_DIR=/data
+
+# Everything else is configured for self-hosting by the entrypoint: local SQLite storage,
+# no auth, no metering, a loopback runner, and direct key hand-off to the agent. You should
+# not need to set them, and they are documented in the README if you want to.
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 00000000..ca9db8d8
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,99 @@
+# HarnessRouter — self-hosted, all-in-one.
+#
+# One container runs the whole product: the UI, the gateway, and the agent runner. There is
+# no cloud dependency, no control plane to reach, and nothing to provision. State is SQLite
+# and files on one mounted volume.
+#
+# Why one container rather than compose-by-default: self-hosting should be `docker run`. The
+# three processes are supervised by a tiny entrypoint, and because the gateway talks to the
+# runner over loopback it needs no pool, no service discovery and no cloud identity.
+#
+# AGENT CLIs ARE INSTALLED ON FIRST RUN, NOT BAKED IN. This is a licensing requirement, not a
+# size optimisation: Claude Code ships under Anthropic's own terms ("SEE LICENSE IN README.md")
+# and hermes-agent declares no license at all, so neither may be redistributed inside a public
+# image. Installing them at first start means YOU install them, under their terms, exactly as
+# if you had run npm/pip yourself — and it keeps this image redistributable.
+#
+# They land in the data volume, so the cost is paid once per volume rather than once per start.
+# Choose backends at RUN time:
+#
+# docker run -e HR_BACKENDS=claude,codex,hermes ... # default: all three
+# docker run -e HR_BACKENDS=claude ... # lean
+#
+# WITH_BROWSER is still a build arg because Chromium and its system libraries genuinely belong
+# in the image layer.
+
+# ── UI build ──────────────────────────────────────────────────────────────────
+FROM node:20-slim AS ui
+WORKDIR /ui
+COPY ui/package.json ui/package-lock.json* ./
+RUN npm ci --no-audit --no-fund 2>/dev/null || npm install --no-audit --no-fund
+COPY ui/ ./
+ENV NEXT_TELEMETRY_DISABLED=1
+RUN npm run build
+
+# ── runtime ───────────────────────────────────────────────────────────────────
+FROM python:3.12-slim
+
+ARG WITH_BROWSER=0
+
+ENV DEBIAN_FRONTEND=noninteractive \
+ PYTHONUNBUFFERED=1 \
+ PIP_NO_CACHE_DIR=1 \
+ NEXT_TELEMETRY_DISABLED=1 \
+ HOME=/home/agent \
+ HARNESS_WORKSPACE=/workspace \
+ HR_DATA_DIR=/data
+
+RUN apt-get update -y && apt-get install -y --no-install-recommends \
+ curl ca-certificates git bash tini \
+ && rm -rf /var/lib/apt/lists/*
+
+# Node is needed for the UI server and for the npm-based agent CLIs.
+RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
+ && apt-get install -y --no-install-recommends nodejs \
+ && rm -rf /var/lib/apt/lists/* /root/.npm
+
+# Optional: browser automation for harnesses that verify their own output.
+RUN set -eux; \
+ if [ "$WITH_BROWSER" = "1" ]; then \
+ pip install --no-cache-dir playwright && playwright install --with-deps chromium; \
+ fi
+
+WORKDIR /app
+
+COPY gateway/requirements.txt /app/gateway/requirements.txt
+COPY runner/requirements.txt /app/runner/requirements.txt
+# The gateway's requirements include hosted-only clients (cloud identity, the hosted document
+# store). They are imported lazily and never touched self-hosted, so they are stripped here to
+# keep the image small and the dependency surface honest about what this build actually uses.
+RUN grep -viE "^(azure-|azure_)" /app/gateway/requirements.txt > /app/gateway/req.local.txt \
+ && pip install --no-cache-dir -r /app/gateway/req.local.txt \
+ && pip install --no-cache-dir -r /app/runner/requirements.txt
+
+COPY gateway/ /app/gateway/
+COPY runner/ /app/runner/
+COPY docker/entrypoint.sh /app/entrypoint.sh
+RUN chmod +x /app/entrypoint.sh
+
+# Next.js standalone output: server + only the modules it actually needs.
+COPY --from=ui /ui/.next/standalone /app/ui/
+COPY --from=ui /ui/.next/static /app/ui/.next/static
+COPY --from=ui /ui/public /app/ui/public
+
+# The agent CLIs refuse to run as root (they gate their own permission bypass on it), so the
+# runtime user is unprivileged and owns the workspace and data volume.
+RUN useradd -m -u 10001 agent \
+ && mkdir -p /workspace /data \
+ && chown -R agent:agent /workspace /data /app
+USER agent
+
+EXPOSE 3000
+VOLUME ["/data"]
+
+# The UI is the only published port. The gateway and runner stay on loopback — nothing else
+# needs to be reachable from outside the container.
+HEALTHCHECK --interval=30s --timeout=5s --start-period=40s \
+ CMD curl -fsS http://127.0.0.1:8080/healthz >/dev/null || exit 1
+
+ENTRYPOINT ["/usr/bin/tini", "--", "/app/entrypoint.sh"]
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 00000000..44b9c847
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2026 Epsilla
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 00000000..b5f57afb
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,42 @@
+HarnessRouter
+Copyright (c) 2026 Epsilla
+
+This product is licensed under the MIT License (see LICENSE).
+
+THIRD-PARTY DEPENDENCIES
+------------------------
+The published container image bundles the following third-party software. All are
+permissive licenses, and their notices are preserved here as those licenses require.
+
+ Python
+ FastAPI MIT
+ Uvicorn BSD-3-Clause
+ httpx BSD-3-Clause
+ Pydantic MIT
+ python-multipart Apache-2.0
+ aiohttp Apache-2.0
+ redis-py MIT
+ PyJWT MIT
+ PyYAML MIT
+
+ JavaScript
+ Next.js MIT
+ React / ReactDOM MIT
+ ReifyUI MIT
+ highlight.js BSD-3-Clause
+ Mermaid MIT
+ Apache ECharts Apache-2.0
+
+AGENT RUNTIMES — NOT REDISTRIBUTED
+----------------------------------
+The agent CLIs are deliberately NOT included in this image. They are installed on first
+run, by you, under their own licenses:
+
+ @anthropic-ai/claude-code Anthropic's own terms ("SEE LICENSE IN README.md")
+ @openai/codex Apache-2.0
+ hermes-agent no license declared by the publisher
+
+Because Claude Code is distributed under Anthropic's terms and hermes-agent declares no
+license, neither may be redistributed inside a public image. Installing them at first
+start keeps that decision — and its terms — with the operator. Review each tool's license
+before enabling its backend. Set HR_BACKENDS to control which are installed.
diff --git a/README.md b/README.md
new file mode 100644
index 00000000..6559d4ba
--- /dev/null
+++ b/README.md
@@ -0,0 +1,141 @@
+# HarnessRouter
+
+**Run agentic coding harnesses on your own machine.** One container, your own API keys, your
+own data. Configure a harness, give it work, watch it run — no account, no cloud, no telemetry.
+
+```bash
+cp .env.example .env # add your provider key
+docker compose up -d
+open http://localhost:3000
+```
+
+That's the whole install. State is SQLite and files on one Docker volume.
+
+---
+
+## What it is
+
+A *harness* is a configured agent: a backend runtime, a model, instructions, and limits. A
+*task* is one run of that harness — a real conversation against a real POSIX workspace with
+bash and git, streamed back as it happens.
+
+HarnessRouter gives you the full protocol for both: an OpenAI **Responses-compatible** API for
+running turns, harness CRUD, sessions, streaming, cancellation, and idempotency. The console is
+a thin client over that API — anything the UI does, you can do from `curl`.
+
+**Backends:** Claude Code, OpenAI Codex, and Hermes. They are installed on first run rather than
+shipped in the image — Claude Code is distributed under Anthropic's own terms and hermes-agent
+declares no license, so neither can be redistributed. Set `HR_BACKENDS` to choose which you want,
+and review each tool's license before enabling it.
+
+**Bring your own key.** Your provider credentials are read from the environment at start-up and
+handed to the agent directly. They are never written into the image, never committed, and never
+sent anywhere but your provider.
+
+## Why self-host
+
+- **Your keys, your bills, your data.** Nothing leaves the box except calls to your model provider.
+- **Real workspaces.** Agents get bash, git, and a filesystem — their native environment, not a
+ sandbox emulation.
+- **The same API as the hosted product.** Not a reduced fork: the same `/v1` surface, so anything
+ you build against it keeps working if you later move to the hosted service.
+- **Actually self-contained.** No control plane to phone home to, no managed database, no vault.
+
+## Configuration
+
+Everything is configured for self-hosting out of the box. The only thing you must supply is a
+provider key:
+
+```bash
+# .env
+HR_SECRET_GLOBAL_HARNESS_CONN_ANTHROPIC={"name":"anthropic","provider":"anthropic","api_key":"sk-ant-…"}
+HR_SECRET_GLOBAL_HARNESS_POLICY_CLAUDE={"chain":["anthropic"]}
+```
+
+A *connection* names a provider and its credential; a *policy* says which connection a backend
+uses. Any OpenAI-compatible endpoint works — aggregators, local models, or your own inference
+server — by setting `provider: "openai-api"` and a `base_url`.
+
+<details>
+<summary>Choosing backends, and building with a browser</summary>
+
+Backends are chosen at run time, because they are installed into your data volume rather than
+baked into the image:
+
+```bash
+docker run -e HR_BACKENDS=claude,codex,hermes ... # default
+docker run -e HR_BACKENDS=claude ... # just Claude Code
+```
+
+The first start installs them (once per volume). Chromium is genuinely an image layer, so it
+stays a build flag:
+
+```bash
+docker build -t harnessrouter --build-arg WITH_BROWSER=1 .
+```
+</details>
+
+<details>
+<summary>What the entrypoint sets for you</summary>
+
+| Variable | Default | Why |
+|---|---|---|
+| `HR_BACKING` | `local` | SQLite + files on `/data`. No external storage. |
+| `HR_IDENTITY_MODE` | `off` | Single-tenant box; login would be ceremony with nothing behind it. |
+| `HR_CREDIT_GATE` | `off` | Metering is a hosted concern. |
+| `POOL_MGMT_ENDPOINT` | `http://127.0.0.1:8081` | The runner is in this container. |
+| `HR_POOL_AUTH` | `none` | No cloud identity to present to a loopback runner. |
+| `HR_SANDBOX_TRUST` | `owner` | You own the box, the agent and the key, so the key is handed over directly rather than brokered. |
+| `HARNESS_INTERNAL_KEY` | generated | Per-container; never leaves the process tree. |
+
+</details>
+
+## Using the API
+
+The console is optional. The gateway speaks the Responses API:
+
+```bash
+curl http://localhost:3000/api/gw/v1/responses \
+ -H 'content-type: application/json' \
+ -H 'x-harness-org: local' \
+ -d '{"input":"List the files and summarise this repo",
+ "metadata":{"harness_id":"YOUR_HARNESS_ID"},
+ "stream":true}'
+```
+
+Harness CRUD (`/v1/harnesses`), the model catalog (`/v1/models`), sessions
+(`/v1/sessions/{id}/turns`, `/cancel`) and task listing (`/v1/traces`) are all available on the
+same surface.
+
+## Moving to the hosted service
+
+When a harness is working the way you want, **Harnesses → Push to cloud** copies it into a
+hosted HarnessRouter account with your hosted API key.
+
+This is deliberately one-way. Local is where you iterate; once promoted, the hosted copy is the
+source of truth. There is no "pull from cloud", so a harness can never be live in two places
+each claiming to be current. Your hosted key is used for that one request and is never stored.
+
+## Architecture
+
+```
+┌─ container ────────────────────────────────────────────┐
+│ UI (Next.js) :3000 ← the only published port │
+│ │ same-origin proxy │
+│ Gateway :8080 Responses API, harness CRUD │
+│ │ loopback │
+│ Runner :8081 spawns the agent CLI on /workspace│
+└────────────────────────┬───────────────────────────────┘
+ /data (volume): SQLite, blobs, secrets
+```
+
+Storage sits behind a small adapter interface (graph / blob / secret). This repo ships the local
+implementations; the hosted deployment overlays its own against the same interface. That seam is
+why this is genuinely the same codebase rather than a fork that drifts.
+
+## License
+
+MIT — see [LICENSE](LICENSE). Third-party notices are in [NOTICE](NOTICE).
+
+The agent CLIs are **not** redistributed here; they are installed on first run under their own
+licenses. Review them before enabling a backend.
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 00000000..934626bc
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,23 @@
+# Self-hosted HarnessRouter.
+#
+# 1. cp .env.example .env and put YOUR provider key in it
+# 2. docker compose up -d
+# 3. open http://localhost:3000
+#
+# One container, one volume. No external services.
+services:
+ harnessrouter:
+ image: harnessrouter/harnessrouter:latest
+ # Use this instead of `image:` to build locally:
+ # build: .
+ ports:
+ - "3000:3000"
+ env_file:
+ - .env
+ volumes:
+ # Everything durable lives here: SQLite databases, blobs, and the secret store.
+ - harnessrouter-data:/data
+ restart: unless-stopped
+
+volumes:
+ harnessrouter-data:
diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh
new file mode 100644
index 00000000..813d2809
--- /dev/null
+++ b/docker/entrypoint.sh
@@ -0,0 +1,125 @@
+#!/usr/bin/env bash
+# Start the three processes and keep them honest.
+#
+# If any one of them dies the container exits, rather than limping along serving a UI whose
+# backend is gone — a half-dead container that still passes a TCP check is worse than one
+# that restarts. `docker run --restart` then does the recovering.
+set -euo pipefail
+
+DATA_DIR="${HR_DATA_DIR:-/data}"
+mkdir -p "$DATA_DIR"
+
+# ── configuration: self-contained defaults ────────────────────────────────────
+# Local storage: SQLite + files on the mounted volume. No external services.
+export HR_BACKING="${HR_BACKING:-local}"
+export HR_DATA_DIR="$DATA_DIR"
+
+# No auth: single-tenant box, identity is a constant supplied by the UI.
+export HR_IDENTITY_MODE="${HR_IDENTITY_MODE:-off}"
+
+# No billing or metering: these are hosted concerns and no-op when their URLs are unset.
+export HR_CREDIT_GATE="${HR_CREDIT_GATE:-off}"
+
+# The runner is right here, so there is no pool to authenticate to.
+export POOL_MGMT_ENDPOINT="${POOL_MGMT_ENDPOINT:-http://127.0.0.1:8081}"
+export HR_POOL_AUTH="${HR_POOL_AUTH:-none}"
+
+# Bring your own key: the operator owns the box, the agent and the key, so the key is handed
+# to the runner directly instead of being brokered. See _auth_from_conn in gateway/app.py for
+# why this is an explicit mode and never a fallback.
+export HR_SANDBOX_TRUST="${HR_SANDBOX_TRUST:-owner}"
+
+# The gateway signs its own internal calls. Generated per container if not supplied, so a
+# default install has no shared secret and nothing to leak; it never leaves this process tree.
+if [ -z "${HARNESS_INTERNAL_KEY:-}" ]; then
+ export HARNESS_INTERNAL_KEY="$(python3 -c 'import secrets; print(secrets.token_hex(32))')"
+fi
+
+export GATEWAY_URL="${GATEWAY_URL:-http://127.0.0.1:8080}"
+export PORT="${PORT:-3000}"
+
+# ── agent CLIs: installed here, not shipped in the image ──────────────────────
+# Claude Code is distributed under Anthropic's own terms and hermes-agent declares no license,
+# so neither can be redistributed inside a public image. Installing them on first run means the
+# operator installs them under those terms, and the image stays redistributable.
+#
+# They go in the data volume, so this is once per volume rather than once per start. A failure
+# to install one backend is not fatal: the others still work, and the gateway's catalog is what
+# the UI offers, so an unavailable backend simply isn't listed.
+TOOLS="$DATA_DIR/agent-tools"
+export PATH="$TOOLS/bin:$PATH"
+export NODE_PATH="$TOOLS/lib/node_modules"
+export HR_BACKENDS="${HR_BACKENDS:-claude,codex,hermes}"
+
+install_backends() {
+ mkdir -p "$TOOLS"
+ local want="$HR_BACKENDS"
+
+ if [[ ",$want," == *",claude,"* ]] && [ ! -x "$TOOLS/bin/claude" ]; then
+ echo "[harnessrouter] installing Claude Code (Anthropic's terms apply)…"
+ npm install --prefix "$TOOLS" --global-style --no-audit --no-fund \
+ @anthropic-ai/claude-code >/dev/null 2>&1 \
+ || echo "[harnessrouter] WARN: Claude Code install failed — that backend is unavailable"
+ fi
+
+ if [[ ",$want," == *",codex,"* ]] && [ ! -x "$TOOLS/bin/codex" ]; then
+ echo "[harnessrouter] installing Codex (Apache-2.0)…"
+ npm install --prefix "$TOOLS" --global-style --no-audit --no-fund \
+ @openai/codex >/dev/null 2>&1 \
+ || echo "[harnessrouter] WARN: Codex install failed — that backend is unavailable"
+ fi
+
+ if [[ ",$want," == *",hermes,"* ]] && [ ! -x "$TOOLS/venv/bin/hermes" ]; then
+ echo "[harnessrouter] installing Hermes (check its upstream license before use)…"
+ python3 -m venv "$TOOLS/venv" >/dev/null 2>&1 \
+ && "$TOOLS/venv/bin/pip" install --no-cache-dir -q \
+ "hermes-agent==0.19.0" anthropic mcp >/dev/null 2>&1 \
+ || echo "[harnessrouter] WARN: Hermes install failed — that backend is unavailable"
+ fi
+ [ -d "$TOOLS/venv/bin" ] && export PATH="$TOOLS/venv/bin:$PATH"
+ # Hermes otherwise tries to install its own dependencies mid-turn.
+ export HERMES_DISABLE_LAZY_INSTALLS=1
+}
+
+install_backends
+
+pids=()
+cleanup() { trap - TERM INT; for p in "${pids[@]:-}"; do kill "$p" 2>/dev/null || true; done; }
+trap cleanup TERM INT EXIT
+
+avail=""
+for b in claude codex hermes; do
+ case "$b" in
+ claude) [ -x "$TOOLS/bin/claude" ] && avail="$avail claude" ;;
+ codex) [ -x "$TOOLS/bin/codex" ] && avail="$avail codex" ;;
+ hermes) [ -x "$TOOLS/venv/bin/hermes" ] && avail="$avail hermes" ;;
+ esac
+done
+echo "[harnessrouter] data=$DATA_DIR backends available:${avail:- none}"
+
+# runner (loopback only)
+( cd /app/runner && exec python3 -m uvicorn server:app --host 127.0.0.1 --port 8081 --log-level warning ) &
+pids+=($!)
+
+# gateway (loopback only)
+( cd /app/gateway && exec python3 -m uvicorn app:app --host 127.0.0.1 --port 8080 --log-level warning ) &
+pids+=($!)
+
+# Wait for the gateway before the UI starts serving, so a first page load never races a
+# backend that is still binding.
+for _ in $(seq 1 60); do
+ curl -fsS "http://127.0.0.1:8080/healthz" >/dev/null 2>&1 && break
+ sleep 1
+done
+
+# UI (the only published port)
+( cd /app/ui && exec node server.js ) &
+pids+=($!)
+
+echo "[harnessrouter] ready on :$PORT"
+
+# Exit as soon as ANY child exits, carrying its status out to the restart policy.
+wait -n "${pids[@]}"
+status=$?
+echo "[harnessrouter] a process exited (status $status) — shutting down"
+exit "$status"