AI SDK 7 HarnessAgent sandbox pattern for safe CI coding jobs
Wire AI SDK 7 HarnessAgent to Vercel Sandbox or E2B using a disposable mirror repo so Codex/Claude Code-style agents never touch your production repo.
What you will actually run, and what it costs
The safest way to run Codex, Claude Code or Cursor-style harnesses through AI SDK 7 HarnessAgent is to treat them like untrusted CI workers. They only ever see a disposable mirror clone of your repo, and they only ever execute inside an isolated sandbox: either Vercel Sandbox microVMs or E2B microVMs wired via AI SDK sandbox adapters. The production Git remote, real tokens and infrastructure never enter that environment. This is the same core principle as the broader CI-safe agent workflows described in the GitHub Actions patterns for AI coding agents in CI, and in the step-by-step GitHub workflow in how to run Codex, Cursor and Claude Code inside GitHub Actions safely.
This article lays out an end-to-end pattern: a minimal Node/TypeScript package in your monorepo that hosts the HarnessAgent, a GitHub Actions workflow that creates and tears down a shallow mirror clone, and pluggable sandbox backends (Vercel Sandbox and E2B) selected via environment flags. Using Vercel’s published usage-based pricing for Sandbox and E2B’s official per-second rates, the incremental sandbox compute for 100–500 HarnessAgent jobs per month generally falls in the low tens of dollars under short (≈15-minute) runs on small instances; the dominant variable is how long each job runs.
Why HarnessAgent needs a sandboxed mirror repo, not your production repo
AI SDK 7 adds HarnessAgent, an experimental abstraction that lets teams program established coding-agent harnesses such as Claude Code, Codex, and Pi through one Agent-style API, with generate/stream semantics and explicit sandbox support, as described in Vercel’s AI SDK 7 announcementAI SDK 7 is now available. Vercel’s follow-on changelog entry shows concrete examples wiring Claude Code, Codex, and Pi harnesses into HarnessAgent and passing a sandbox created via @ai-sdk/sandbox-vercelProgram Claude Code, Codex, Pi and other agent harnesses with AI SDK.
Those harnesses were originally designed to work inside developer environments or tightly-scoped IDE integrations. Given full repo access, they will read any file they can see and often use external tools or shells to execute arbitrary commands. Vercel’s Sandbox knowledge-base articles describe using Vercel Sandbox to run untrusted or AI-generated code in isolation, including running coding agents such as OpenCode in a microVM with controlled egress, which is directly applicable when you run HarnessAgent against untrusted code such as GitHub issue reprosVercel Sandbox | Vercel Knowledge Base.
If you attach HarnessAgent directly to your production monorepo path on a CI machine, three things become hard to defend:
- Repository integrity: a misbehaving harness can rewrite large swathes of your tree, including configuration and workflow files.
- Secret exposure: anything readable on disk (config, build outputs, cached credentials) can be exfiltrated via logs or network calls if the harness or underlying tools are compromised.
- Cost and blast radius: without strict scoping, long-running or looping jobs can burn AI tokens and compute time while still having write access to the repo and CI environment.
The pattern here is simple: HarnessAgent never receives a path that points into the real repo. Instead, GitHub Actions creates a shallow clone of the PR’s head commit into a disposable directory, strips its remotes, and passes only that path into a sandboxed Node process running your HarnessAgent entrypoint. The sandbox (Vercel Sandbox or E2B) is treated like any other untrusted worker: short-lived, tightly budgeted, and with no routes back to production systems. If you need a broader architecture overview of where agents should and shouldn’t touch your CI/CD, see the discussion of safe agent boundaries in where AI coding agents should and shouldn’t touch your CI/CD and the repo-contract perspective in one autonomous coding agents workflow for Codex, Claude Code and Cursor.
Decision overview: which sandbox and when to use HarnessAgent at all
The core decision is not whether HarnessAgent is useful — it is how to run it without violating your repo and security contracts, and whether you should run it at all for a given workflow.
| Option |
Best for |
Starting price |
Main strength |
Main limitation |
| HarnessAgent + Vercel Sandbox + disposable mirror |
Teams already on a Vercel Pro plan (which includes a monthly usage credit that applies to usage-billed products such as Sandbox) that want CI-only agents reviewing PRs |
$20/user/month Pro (includes $20/month in usage credit that applies to Sandbox and other usage-billed products; additional Sandbox usage is billed at published rates) |
Tight integration with AI SDK 7 and Vercel AI Gateway, microVM isolation |
Requires Vercel Pro and alignment with Vercel pricing & limits |
| HarnessAgent + E2B + disposable mirror |
Teams wanting a dedicated agent sandbox cloud, less tied to Vercel |
Usage-billed per second based on vCPUs and RAM provisioned (for example, a 2 vCPU / 4 GiB sandbox at $0.000028/s CPU + $0.000018/s RAM is ≈$0.0468/hour) |
Agent-focused microVM cloud with plan-based concurrency/session options |
Separate provider to manage; integration via @e2b/ai-sdk-sandbox |
| IDE-native agents (Claude Code, Codex, Cursor) |
Interactive development on developer machines |
Varies by tool (often freemium/seat-based) |
No CI wiring; human supervision of every change |
No automated, repeatable check on every PR |
| Conventional CI checks (linters/tests only) |
Teams with strict budgets needing predictable, simple CI |
CI minutes + existing infra |
Cheap, stable, very predictable |
No autonomous code editing or complex refactors |
Who should run this pattern
- Founders and staff engineers who already run CI on GitHub Actions and want Codex, Claude Code or Cursor-like agents as untrusted reviewers on PRs.
- Teams on Vercel Pro already using Vercel Functions or AI Gateway and wanting to stay in that stack while adding coding agents to CI.
- Operators experimenting with AI SDK 7 HarnessAgent who need a concrete, CI-safe wiring for real repositories rather than examples against toy code.
- Security-minded teams that must prove AI agents never see long-lived tokens, the primary Git remote or production infrastructure.
Who should use something else
- Solo developers who only want smarter autocomplete or chat inside an editor; native IDE or terminal agents are simpler than wiring HarnessAgent into CI.
- Teams not using TypeScript/Node or GitHub Actions and unwilling to adapt to their CI stack.
- Organisations that cannot use third-party sandboxes (Vercel Sandbox or E2B) and are not ready to operate their own isolated runtime.
How Vercel Sandbox and E2B slot into AI SDK 7 HarnessAgent
Vercel exposes an official @ai-sdk/sandbox-vercel package that plugs Vercel Sandbox into AI SDK. The AI SDK 7 announcement shows a createVercelSandbox helper used inside HarnessAgent configuration, for example for Claude Code, specifying runtime (such as node24) and allowed portsAI SDK 7 is now available. The pairing allows HarnessAgent to treat the sandbox as its compute substrate while still presenting the normal Agent interface.
E2B offers what it calls an “AI agent cloud”, essentially Firecracker-based microVM sandboxes designed for AI agents, including coding agentsPricing | E2B — The AI Agent Cloud. The @e2b/ai-sdk-sandbox npm package integrates E2B sandboxes with AI SDK 7, acting as the counterpart to Vercel’s sandbox package and designed to be used inside a HarnessAgent configuration@e2b/ai-sdk-sandbox - npm.
This gives you a clean abstraction:
- Your TypeScript monorepo exports a function
createHarnessAgent({ harnessKind, sandboxKind }).
harnessKind selects between configured harnesses such as Codex or Claude Code.
sandboxKind chooses either a Vercel Sandbox microVM via createVercelSandbox or an E2B sandbox via createE2BSandbox from @e2b/ai-sdk-sandbox.
- GitHub Actions passes those as environment variables, so individual workflows or branches can test different combinations without code changes, as in the single-workflow pattern in one HarnessAgent GitHub Actions workflow for CI agents.
Vercel Sandbox capabilities and pricing
Vercel documents Sandbox as an isolated microVM product with configurable resources and supported runtimes, built on its Fluid compute platformSandbox - Vercel. Earlier documentation and third-party analyses have described plan-specific limits on vCPUs, RAM, and session duration for Sandbox sessions, but the current Sandbox product page focuses on runtimes, Firecracker isolation, and usage-based pricing without listing those per-plan caps explicitly. Current limits should be confirmed in the Vercel dashboard and account documentation before hard-coding them into automation or runbooks.
On the pricing page, Vercel lists Sandbox as a usage-billed product with dimensions such as Active CPU, Provisioned Memory, Sandbox Creations, and Data Transfer. Pro teams receive a $20 monthly usage credit that applies across usage-billed products, including Sandbox; any additional Sandbox usage is billed on these dimensions at the published regional ratesVercel Pricing: Hobby, Pro, and Enterprise plans.
| Metric |
How it is billed |
Illustrative starting price (USD) |
| Active CPU hours |
Billed per Active CPU hour at regional rates; Pro teams can offset usage with their monthly credit |
For example, $0.128 per hour in some regions |
| Provisioned Memory |
Billed per GB-hour of provisioned memory at regional rates; again, usage draws from the Pro credit first |
For example, $0.0212 per GB-hour in some regions |
| Sandbox creations |
Billed per creation at regional rates after any free or credit-offset usage |
For example, $0.60 per 1M creations in some regions |
| Data transfer |
Billed under Vercel’s data transfer/CDN overage model after any included or credit-covered usage |
Subject to Vercel’s CDN and data transfer overage rates |
The exact rates and any included usage vary by region and over time, so teams should refer to the live Vercel pricing page and their account’s usage dashboard when estimating Sandbox costs.
E2B capabilities and indicative pricing
E2B documents plan-based limits on concurrency and session duration. A rate-limits file derived from its docs lists Hobby as allowing 20 concurrent sandboxes with sessions up to 1 hour, and Pro as allowing 100 concurrent sandboxes, expandable up to 1,100 with purchase, and session duration up to 24 hoursE2B Rate Limits and Concurrency. Included storage is 10 GiB on Hobby and 20 GiB on Pro in that same metadata.
The current E2B pricing page quotes per-second prices for CPU and RAM. One documented example is a 2 vCPU / 4 GiB sandbox at $0.000028/s for CPU and $0.000018/s for RAM, which works out to (2 × $0.000028 + 4 × $0.000018) × 3,600 ≈ $0.0468 per hourPricing | E2B — The AI Agent Cloud. This is an indicative example; actual costs depend on the chosen shape, plan, and any free quotas or discounts that apply.
| Provider |
Example shape |
Indicative price/hour |
Max session length (non-Enterprise) |
| Vercel Sandbox (usage-billed) |
Example: 2 vCPU / 4 GB RAM |
Active CPU and memory billed separately at regional rates after Pro credits are exhausted |
See current account-level limits and documentation |
| E2B (example) |
2 vCPU / 4 GiB RAM |
≈$0.0468/hour based on $0.000028/s CPU and $0.000018/s RAM |
1 hour (Hobby) / 24 hours (Pro) |
At the harness-integration level, both providers look similar: your code calls into a sandbox adapter that launches an isolated microVM, mounts a workspace, and runs your HarnessAgent process. The key differences are concurrency and session policies and how well each fits your existing stack. For a deeper comparison of which agents actually belong in CI, see the trade-offs in HarnessAgent vs managed Codex and Claude Code.
Use the pluggable sandbox pattern in a minimal monorepo
The core of this pattern is a small TypeScript package inside your monorepo that knows how to:
- Select a harness implementation (Codex, Claude Code, Cursor-style harness through HarnessAgent) based on configuration.
- Select a sandbox backend (Vercel Sandbox or E2B) via environment variables.
- Accept an on-disk mirror path, run the agent against that path, and emit structured results and logs without attempting to push or write anywhere else.
Repository layout
A minimal layout might look like this:
root/
apps/
web/ # your main app
packages/
ai-harness-runner/ # <-- HarnessAgent + sandbox abstraction
src/
index.ts
createHarnessAgent.ts
sandboxes/
vercelSandbox.ts
e2bSandbox.ts
tsconfig.json
package.json
.github/
workflows/
harnessagent-ci.yml
TypeScript entrypoint and harness selection
The following illustrates a single CLI-style entrypoint that chooses the harness and sandbox from environment variables. The specific harness factory functions follow the patterns in Vercel’s HarnessAgent examples but are shown abstractly here as the official code examples are brief and focused on one harness at a timeProgram Claude Code, Codex, Pi and other agent harnesses with AI SDK.
// packages/ai-harness-runner/src/index.ts
import { createHarnessAgent } from './createHarnessAgent';
async function main() {
const mirrorPath = process.env.MIRROR_REPO_PATH;
if (!mirrorPath) {
throw new Error('MIRROR_REPO_PATH is required');
}
const harnessKind = process.env.HARNESS_KIND ?? 'codex';
const sandboxKind = process.env.SANDBOX_KIND ?? 'vercel';
const agent = await createHarnessAgent({ harnessKind, sandboxKind, mirrorPath });
const task = process.env.HARNESS_TASK ?? 'review-changes';
const result = await agent.generate({
input: `Task: ${task}\nRepo path: ${mirrorPath}`,
});
// In CI, write results to a JSON file for later steps to consume
const fs = await import('node:fs/promises');
await fs.writeFile(
process.env.HARNESS_OUTPUT_PATH ?? './harness-result.json',
JSON.stringify(result, null, 2),
'utf8',
);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});
Create HarnessAgent with pluggable sandboxes
The factory wires harnesses to sandbox adapters. The shape follows Vercel’s documented pattern: call HarnessAgent with a harness factory and a sandbox created from either @ai-sdk/sandbox-vercel or @e2b/ai-sdk-sandboxAI SDK 7 is now available.
// packages/ai-harness-runner/src/createHarnessAgent.ts
import { HarnessAgent } from 'ai';
import { createVercelSandbox } from './sandboxes/vercelSandbox';
import { createE2BSandbox } from './sandboxes/e2bSandbox';
// Placeholder imports; in real code you use the official adapters
// e.g. import { createClaudeCodeHarness } from '@vercel/ai-harness-claude-code';
// and similar for Codex or other harnesses.
interface Options {
harnessKind: 'codex' | 'claude-code' | 'cursor-style';
sandboxKind: 'vercel' | 'e2b';
mirrorPath: string;
}
export async function createHarnessAgent(options: Options) {
const sandbox =
options.sandboxKind === 'e2b'
? await createE2BSandbox({ mirrorPath: options.mirrorPath })
: await createVercelSandbox({ mirrorPath: options.mirrorPath });
const harness = (() => {
switch (options.harnessKind) {
case 'claude-code':
// return createClaudeCodeHarness({ sandbox, workingDirectory: options.mirrorPath });
return { sandbox } as any;
case 'cursor-style':
// return createCursorLikeHarness({ sandbox, cwd: options.mirrorPath });
return { sandbox } as any;
case 'codex':
default:
// return createCodexHarness({ sandbox, cwd: options.mirrorPath });
return { sandbox } as any;
}
})();
const agent = new HarnessAgent({ harness });
return agent;
}
Sandbox adapters
The adapter implementations encapsulate provider-specific config (runtime, ports, resource sizes) and enforce strict time and cost limits. The Vercel example below mirrors Vercel’s own usage of createVercelSandbox({ runtime: 'node24', ports: [...] }) shown in the AI SDK 7 announcementAI SDK 7 is now available.
// packages/ai-harness-runner/src/sandboxes/vercelSandbox.ts
import { createVercelSandbox as createVercelSandboxSdk } from '@ai-sdk/sandbox-vercel';
interface VercelSandboxOptions {
mirrorPath: string;
}
export async function createVercelSandbox(opts: VercelSandboxOptions) {
const timeoutMs = Number(process.env.HARNESS_TIMEOUT_MS ?? '900000'); // 15 minutes
const sandbox = await createVercelSandboxSdk({
runtime: 'node24',
// For CI-only use, you may not need to expose any ports externally.
ports: [],
// Filesystem mounts will reference opts.mirrorPath if supported.
workingDirectory: opts.mirrorPath,
timeoutMs,
});
return sandbox;
}
// packages/ai-harness-runner/src/sandboxes/e2bSandbox.ts
import { createE2BSandbox as createE2BSandboxSdk } from '@e2b/ai-sdk-sandbox';
interface E2BSandboxOptions {
mirrorPath: string;
}
export async function createE2BSandbox(opts: E2BSandboxOptions) {
const timeoutMs = Number(process.env.HARNESS_TIMEOUT_MS ?? '900000');
const sandbox = await createE2BSandboxSdk({
cwd: opts.mirrorPath,
timeoutMs,
// Shape selection can be encoded via env vars like E2B_MACHINE_TYPE.
});
return sandbox;
}
All sandbox-specific flags (runtime, vCPUs, memory, session timeout) should be parameterised via environment variables or configuration files, not hard-coded. That makes it easier to enforce environment-wide caps and adjust resource envelopes without redeploying your harness package.
CI-safe mirror repo contract
The safety guarantee relies on a strict contract enforced by CI rather than informal discipline. The steps below assume GitHub Actions, but the structure applies to any CI system.
1. Create a shallow, disposable mirror clone
Each CI run creates a dedicated workspace directory, then performs a shallow clone of the PR’s head SHA into that directory. The mirror clone has no push permissions and no configured remotes after cloning.
# .github/workflows/harnessagent-ci.yml
name: HarnessAgent Sandbox CI
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
harnessagent:
runs-on: ubuntu-latest
permissions:
contents: read # only needs read for cloning
env:
NODE_ENV: production
HARNESS_KIND: codex # or claude-code / cursor-style
SANDBOX_KIND: vercel # or e2b
HARNESS_TIMEOUT_MS: '900000' # 15 minutes hard cap
steps:
- name: Checkout sources (read-only)
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies (pnpm example)
run: |
corepack enable
pnpm install --filter ai-harness-runner...
- name: Prepare disposable mirror repo
id: mirror
run: |
MIRROR_DIR="${{ runner.temp }}/mirror-repo"
mkdir -p "$MIRROR_DIR"
git clone --depth=1 \
--no-tags \
--branch "${{ github.head_ref }}" \
"${{ github.server_url }}/${{ github.repository }}.git" \
"$MIRROR_DIR"
cd "$MIRROR_DIR"
# Remove origin to prevent any accidental pushes
git remote remove origin
# Optionally, remove all remotes to be strict
# git remote | xargs -r -n1 git remote remove
echo "mirror_path=$MIRROR_DIR" >> "$GITHUB_OUTPUT"
- name: Run HarnessAgent inside sandboxed runner
env:
MIRROR_REPO_PATH: ${{ steps.mirror.outputs.mirror_path }}
HARNESS_OUTPUT_PATH: ${{ runner.temp }}/harness-result.json
HARNESS_TASK: "Review PR changes for regressions and style issues"
# Provider-specific secrets for AI models can be scoped to this job
# and never persisted in the mirror.
run: |
pnpm --filter ai-harness-runner exec tsx ./src/index.ts
- name: Upload HarnessAgent result artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: harnessagent-result
path: ${{ runner.temp }}/harness-result.json
Key points:
- No write permissions: the job only has
contents: read permissions, and the mirror repo has no remotes configured after clone.
- Shallow clone:
--depth=1 keeps fetch size and runtime small. If your harness needs history, you can increase depth or fetch specific ranges.
- Disposable path:
runner.temp ensures the workspace is isolated per job and cleaned up by the runner lifecycle.
2. Never pass real credentials into the mirror
The mirror clone should never hold secrets. Credentials for AI providers are injected as environment variables into the sandboxed HarnessAgent process, not written to disk in the mirror path. If the sandbox implementation supports fine-grained filesystem grants, they can be used to ensure even the HarnessAgent cannot write outside the mirror directory.
OpenAI’s Agents sandbox docs, for example, describe a readOnly: true flag on filesystem grants that prevents writesConcepts | OpenAI Agents SDK. While AI SDK 7’s sandbox integrations have their own APIs, the same principle can be applied: guard writable paths and avoid mounting secrets.
3. Enforce hard time and budget caps
The job-level timeout and the sandbox runtime limit jointly control cost:
- GitHub Actions: use
timeout-minutes on the job to cap wall-clock time.
- Sandbox: for Vercel Sandbox, configure session length within any documented or account-level limit via the sandbox create options or agent-level timeouts. For E2B, keep within the 1-hour Hobby or 24-hour Pro session capsE2B Rate Limits and Concurrency.
- AI Gateway: when using Vercel AI Gateway, rely on its cost metadata (
providerMetadata.gateway.cost) to track token spend per request, as Vercel notes that Gateway charges tokens at upstream providers’ list prices with no markupAI Gateway - Vercel.
jobs:
harnessagent:
runs-on: ubuntu-latest
timeout-minutes: 20 # hard job wall-clock cap
These caps align with the cost model assumptions described later: 15-minute HarnessAgent runs at small instance sizes are relatively inexpensive; much longer runs at scale move the Sandbox or E2B line item into a different order of magnitude.
Cost model: what 100–2,000 HarnessAgent jobs actually cost
The cost numbers below combine Vercel’s published Sandbox pricing model with a normalised scenario analysis. AI tokens are not quantified precisely because they depend on the models chosen, but Vercel’s AI Gateway documentation states that token costs match the upstream provider’s list price without markupAI Gateway - Vercel.
Assumptions
- Vercel Pro at $20/user/month; Sandbox usage billed against the Pro team’s monthly usage credit and then at published rates.
- Sandbox shape for coding agents: an example 2 vCPU / 4 GB RAM configuration.
- Each HarnessAgent job runs for 15 minutes (0.25 hours).
- E2B example shape: 2 vCPU / 4 GiB at ≈$0.0468/hour derived from per-second CPU and RAM ratesPricing | E2B — The AI Agent Cloud.
Vercel Sandbox cost scenarios
Using Vercel’s Pro Sandbox modelVercel Pricing: Hobby, Pro, and Enterprise plans:
- Active CPU and Provisioned Memory are billed as usage after the Pro usage credit is consumed.
- Sandbox creations and data transfer are also usage-billed, but for the volumes below they typically remain a minor component.
| Scenario |
Jobs/month |
Total vCPU-hours |
Illustrative Active CPU cost |
Illustrative Memory cost |
Approximate incremental Sandbox compute (before credits) |
| Solo (100 PRs, 1 job each) |
100 |
25 hours |
25 × $0.128 = $3.20 |
4 GB × 25 = 100 GB-hrs × $0.0212 ≈ $2.12 |
≈ $5.32/month (+ tokens, partially or fully offset by Pro credit) |
| Small team (500 PRs, 1 job each) |
500 |
125 hours |
125 × $0.128 = $16.00 |
4 GB × 125 = 500 GB-hrs × $0.0212 ≈ $10.60 |
≈ $26.60/month (+ tokens, partially offset by Pro credit) |
| Aggressive CI (1,000 PRs, 2 jobs each) |
2,000 |
500 hours |
500 × $0.128 = $64.00 |
4 GB × 500 = 2,000 GB-hrs × $0.0212 ≈ $42.40 |
≈ $106.40/month (+ tokens, partially offset by Pro credit) |
The arithmetic in each row is explicit: vCPU-hours = jobs × 0.25; memory GB-hours = 4 × vCPU-hours. These numbers are approximate because Vercel flags its pricing as regional and starting at the listed rates, and because the Pro usage credit reduces the effective bill. They illustrate that for modest HarnessAgent usage, Sandbox compute is typically not the dominant cost line item.
Vercel Sandbox vs E2B at 500 jobs/month
Using the 500-job scenario and the E2B example cost:
- Vercel Sandbox (illustrative): 500 jobs × 0.25 hours = 125 hours, ≈$26.60 in Sandbox compute at the example CPU and memory rates above, with some or all of that offset by the Pro usage credit.
- E2B example shape: 125 hours × ≈$0.0468/hour ≈ $5.85, ignoring any plan-specific quotas or discounts.
Under these assumptions, raw compute cost remains in the “tens of dollars per month” band for the volumes discussed. The more influential differences are:
- How many concurrent sandboxes you need (Vercel accounts can support high concurrency; E2B Hobby lists 20 and Pro 100–1,100E2B Rate Limits and Concurrency).
- Whether you benefit from being inside the Vercel Pro stack versus adding another provider relationship.
- The token costs from your harness models, which often dominate once large-context models are used heavily.
Failure modes and how the mirror pattern contains them
Treating HarnessAgent as an untrusted CI worker helps you reason about failure modes explicitly.
Sandbox crash or timeout
Failure: The sandbox reaches its runtime limit, exhausts memory, or fails to start due to configuration errors. The HarnessAgent process does not complete, and no result file is written.
Containment: Because the agent only has access to the mirror repo path, a crash cannot corrupt the main repo. GitHub Actions marks the job as failed, and the PR remains unaffected apart from a missing or partial AI review. Absence of a valid result file can be interpreted as a failure signal.
Mitigation:
- Set conservative timeouts in both the sandbox create call and the CI job.
- Log sandbox lifecycle events (start, stop, error) in the HarnessAgent runner package for debugging.
- Allow retries with backoff if the provider documents transient failure behaviour.
Partial file writes or malformed changes
Failure: The harness produces incorrect or incomplete edits in the mirror repo, such as partially refactored modules or misapplied patches.
Containment: All writes are confined to the mirror path. The main repo and any live branches are untouched. A CI workflow can choose to:
- Ignore changes and only consume the agent’s textual report.
- Archive the changed mirror as an artifact for human inspection.
- In future, consider a separate workflow that turns approved mirror changes into a controlled PR via a human-in-the-loop process.
Since the mirror repo has no remotes, the harness cannot push its changes anywhere even if it tries to run git push.
Unexpected network calls or tool usage
Failure: The harness or underlying tools attempt to reach arbitrary external endpoints or use system tools that were not intended.
Containment:
- Vercel Sandbox runs the code in a microVM with controlled ports and network environmentSandbox - Vercel. It is possible to avoid exposing any inbound ports for CI-only workflows.
- E2B’s Firecracker microVM model similarly isolates the process with controlled networking according to its plan and documentationPricing | E2B — The AI Agent Cloud.
- No long-lived credentials (database, production APIs) are passed into the sandbox environment. AI API keys are scoped to the job only.
Provider or adapter breaking changes
Failure: HarnessAgent or a sandbox adapter introduces a breaking change because the abstraction is explicitly labelled experimental in comparisons such as TanStack’sTanStack AI vs Vercel AI SDK.
Containment: The harness runner is a separate package in your monorepo with a strict API surface. Breaking changes remain local to this package. CI workflows can pin adapter versions and gradually upgrade once compatibility has been verified.
When the decision changes
The mirror plus sandbox pattern is optimised for short-lived, automated CI jobs on untrusted code. Several scenarios change the decision:
- Interactive IDE-like development: When a team wants interactive Claude Code, Codex or Cursor usage on developer machines, native IDE integrations or first-party clients are better fits. HarnessAgent plus CI sandboxes adds overhead and cost that only pays off for automated, repeatable checks.
- No access to Vercel Sandbox or E2B: If data residency or vendor policy disallows these providers, the same principle can be applied using a self-hosted sandbox environment. OpenAI’s Agents API, for example, explains a self-hosted sandbox model where webhooks provision external sandboxes via provider SDKsSelf-hosted sandboxes | OpenAI API. The disposable mirror and strict budget pattern remain valid.
- Very tight CI budgets: When only simple linting or unit tests are needed, conventional tools are almost always cheaper and simpler than full coding agents. The extra degrees of freedom in HarnessAgent are only worth it when genuinely autonomous edits or complex reasoning are needed.
- Long-lived workspaces: For multi-day branches or persistent dev environments, a devbox-style provider (such as a general container platform) or managed IDE agents may be a better fit. This mirror pattern assumes one sandbox per CI job rather than multi-day sessions.
- Limited tolerance for experimental APIs: Teams that are not prepared to monitor HarnessAgent and sandbox adapter releases and handle occasional churn may prefer to defer adoption or use more mature single-vendor agents/APIs to reduce operational risk.
Comparison criteria
The recommendations above are based on:
No private benchmarks or production deployments are assumed; the architecture and cost models are derived from these public documents and explicit arithmetic on the published prices and limits.
How to decide quickly
For teams already on Vercel Pro and comfortable with TypeScript, a straightforward default is to implement the monorepo package pattern described here, target Vercel Sandbox via @ai-sdk/sandbox-vercel, use a disposable shallow mirror per PR, and cap each job to 15–20 minutes. For 100–500 HarnessAgent runs per month, the Sandbox compute cost under the example rates above stays in the tens-of-dollars range plus token spend, with some or all of the infrastructure cost offset by the Pro usage credit. A step-by-step template GitHub Actions workflow for this style of setup follows directly from the YAML example in this article and the hardened pattern in secure HarnessAgent CI with AI SDK 7.
For teams not on Vercel or that prefer provider separation, E2B can be used via @e2b/ai-sdk-sandbox while keeping the same mirror and CI contract. The result is the same: HarnessAgent behaves like an untrusted worker inside a disposable microVM, with no path back to the main repo or production secrets. For an adjacent perspective on how this ties into broader repo-safe HarnessAgent usage, see the overview of repo-safe coding agents with AI SDK 7 HarnessAgent.
If neither managed sandbox fits organisational constraints, the pattern can be replicated with a self-hosted sandbox environment using a similar mirror-repo contract. The constant is the security mindset: HarnessAgent should not run against the real repo or infrastructure, and jobs should always be budgeted in terms of explicit time and cost envelopes.