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

Run lifecycle diagram

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 or merge request
issueAgent creates an issue

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.

A run can also fail with failReason: error and error code RUN_RESOURCE_LIMIT_EXCEEDED if the sandbox runs out of memory.

Sandbox Size

The sandbox size used for a run comes from the template. The run response includes a sandbox object with the resolved size and resource limits:

{
  "sandbox": {
    "id": "snd_...",
    "size": "m",
    "resources": {
      "cpuMillis": 2000,
      "memoryMi": 4096,
      "diskMi": 10240
    }
  }
}

To use a different size, update the template's size field. See Templates — Sandbox Sizes.

Environment Variables

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

Getting Results

Three ways to get results from a run:

MethodHow it worksBest for
PollingPoll GET /v1/runs/:id every 5–10 sSimple scripts
WebhooksSigned push to your server for all runs in your orgProduction integrations
callbackUrlUnsigned push to a URL you set per runQuick prototyping

See the Webhooks guide for setup and signature verification.

Managing Runs

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

On this page