feat(ai-sandbox, ai-harness): delegate to Claude Code, Codex, and other coding agents from a harness #1538
feat/harness-p8-code-mode fromfeat/harness-p9-coding-agents·opened View on GitHubAdd codingAgents(...) to a harness, and the lead model can hand coding work to Claude Code, Codex, Grok Build, or any ACP agent. Each agent works in a sandbox, keeps its own session per thread (also after a restart), and its tool calls show up in the CLI, ACP editors, and the dashboard.
Stacked on #1524 (Phase 8) → #1523 → #1522 → #1521 → #1520 → #1519 → #1518 → #1515 → #1513 → #1509. Merge those first.
🎯 Changes#
codingAgents({ sandbox, agents, workspace? })at@tanstack/ai-sandbox/harness: one tool per agent. Each call runsctx.chatwithwithSandbox, so nobody wires the sandbox by hand.- Sessions: the plugin saves the
<adapter>.session-idevent per thread and agent, and passes it back asmodelOptions.sessionId./fresh [agent]starts over. - Workspaces:
'shared'(default) is one sandbox per thread, one agent at a time.'per-agent'gives each agent its own sandbox. - Plan mode: the harness
planmode starts Claude Code withpermissionMode: 'plan'and Codex withsandboxMode: 'read-only'. Other agents useplanModelOptions. @tanstack/ai-harness: plugins can contributesubagents, agents the model can call as tools.- Child work is visible: the CLI shows child tool calls and a finish line, ACP gets child tool calls, and the dashboard shows a block per child.
examples/harness-cli:CODING_AGENTS=1adds Claude Code and Codex in./playgroundwith the hostclaude loginandcodex login.- Docs:
docs/harness/coding-agents.md(new), plusplugins.mdandcoding-agent.md. Changeset: ai-sandbox, ai-harness, ai-harness-cli, ai-acp, ai-dashboard (minor).
✅ Checklist#
- I have followed the steps in the Contributing guide.
- I have tested code changes locally with
pnpm run test:pr, or these tests do not apply to this pull request. - I fully understand the code in this pull request, including any code generated with AI assistance.
- Docs: I updated
docs/for this change, or this change is not user-facing. - Changeset: I added a changeset (
pnpm changeset), or this PR does not change a published package.
🚀 Release Impact#
- This change affects published code, and I have generated a changeset.
- This change is docs/CI/dev-only (no release).
Testing#
Commands run (not the full pnpm test:pr, see below):
vitest run: ai-harness (156), ai-sandbox (985, 3 skipped), ai-harness-cli (20), ai-acp (68), ai-dashboard (4). All pass.test:typesfor the same five packages andtsc --noEmitforexamples/harness-cli.publint --strictfor@tanstack/ai-sandbox,kiira checkfor the three docs pages,oxfmtandoxlinton the changed files,test:sherif.- Skipped the full
pnpm test:prbecause it is slow on this machine. CI runs it. No new E2E test: the flow needs the real coding-agent CLIs, so the unit tests use a fake sandbox provider and stand-in agents, and the manual run below used the real CLIs.
Manual test (done on Windows with real logins)
pnpm install && pnpm build:all, then sign in once:claude loginandcodex login.- In
examples/harness-cli, setOPENAI_API_KEY,CODING_AGENTS=1, andCODEX_MODELto the model in~/.codex/config.toml(a ChatGPT login does not acceptgpt-5.3-codex). - Ask:
have claude_code create delegates.md with the line "Claude Code was here.", then have codex append "Codex was here." - Result on my run: Claude Code wrote the first line. Codex resumed the same session on its second call and appended the second line. On Windows the Codex
workspace-writesandbox denied the folder, so this step neededCODEX_SANDBOX_MODE=danger-full-access(the README says so).
How this PR makes testing easy
packages/ai-sandbox/tests/coding-agents.test.ts: sandbox per thread, session resume (also after a restart),/fresh, shared lock versus per-agent, plan mode.packages/ai-harness/tests/plugin-subagents.test.ts,packages/ai-harness-cli/tests/child-view.test.ts,packages/ai-acp/tests/child-updates.test.ts,packages/ai-dashboard/tests/child-agents.test.ts.examples/harness-cliwithCODING_AGENTS=1.
Risk / rollback#
Low. A new subpath and a new plugin contribution. The CLI line mode now prints only new entries (or growing assistant text), so a changed earlier entry does not print twice. Revert the PR to undo.
Public API change#
Before
defineHarness({ name: 'acme/lead', adapter: openaiText('gpt-5.6') })
After
import { codingAgents } from '@tanstack/ai-sandbox/harness'
defineHarness({
name: 'acme/lead',
adapter: openaiText('gpt-5.6'),
plugins: () => [
codingAgents({
sandbox: defineSandbox({ id: 'repo', provider: localProcessSandbox({ dir: repo }), workspace: defineWorkspace({ source: localSource(repo) }) }),
agents: {
claude_code: { adapter: claudeCodeText('claude-opus-4-8'), description: 'Larger changes' },
codex: { adapter: codexText('gpt-5.3-codex'), description: 'Quick fixes' },
},
}),
],
})
🤖 Generated with Claude Code
- 1
View your CI Pipeline Execution ↗ for commit c782dc2a99ef427c826cbf2b705d32a4198cb7f9
Command Status Duration Result nx run-many --targets=build --exclude=examples/...✅ Succeeded 50s View ↗
☁️ Nx Cloud last updated this comment at
2026-09-28 14:56:43UTC@tanstack/ai
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai@1538@tanstack/ai-acp
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-acp@1538@tanstack/ai-angular
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-angular@1538@tanstack/ai-anthropic
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-anthropic@1538@tanstack/ai-bedrock
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-bedrock@1538@tanstack/ai-byteplus
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-byteplus@1538@tanstack/ai-claude-code
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-claude-code@1538@tanstack/ai-client
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-client@1538@tanstack/ai-cloudflare
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-cloudflare@1538@tanstack/ai-code-mode
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-code-mode@1538@tanstack/ai-code-mode-snippets
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-code-mode-snippets@1538@tanstack/ai-codex
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-codex@1538@tanstack/ai-cohere
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-cohere@1538@tanstack/ai-compaction
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-compaction@1538@tanstack/ai-dashboard
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-dashboard@1538@tanstack/ai-devtools-core
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-devtools-core@1538@tanstack/ai-durable-stream
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-durable-stream@1538@tanstack/ai-elevenlabs
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-elevenlabs@1538@tanstack/ai-event-client
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-event-client@1538@tanstack/ai-fal
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-fal@1538@tanstack/ai-gemini
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-gemini@1538@tanstack/ai-grok
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok@1538@tanstack/ai-grok-build
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok-build@1538@tanstack/ai-groq
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-groq@1538@tanstack/ai-harness
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-harness@1538@tanstack/ai-harness-cli
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-harness-cli@1538@tanstack/ai-isolate-cloudflare
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-cloudflare@1538@tanstack/ai-isolate-daytona
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-daytona@1538@tanstack/ai-isolate-node
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-node@1538@tanstack/ai-isolate-quickjs
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-quickjs@1538@tanstack/ai-isolate-quickjs-bun
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-quickjs-bun@1538@tanstack/ai-llmgateway
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-llmgateway@1538@tanstack/ai-lovable
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-lovable@1538@tanstack/ai-mcp
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-mcp@1538@tanstack/ai-memory
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-memory@1538@tanstack/ai-mistral
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-mistral@1538@tanstack/ai-octane
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-octane@1538@tanstack/ai-ollama
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollama@1538@tanstack/ai-openai
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openai@1538@tanstack/ai-opencode
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-opencode@1538@tanstack/ai-openrouter
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openrouter@1538@tanstack/ai-perplexity
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-perplexity@1538@tanstack/ai-persistence
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-persistence@1538@tanstack/ai-preact
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-preact@1538@tanstack/ai-react
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react@1538@tanstack/ai-react-ui
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react-ui@1538@tanstack/ai-reactor
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-reactor@1538@tanstack/ai-remix
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-remix@1538@tanstack/ai-sandbox
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox@1538@tanstack/ai-sandbox-blaxel
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-blaxel@1538@tanstack/ai-sandbox-boxd
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-boxd@1538@tanstack/ai-sandbox-cloudflare
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-cloudflare@1538@tanstack/ai-sandbox-daytona
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-daytona@1538@tanstack/ai-sandbox-docker
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-docker@1538@tanstack/ai-sandbox-e2b
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-e2b@1538@tanstack/ai-sandbox-local-process
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-local-process@1538@tanstack/ai-sandbox-sprites
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-sprites@1538@tanstack/ai-sandbox-upstash-box
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-upstash-box@1538@tanstack/ai-sandbox-vercel
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-vercel@1538@tanstack/ai-skills
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-skills@1538@tanstack/ai-solid
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid@1538@tanstack/ai-solid-ui
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid-ui@1538@tanstack/ai-svelte
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-svelte@1538@tanstack/ai-typesafe
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-typesafe@1538@tanstack/ai-utils
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-utils@1538@tanstack/ai-vercel-gateway
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vercel-gateway@1538@tanstack/ai-vertex
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vertex@1538@tanstack/ai-vue
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue@1538@tanstack/ai-vue-ui
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue-ui@1538@tanstack/ai-worldlabs
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-worldlabs@1538@tanstack/openai-base
npm i https://pkg.pr.new/TanStack/ai/@tanstack/openai-base@1538@tanstack/preact-ai-devtools
npm i https://pkg.pr.new/TanStack/ai/@tanstack/preact-ai-devtools@1538@tanstack/react-ai-devtools
npm i https://pkg.pr.new/TanStack/ai/@tanstack/react-ai-devtools@1538@tanstack/solid-ai-devtools
npm i https://pkg.pr.new/TanStack/ai/@tanstack/solid-ai-devtools@1538@tanstack/svelte-ai-devtools
npm i https://pkg.pr.new/TanStack/ai/@tanstack/svelte-ai-devtools@1538commit:
c782dc2github-actions[bot](GitHub profile, opens in a new tab) assignedjherr
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer
Closed in favor of the combined PR #1555, which holds this phase and every other phase of the harness (P0 to P14) on one branch against main. All further fixes go there. This PR stays as the review record of P9.
AlemTuzlak closed this
Sign in to join this conversation.
Important
Review skipped#
Auto reviews are disabled on base/target branches other than the default branch.
Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository: TanStack/ai/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
48d4c64d-9653-4fb3-8a8c-4a339225af94You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share