Skip to content

Caveman Agent SDK· Open sourceAgent SDK & Harness v4

Harness v4 Engine: Loadouts, Code-Mode MCP, and Environments

Embed @caveman-ai/harness directly: model-native loadouts (app-gpt, app-claude, app-code, app-general), QuickJS with_mcp code mode, byte-stable cache prefixes, and Local/Docker/Sandbox environments.

@caveman-ai/harness (also re-exported from @caveman-ai/agent/harness) is the open-source agent engine underneath @caveman-ai/agent and Caveman Code. It matches tool surfaces to each model family, preserves byte-stable prompt prefixes across turns, isolates subprocess credentials (inheritEnv: false), and exits with stable codes when parked.

Install and run a session#

npm install @caveman-ai/agent
import { tool } from "@caveman-ai/agent";
import {
HarnessSession,
LocalEnv,
appLoadoutFor,
resolveHarnessModel,
toHarnessTool,
} from "@caveman-ai/agent/harness";

const { model, stream } = resolveHarnessModel("anthropic/claude-sonnet-4-6");

const recordFinding = tool(
"record_finding",
"Record a finding from workspace inspection.",
{ type: "object", properties: { note: { type: "string" } }, required: ["note"] },
async ({ note }: { note: string }) => ({ recorded: true, note }),
);

const session = new HarnessSession({
model,
stream,
loadout: appLoadoutFor(model),
env: new LocalEnv({ cwd: process.cwd() }),
tools: [toHarnessTool(recordFinding)],
});

try {
const outcome = await session.runTurn("Inspect this repo and record one key finding.", {
onEvent: (event) => {
if (event.type === "text_delta") process.stdout.write(event.delta);
},
});
console.log(outcome.finalText, outcome.usage);
} finally {
await session.close();
}

Model-native loadouts#

A loadout defines the exact prompt sections, tool schemas, limits, and wire flags sent to a model. Every loadout hashes canonically (normalizeLoadout() + loadoutHash()), so benchmarked configurations match production byte for byte.

LoadoutExecution environmentBuilt-in toolsBest for
app-generalNone (computer: "none")User-declared host tools & MCP onlySupport, triage, structured extraction, non-coding workflows
app-codeIn-process QuickJSprogram over declared toolsTool-heavy workflows composing calls in code without a Linux shell
app-claudeLocalEnv, DockerEnv, or SandboxEnvCompact 5-tool surface (read, bash, wait, fuzzy edit, write, compact) + 270 s cache keepaliveCoding tasks targeting Claude models
app-gptLocalEnv, DockerEnv, or SandboxEnvCodex exec QuickJS surface (exec_command, apply_patch, write_stdin, wait, view_image, compact)Coding tasks targeting OpenAI Responses API models

Cache-stable prefix contract & QuickJS code-mode MCP#

  • Deterministic ordering. Built-in, custom, and MCP tools serialize in a fixed order so earlier prefix bytes never shift between turns.
  • 270 s Anthropic cache keepalive. Keeps warm prompt caches alive across long-running tool pauses.
  • QuickJS code-mode MCP (with_mcp). Attached MCP servers run inside a sandboxed QuickJS WASM cell with compact one-line tool signatures and ask() fan-out, loaded only when MCP servers are connected (connectMcp() / mcpDirectTools()).
  • Explicit compaction. The compact tool writes a clean handoff frame rather than mutating earlier cached history.

Published Harness v4 benchmark results#

Each optimization in Harness v4 was evaluated on held-out paired tasks (caveman-ai/agent-sdk README). Local cost figures are inferred, not invoice promises:

BenchmarkMeasured resultScope
Lean Harness vs Pi 1.331% lower $/solve (0.69x, 95% CI 0.59-0.79) at equal 0.584 pass@173 held-out DeepSWE + Terminal-Bench 4 tasks, k=3
QuickJS code-mode MCP (with_mcp)0.33x direct MCP / 0.29x Claude Code on Opus; 0.67x direct / 0.59x Codex on SolConnector benchmark suite at equal task passes
Anthropic 270 s cache keepalive-6.4% cost/attempt; cache misses dropped 0.50 -> 0 per trialo20 Anthropic cache-expiry benchmark

Execution environments (LocalEnv, DockerEnv, SandboxEnv)#

Every environment implements the same ExecEnv interface so the same agent runs locally, in Docker, or on Caveman Cloud without changing agent code:

ClassIsolationCredential handling
LocalEnvHost process groups (Git Bash on Windows)Explicit allowlist (inheritEnv: false): PATH, HOME, USER, LANG plus variables you pass; strips ambient provider keys
DockerEnvLocal container (docker exec)Container boundary with mounted workspace
SandboxEnvCaveman Cloud Firecracker microVMLazily provisioned on first tool call; API keys stay in the host harness process and never enter the VM
import { SandboxEnv } from "@caveman-ai/harness";

const env = new SandboxEnv({
controlURL: "https://api.caveman.so",
apiKey: process.env.CAVEMAN_API_KEY!,
cwd: "/workspace",
});

Headless exit codes#

When driven as a headless subprocess (caveman-harness), exit codes tell schedulers when to reclaim compute:

Exit codeMeaning
0Turn completed normally
1Unrecoverable error
2Invalid arguments or configuration
3Budget or turn limit reached
4Cancelled by caller
5Parked waiting for approval, external tool result, or timer
6Idle between turns; safe to hibernate and resume from event log
Esc

Start here