Claude Code harness authentication environment variables
By default, authentication is resolved from the host environment and forwarded to the sandbox bridge. The adapter checks for AI Gateway and Anthropic credentials. Supported environment variables are: VERCEL_OIDC_TOKEN, AI_GATEWAY_API_KEY, AI_GATEWAY_BASE_URL, ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN, and ANTHROPIC_BASE_URL.
Claude Code harness setup packages
The Claude Code harness adapter requires three packages: @ai-sdk/harness, @ai-sdk/harness-claude-code, and @ai-sdk/sandbox-vercel. The adapter bootstraps the Claude Code bridge dependencies inside the sandbox when the first session starts.
Claude Code harness imports
Import claudeCode and createClaudeCode from @ai-sdk/harness-claude-code. The claudeCode export is equivalent to createClaudeCode() with its default configuration.
Claude Code harness basic usage example
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],
}),
});
const session = await agent.createSession();
let exitCode = 0;
try {
const result = await agent.stream({
session,
prompt: 'Check the test failures and fix the production code.',
});
for await (const part of result.stream) {
if (part.type === 'text-delta') {
process.stdout.write(part.text);
}
}
} catch (err) {
exitCode = 1;
console.error(err);
} finally {
await session.destroy();
process.exit(exitCode);
}
Claude Code harness configuration with createClaudeCode
The createClaudeCode() function configures the Claude Code runtime with the following settings: model (Anthropic model id passed to the underlying Claude Code runtime), maxTurns (maximum internal turns before yielding), env (environment variables for the Claude Code process that merge over the sandbox bridge process environment and take precedence), thinking (extended-thinking configuration with type: 'enabled'|'disabled'|'adaptive' and display: 'summarized'|'omitted', defaults to {type: 'adaptive', display: 'summarized'}), port (bridge port override), and startupTimeoutMs (maximum time to wait for the bridge to start). Additionally, auth can be provided for direct Anthropic or AI Gateway authentication settings.
Claude Code harness createClaudeCode configuration example
const harness = createClaudeCode({
model: 'claude-sonnet-4-6',
maxTurns: 10,
env: {
DEPLOYMENT_ENV: 'staging',
},
thinking: {
type: 'adaptive',
display: 'summarized',
},
});
Claude Code harness explicit authentication configuration
const harness = createClaudeCode({
auth: {
gateway: {
apiKey: process.env.AI_GATEWAY_API_KEY,
},
},
});
Claude Code harness sandbox requirements
Claude Code requires a network sandbox with at least one exposed port. The example uses @ai-sdk/sandbox-vercel with runtime 'node24' and ports [4000].
Claude Code harness built-in tools
The adapter exposes these common Claude Code built-ins through agent.tools: read, write, edit, bash, glob, grep, and webSearch. Additional Claude Code built-ins may also appear in agent.tools when they do not fit a common tool shape. Claude Code supports built-in tool approval requests when permissionMode is 'allow-reads' or 'allow-edits'.
Claude Code harness is experimental
Harness packages are experimental. Expect breaking changes between releases as this early API gets further refined.
AI SDK Harnesses overview
AI SDK harness adapters connect HarnessAgent to established agent runtimes. They are separate from model providers but expose AI SDK-compatible stream and response primitives.
Available harness adapters
The AI SDK harness system provides adapters for: Claude Code, Codex, Grok Build, OpenCode, Pi, and Agent Client Protocol (ACP). ACP is compatible with any ACP-compatible harness.
HarnessAgent usage example
HarnessAgent is instantiated with a harness configuration and sandbox. Example: import { HarnessAgent } from '@ai-sdk/harness/agent'; import { codex } from '@ai-sdk/harness-codex'; import { createVercelSandbox } from '@ai-sdk/sandbox-vercel'; const agent = new HarnessAgent({ harness: codex, sandbox: createVercelSandbox({ runtime: 'node24', ports: [4000], }), });
HarnessAgent constructor parameters
HarnessAgent accepts an object with harness and sandbox properties. The harness property specifies which agent runtime to use. The sandbox property configures the execution environment with options like runtime and ports.