AI SDK HarnessAgent

AI SDK 7 unifies established agent harnesses behind one TypeScript API — swap Claude Code, Codex, Deep Agents, OpenCode, or Pi like you swap models, with sandboxed sessions and AI SDK-compatible streams.

Vercel shipped HarnessAgent on 2026-06-12 as an experimental canary API. The thesis: the AI SDK already made models swappable; harnesses manage everything above a model call (skills, sandboxes, sessions, permissions, compaction, sub-agents, runtime config) — and should be swappable the same way. Source: Vercel changelog, https://vercel.com/changelog/program-agent-harnesses-with-ai-sdk, 2026-06-12

What it is

Two abstractions, decoupled:

Layer Exposes AI SDK entrypoints
Providers / models LLM APIs generateText, streamText, generateObject, …
Harnesses Full agent runtimes HarnessAgent

A harness is a complete agent runtime — not a thin wrapper around one model call. It owns workspace access, built-in coding tools, native session state, compaction, permission flows, and harness-specific configuration. Every harness run operates inside a sandbox so the host environment stays safe. Source: AI SDK docs, https://ai-sdk.dev/v7/docs/ai-sdk-harnesses/overview, 2026-06-12

HarnessAgent.generate() and .stream() return standard AI SDK result types (GenerateTextResult, StreamTextResult). Apps using useChat or related UI tooling can consume harness streams without rewriting the UI layer — including toUIMessageStream for chat surfaces. Source: Vercel changelog, 2026-06-12

Install

npm i ai @ai-sdk/harness @ai-sdk/sandbox-vercel

Package split (experimental - expect breaking changes):

Package Role
@ai-sdk/harness HarnessAgent class; 1.0.18 latest as of 2026-07-04
@ai-sdk/harness-claude-code Claude Code adapter; 1.0.18 latest
@ai-sdk/harness-codex Codex adapter; 1.0.19 latest
@ai-sdk/harness-pi Pi adapter; 1.0.18 latest
@ai-sdk/sandbox-vercel createVercelSandbox(); 1.0.18 latest

Docs: AI SDK harnesses overview

Minimal usage

import { HarnessAgent } from '@ai-sdk/harness/agent';
import { claudeCode } from '@ai-sdk/harness-claude-code';
import { createVercelSandbox } from '@ai-sdk/sandbox-vercel';

const agent = new HarnessAgent({
  harness: claudeCode,
  sandbox: createVercelSandbox({ runtime: 'node24', ports: [4000] }),
  tools: { /* custom AI SDK tools */ },
  skills: [ /* custom skills */ ],
});

const session = await agent.createSession();
try {
  const result = await agent.stream({
    session,
    prompt: 'Check the test failures and fix the production code.',
  });
  for await (const part of result.fullStream) {
    if (part.type === 'text-delta') process.stdout.write(part.text);
  }
} finally {
  await session.destroy();
}

Swap claudeCode for codex, deepAgents, openCode, or pi — same HarnessAgent flow. Source: Vercel changelog, 2026-06-12; Vercel changelog, 2026-06-25

Deep Agents And OpenCode

On 2026-06-25, Vercel added two harness adapters:

  • @ai-sdk/harness-deepagents adapts LangChain's deepagents runtime, including file and shell tools, skills, host tools, multi-turn sessions, attach/resume, and built-in tool approvals.
  • @ai-sdk/harness-opencode boots an OpenCode server inside the sandbox via @opencode-ai/sdk, streams session events through the harness, exposes OpenCode tools, supports built-in and host tool approvals, and lets the app choose model, provider, and reasoning variant.

The supported harness set is now Claude Code, Codex, Deep Agents, OpenCode, and Pi. Current package snapshot as of 2026-07-04: @ai-sdk/harness@1.0.18, @ai-sdk/harness-deepagents@1.0.17, and @ai-sdk/harness-opencode@1.0.18, each on the latest dist-tag; snapshot/canary channels also exist, so check the exact package before coding against adapter config. Source: Vercel changelog, 2026-06-25; Source: npm registry via npm view, 2026-07-04

Core concepts

  • HarnessAgent — application-facing agent; accepts custom instructions, skills, AI SDK tools, permission settings, sandbox hooks, adapter-specific config while preserving native harness behavior.
  • Harness adapter — connects to a runtime (@ai-sdk/harness-claude-code, etc.).
  • Sandbox provider — isolated filesystem + process environment (createVercelSandbox).
  • Session — live conversation + workspace state; create before turns, destroy() when done. Server routes can persist resume state via session.detach() / session.stop() with a stable sessionId. Source: AI SDK docs, https://ai-sdk.dev/v7/docs/ai-sdk-harnesses/overview, 2026-06-12

When to use a harness vs a model loop

Use a harness when an existing runtime should drive the task:

  • Coding agents inspecting/modifying a sandboxed workspace
  • Runtimes with built-in tools and permission models (Claude Code Harness, Codex Harness (OpenAI))
  • Multi-turn sessions where the runtime owns conversation history and compaction
  • Workflows that should preserve native harness behavior instead of re-implementing a tool loop

Use providers/models when you need direct control over the tool loop, model settings, structured output, or a custom agent architecture (AI SDK 5 Agent, stopWhen, prepareStep). Source: AI SDK docs, 2026-06-12

Stream compatibility

Harness events project into AI SDK stream parts where possible: text, reasoning, tool calls/results, usage, finish reasons. Events without first-class AI SDK parts (workspace file changes, compaction) surface as dynamic provider-executed tool parts. Source: AI SDK docs, 2026-06-12

Stack fit

  • Parent toolkit: Vercel AI SDK (AI SDK 7 canary).
  • Harness pages: Claude Code Harness, Codex Harness (OpenAI) — adapters wrap these runtimes; Cursor Harness not in initial adapter set ("more coming soon").
  • Sandboxes: ties to Agent Sandboxes framing; Vercel Sandbox via @ai-sdk/sandbox-vercel (see also Browser Testing Skills skill for microVM browser automation).
  • Kevin projects on AI SDK (Loop, Lumachor) can embed harness-backed coding agents without bespoke integration per harness vendor.
  • Community analog over the open Agent Client Protocol: Spawn Agent (Aiden Bai) exposes 8 local coding agents as AI SDK providers — same "embed any agent" goal, different lineage (ACP vs first-party adapters).

Status

Experimental. Vercel explicitly welcomes feedback while the API stabilizes. Do not treat adapter package names or config shapes as frozen until GA. Source: Vercel changelog, 2026-06-12


Timeline