Open source  /  Implementation guide

Open-source implementation · Agentic harnesses

Run coding and ops agents on open source

What this is. A build-it-yourself path to the same outcome, made from open-source parts you host. It does not publish 5 Kings’ internal method, client data, or any third party’s confidential information — and it says plainly where the open-source path is weaker than a specialist service.

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.

LayerOpen-source projectLicenceWhat it does for you
Harness (CLI/agent loop)AiderApache-2.0Repo-aware editing with git-native diffs and a small, auditable surface. Good default for code changes.
Harness (general agent)OpenHandsMITA sandboxed agent that can run commands, browse and edit; the container is the security boundary.
Harness (framework)LangGraphMITExplicit state machines for multi-step agents, so a loop has named states and a checkpoint you can resume.
Model accessLiteLLM gateway + OllamaMITPer-run budgets and local model fallback, so an agent cannot spend without a ceiling.
SandboxDocker / Podman with a read-only rootApache-2.0No host socket, no ambient env, a mounted workspace and an egress allowlist.
Tool surfaceMCP servers (filesystem, git, fetch)MITExplicit, scoped tools instead of a general shell wherever the task allows it.
Trace + costLangfuseMIT (core)One trace per run: prompts, tool calls, file writes, tokens, cost, duration.
CI gateGitHub Actions or Gitea Actions + your test suiteMITThe 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 checkHow to verify it
The runtime has no ambient credentialsList the environment inside the container; only the gateway key and a scoped git token.
Egress is limited to the allowlistAttempt a request to a non-allowed host from inside the container; expect a refusal.
Every run has a trace and a costRun count vs trace count; both must match for the same window.
Step, time and token caps are enforcedSet a cap of 10 steps in staging and confirm the run stops at 10.
No agent commit reaches a protected branch without green CIBranch protection rule verified by attempting a direct push.
A run can be reconstructed from its tracePick a completed run and answer: prompts, files read, files written, cost — from the trace alone.

Effort and cost

Estimate
Skill neededAdvanced: containers, git, and enough LLM experience to distinguish a bad prompt from a bad loop
Build time1–2 days for a working harness in a sandbox, 1 week for the CI gate and trace discipline
Running costModel tokens dominate; a laptop GPU or a local model keeps it near zero at low volume
What you must hostA 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.

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

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.

PDF · A4 · no email required · free to redistribute with attribution

Open-source Guides & PDFs