Docs

Runs

Create, monitor, and manage agent execution sessions

What Are Runs?

A run is a single agent execution. You provide a prompt and a repository — coSPEC provisions a sandbox, runs the agent, and returns the output. Each run is isolated, time-limited, and fully audited.

Creating a Run

Start a run by sending a prompt and repository to the API:

Terminal
curl -X POST https://api.cospec.io/v1/runs \
  -H "Authorization: Bearer csk_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "repo": "your-org/your-repo",
    "prompt": "Refactor the auth middleware to use JWT",
    "template": "your-template",
    "model": "sonnet"
  }'

See the Create Run API reference for all available fields.

Run Lifecycle

pending → running → completed | failed | cancelled
StatusDescription
pendingRun is queued, sandbox is being provisioned
runningAgent is executing inside the sandbox
completedAgent finished successfully
failedAgent hit a guardrail or encountered an error
cancelledRun was cancelled via the API

Outputs

Outputs are detected automatically based on what the agent does during the run. You don't configure them upfront — they are collected as the agent works.

TypeDetected when
textAgent produces a final text response
branchAgent pushes changes with git push
prAgent creates a pull request with gh pr create
issueAgent creates an issue with gh issue create

A single run can produce multiple outputs. For example, an agent might push a branch and open a pull request in the same run.

Guardrails

Guardrails cap resource usage per run. Set them on the run directly or as defaults on a template.

GuardrailRangeDefaultDescription
maxTurns1–1000100Maximum agent turns
maxCostUsd$0.01–$1000$5Maximum Anthropic API cost
timeoutSeconds30–36001800Maximum wall-clock time

When a guardrail triggers, the run stops with status: failed and a failReason of max_turns, max_cost, or timeout.

Environment Variables

Pass per-run environment variables using the env field. These are merged with template defaults — run values win on conflict.

Managing Runs

Use the API to monitor, cancel, and list runs. See the Runs API reference for details.

On this page