# The kosa8 AI agent

Type a task, press **Go**. kosa8 starts a fresh sandbox with your repository, a coding agent works on it, and you get one clear result: an answer, or a draft pull request. No model key, no setup.

kosa8 AI reads, explains and makes small changes as draft pull requests. It never approves, merges, deletes or widens access. For larger coding work, **Use your own model** (Claude Code, Codex or Gemini CLI with your key) under **More options**: it is the better choice for real coding.

## Start one

- **Autopilot → Start an AI agent**: one-click templates *Fix a failing test*, *Explain this error*, *Summarize this repo* and *Write a README*.

- **Integrations → GitHub** and a sandbox's page: **Ask the AI agent to…**, one text box and Go.

- **Ask kosa8**: **Do it for me** on a suggestion, after you confirm.

- GitHub: `@kosa8 agent fix the flaky login test` on an issue or pull request ([@kosa8 in issues and PRs](https://docs.kosa8.com/guides/cloud-github-triggers/)). With no agent chosen, kosa8 AI is the default.

```
kosa8 agent "fix the failing test" --repo .      # from the next release
kosa8 agent "summarize this repo" --repo acme/api --no-wait
```

`--repo .` uses the GitHub repository of the folder you are in. The repository must be one your organization connected ([Your GitHub repos](https://docs.kosa8.com/guides/cloud-github/)).

## What you see

The run shows its steps as it goes: **Reading the repo** → **Thinking** → **Making changes** → **Running tests** → **Draft PR**. It ends with one result: a summary, the draft pull request's link, or why it failed with a suggested fix. When it finishes it shows what it cost, such as *This cost $0.01*: sandbox time plus the model calls.

## HTTP, MCP and SDKs

```
curl https://api.kosa8.com/v1/agent/tasks \
  -H "Authorization: Bearer $KOSA8_API_KEY" -H "Content-Type: application/json" \
  -d '{"task": "fix the failing test", "repo": "acme/api"}'
# → 202 {"id": "agt_…", "state": "queued", "steps": [...], "url": "https://app.kosa8.com/app#agent/agt_…"}

curl https://api.kosa8.com/v1/agent/tasks/agt_… -H "Authorization: Bearer $KOSA8_API_KEY"
# → {"state": "done", "result": {"summary": "…", "pr_url": "…"}, "cost_text": "This cost $0.01"}
```

Your agent can start one with the hosted [MCP server](https://docs.kosa8.com/guides/cloud-mcp/)'s `agent_task` tool and follow it with `agent_task_status`.

The SDKs do not have an `agent` helper yet. These few lines over the HTTP API do the same:

**Python**

```
import os, time, requests

API = "https://api.kosa8.com"
H = {"Authorization": f"Bearer {os.environ['KOSA8_API_KEY']}"}

def agent_run(task, repo):
    t = requests.post(f"{API}/v1/agent/tasks", headers=H, json={"task": task, "repo": repo}).json()
    while t["state"] in ("queued", "running"):
        time.sleep(3)
        t = requests.get(f"{API}/v1/agent/tasks/{t['id']}", headers=H).json()
    return t

t = agent_run("fix the failing test", "acme/api")
print(t["state"], (t.get("result") or {}).get("pr_url"), t.get("cost_text"))
```

**TypeScript**

```
const API = "https://api.kosa8.com";
const H = { Authorization: `Bearer ${process.env.KOSA8_API_KEY}`, "Content-Type": "application/json" };

async function agentRun(task: string, repo: string) {
  let t = await (await fetch(`${API}/v1/agent/tasks`, { method: "POST", headers: H, body: JSON.stringify({ task, repo }) })).json();
  while (t.state === "queued" || t.state === "running") {
    await new Promise((r) => setTimeout(r, 3000));
    t = await (await fetch(`${API}/v1/agent/tasks/${t.id}`, { headers: H })).json();
  }
  return t;
}

const t = await agentRun("fix the failing test", "acme/api");
console.log(t.state, t.result?.pr_url, t.cost_text);
```

## In your own sandboxes

A sandbox created with `"ai_gateway": "workers-ai"` (and a size) gets `OPENAI_BASE_URL` and `OPENAI_API_BASE` pointing at kosa8 AI, so any OpenAI-compatible tool works in it with no key. The sandbox holds only a placeholder: a short-lived credential for that one sandbox is added on the way out by its [egress broker](https://docs.kosa8.com/guides/cloud-secrets/), and it stops working when the sandbox goes.

```
curl https://api.kosa8.com/v1/sandboxes -H "Authorization: Bearer $KOSA8_API_KEY" \
  -H "Content-Type: application/json" -d '{"size": "2x4", "ai_gateway": "workers-ai"}'
```

## Safety and limits

- The agent works in a fresh microVM that holds no GitHub token and no long-lived model key.

- Its only way out is a **draft** pull request on a `kosa8/` branch. It never approves, merges, pushes to the default branch, deletes or widens access.

- Your spending cap, the per-run budget and a per-organization hourly cap apply (`429 agent_rate_limit` past it).

## Model and data

The agent is [aider](https://aider.chat/), already in the [universal image](https://docs.kosa8.com/guides/cloud-images/), using a coding model on [Cloudflare Workers AI](https://developers.cloudflare.com/workers-ai/) through kosa8's [AI Gateway](https://docs.kosa8.com/guides/cloud-ai-gateway/), on kosa8's Cloudflare account. Your code and prompts stay within Cloudflare and kosa8's sandbox hosts; no other model provider sees them. Every model call is logged for your organization (`GET /v1/ai/usage`). The model's name is under **Details**. It is included in your plan; prices are unchanged.

See also: [AI in kosa8](https://docs.kosa8.com/guides/autopilot/#ai), [Ask kosa8](https://docs.kosa8.com/guides/ask-kosa8/).

---
Source: https://docs.kosa8.com/guides/ai-agent/
