In one paragraph
An agent harness is the loop around a model: tools, permissions, context, and a place to run. The open-source options are real and they are good — the part that needs engineering is the safety envelope, not the loop. This guide builds a harness you can hand a repository to without losing sleep.
What you end up with
- A containerised agent runtime with a defined tool surface and no ambient credentials
- Model access through a gateway, so cost and provider are visible per run
- A review gate: every agent change arrives as a diff with a test result attached
- A trace of what the agent read, wrote and spent, for any run you need to explain
The reference stack
Every project below is open source and self-hostable. Licences are the ones the project publishes today; check them against your own distribution model before you ship, because a licence can change and an AGPL project has obligations a MIT project does not.
| Layer | Open-source project | Licence | What it does for you |
|---|---|---|---|
| Harness (CLI/agent loop) | Aider | Apache-2.0 | Repo-aware editing with git-native diffs and a small, auditable surface. Good default for code changes. |
| Harness (general agent) | OpenHands | MIT | A sandboxed agent that can run commands, browse and edit; the container is the security boundary. |
| Harness (framework) | LangGraph | MIT | Explicit state machines for multi-step agents, so a loop has named states and a checkpoint you can resume. |
| Model access | LiteLLM gateway + Ollama | MIT | Per-run budgets and local model fallback, so an agent cannot spend without a ceiling. |
| Sandbox | Docker / Podman with a read-only root | Apache-2.0 | No host socket, no ambient env, a mounted workspace and an egress allowlist. |
| Tool surface | MCP servers (filesystem, git, fetch) | MIT | Explicit, scoped tools instead of a general shell wherever the task allows it. |
| Trace + cost | Langfuse | MIT (core) | One trace per run: prompts, tool calls, file writes, tokens, cost, duration. |
| CI gate | GitHub Actions or Gitea Actions + your test suite | MIT | The agent proposes; CI decides. No agent push reaches a protected branch without a green suite. |
Build it
1. Start with the envelope, not the prompt
Decide what the agent may touch before you decide what it should do: which directories, which commands, which network destinations, which credentials. Write it as a container spec. A prompt-level instruction is not a control.
# agent sandbox (excerpt)
docker run --rm -it
--read-only --tmpfs /tmp
--cap-drop ALL --security-opt no-new-privileges
-v "$PWD/repo:/work:rw" -w /work
--network agent-egress
agent-runtime:latest
2. Give it a repository, not a filesystem
Mount one repository at one path. An agent with a home directory mount will eventually read a credential file, not out of malice but because it was looking for config. Scope is a design decision that costs nothing at the start and everything later.
3. Route model calls through the gateway
Per-run key, per-run budget, model allowlist. When a run costs ten times the expected amount, you want the spend log to say which step, not a monthly invoice surprise.
4. Make the diff the unit of output
An agent run produces a branch, a commit series and a test result. Not a summary of what it thinks it did. Review the diff the way you would review a junior engineer’s pull request — because that is what it is.
5. Trace and keep the trace
One trace per run with every tool call. When an agent breaks something, the trace is the incident report. Store it somewhere the whole team can read, and put the run id in the commit message.
6. Cap the loop
Maximum steps, maximum wall time, maximum tokens, maximum files changed. Four numbers, enforced by the runtime, not the prompt. Most agent disasters are an uncapped loop doing something reasonable 200 times.
7. Rotate the tool surface as you learn
Start with read-only tools plus a write to one directory. Add capabilities only when a specific task needs them, and record which run needed which tool. The tool list is the attack surface; treat expansion as a reviewed change.
Acceptance checks
If you cannot verify a claim, it is not a finding. These are the checks that close the work; each one can be run by somebody who did not build it.
| Acceptance check | How to verify it |
|---|---|
| The runtime has no ambient credentials | List the environment inside the container; only the gateway key and a scoped git token. |
| Egress is limited to the allowlist | Attempt a request to a non-allowed host from inside the container; expect a refusal. |
| Every run has a trace and a cost | Run count vs trace count; both must match for the same window. |
| Step, time and token caps are enforced | Set a cap of 10 steps in staging and confirm the run stops at 10. |
| No agent commit reaches a protected branch without green CI | Branch protection rule verified by attempting a direct push. |
| A run can be reconstructed from its trace | Pick a completed run and answer: prompts, files read, files written, cost — from the trace alone. |
Effort and cost
| Estimate | |
|---|---|
| Skill needed | Advanced: containers, git, and enough LLM experience to distinguish a bad prompt from a bad loop |
| Build time | 1–2 days for a working harness in a sandbox, 1 week for the CI gate and trace discipline |
| Running cost | Model tokens dominate; a laptop GPU or a local model keeps it near zero at low volume |
| What you must host | A workstation or a 16 GB VM; a GPU helps a lot for local models. |
What open source does not give you
The honest half of the comparison. Each of these is a reason somebody buys the service instead of building it, and pretending otherwise would make the rest of this page worthless.
- Agent quality is dominated by the model and the repository’s own test coverage. A repo with no tests gives the agent no feedback loop and produces confident, broken changes.
- Sandboxing reduces blast radius; it does not eliminate prompt injection. An agent that reads untrusted web content can still be steered, so keep high-impact tools out of reach for those runs.
- Local models handle single-file edits acceptably and multi-file refactors poorly. Expect to spend the difference in review time.
- The harness ecosystem changes monthly. Pin versions and budget migration work — a config from six months ago may not run.
- No harness removes the need for a reviewer who understands the codebase.
What the service adds
Scope only, stated so you can compare it with the build above.
- The safety envelope designed against your actual repositories and secrets, not a generic template
- A review gate wired into your CI with the checks your team already trusts
- Harness selection and configuration for the specific task mix — coding, ops, or content
Sources and further reading
Related guides
What this page does not include. This guide documents an open-source implementation of the same outcome. It deliberately leaves out 5 Kings’ internal playbooks, client data, vendor terms and unpublished method: we publish what any competent team can reproduce, and we do not publish what belongs to a client or to a contract. Where a step depends on a decision only your business can make, the guide says so instead of guessing.
Take it with you
Run coding and ops agents on open source
The full guide as an A4 PDF: the reference stack with licences, the build steps, the acceptance checks and the honest limits — in one file you can hand to an engineer or print for a planning session.