# Autopilot bots

Autopilot bots do the chores you would otherwise watch for: runaway spend, idle sandboxes, an agent hammering a blocked host, a stuck RL run. Each bot is a trigger and a few typed actions. What it may do on its own is decided by kosa8, not by the bot: reversible steps run and can be undone, and anything that deletes, unblocks or spends waits for a person.

## Templates

| Template | What it does | Highest tier |
|---|---|---|
| `spend-guard` Spend Guard | Warns at 50% and 80% of your spending cap and on a sudden jump; at 100% pauses the three costliest sandboxes and asks an admin before raising the cap. | T3 |
| `lifecycle-janitor` Lifecycle Janitor | Snapshots and sleeps sandboxes idle for 20 minutes; asks before deleting one asleep for 7 days. | T3 |
| `egress-guard` Egress Guard | When an agent keeps hitting blocks (3 in 10 minutes) or a sandbox is killed for egress, pauses it with a snapshot, blocks the host and tells you at once. | T2 |
| `github-task-agent` GitHub Task Agent | Turns on `@kosa8 agent` and `@kosa8 run`: your agent works in a fresh microVM and opens a draft pull request. Needs GitHub connected. | T2 |
| `pr-evidence` PR Evidence | One kosa8 check run on every `@kosa8` pull request: tests, files, egress allowed and blocked, minutes and cost. Needs GitHub connected. | T1 |
| `rl-run-watcher` RL Run Watcher | Drains a stuck RL run's leftover sandboxes and tells you when infrastructure failures climb past 20%. | T1 |
| `cost-digest` Cost Digest | Every Monday, one message: spend against your cap, top labels, sandboxes asleep and what your bots did. | T0 |

The list in the app is ranked for your organization (an org with RL runs sees the RL Run Watcher higher, and says why). Guard bots cost nothing on every plan: their steps are free and a dry run is never billed. A step that starts a sandbox, such as the GitHub Task Agent's agent run, is billed as that sandbox always is, and only within the bot's budget.

## Turn a bot on: plan, dry run, on

Every way in goes through the same three steps. The **plan** says in plain words what the bot watches, each action with its tier, the permissions it uses, how often it checks and what it never does. The **dry run** replays the last 7 days of your real events and lists what the bot would have done. Nothing changes. Then a person presses **Turn on**.

**Web app**

```
1. Open app.kosa8.com → Autopilot.
2. Pick a template, for example Lifecycle Janitor.
3. Read its plan: what it watches, each action with its tier,
   and what it never does.
4. Read the dry run: what it would have done over the last 7 days.
   Nothing changed.
5. Press Turn on.
```

**CLI**

```
kosa8 bots templates                       # best fit first
kosa8 bots add lifecycle-janitor --name dev-janitor --budget 5
# plan → what it would have done over the last 7 days → turn it on? [y/N]

kosa8 bots new "sleep anything idle for 20 minutes unless it's labelled prod"
kosa8 bots runs dev-janitor                # the latest run as a live checklist
kosa8 bots off dev-janitor
```

**curl**

```
# The plan, and a replay of the last 7 days (nothing is saved)
curl -s https://api.kosa8.com/v1/bots/plan \
  -H "Authorization: Bearer $KOSA8_API_KEY" -H 'Content-Type: application/json' \
  -d '{"template": "lifecycle-janitor", "replay": true}'

# Save it as a draft; then a person turns it on
curl -s https://api.kosa8.com/v1/bots \
  -H "Authorization: Bearer $KOSA8_API_KEY" -H 'Content-Type: application/json' \
  -d '{"template": "lifecycle-janitor", "name": "dev-janitor"}'
curl -s -X POST https://api.kosa8.com/v1/bots/bot_…/enable \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

**Python**

```
from kosa8 import Kosa8Cloud

cloud = Kosa8Cloud()  # reads KOSA8_API_KEY

plan = cloud.bots.plan(template="lifecycle-janitor", replay=True)
print(plan["plan"]["summary"])

bot = cloud.bots.create(template="lifecycle-janitor", name="dev-janitor")  # a draft
run = cloud.bots.run(bot["id"])  # a dry run by default: changes nothing, never billed
cloud.bots.enable(bot["id"])     # a person's key only
```

**JavaScript**

```
import { Kosa8Cloud } from '@kosa8/sdk';

const cloud = new Kosa8Cloud(); // reads KOSA8_API_KEY

const { plan } = await cloud.bots.plan({ template: 'lifecycle-janitor', replay: true });
console.log(plan.summary);

const bot = await cloud.bots.create({ template: 'lifecycle-janitor', name: 'dev-janitor' }); // a draft
const run = await cloud.bots.run(bot.id); // a dry run by default: changes nothing, never billed
await cloud.bots.enable(bot.id); // a person's key only
```

**Go**

```
plan, _ := cloud.Bots.Plan(ctx, kosa8.CloudBotPlanOptions{Template: "lifecycle-janitor", Replay: true})
fmt.Println(plan.Plan["summary"])

bot, _ := cloud.Bots.Create(ctx, kosa8.CloudBotCreateOptions{Template: "lifecycle-janitor", Name: "dev-janitor"}) // a draft
run, _ := cloud.Bots.Run(ctx, bot.ID, nil) // a dry run by default: changes nothing, never billed
fmt.Println(run.State)

// A person's key only; otherwise kosa8.ErrHumanApprovalRequired
if _, err := cloud.Bots.Enable(ctx, bot.ID); err != nil {
	log.Fatal(err)
}
```

A new bot is a draft until a person turns it on. Turning one on needs a person's credential ([below]), the `sandboxes:write` scope, GitHub connected for the GitHub templates, and a monthly budget when a step costs money. The SDK calls come with the next release of each SDK; until then use the web app, the CLI, MCP or the API.

## Describe a bot in a sentence

In the app's sentence box, `kosa8 bots new "…"`, or `POST /v1/bots/compile`, write what you want, for example *"sleep anything idle for 20 minutes unless it's labelled prod"* (up to 500 characters). kosa8 turns it into the same spec a template has, checked against the same catalog, and shows you its plan and a dry run. It never saves or turns anything on by itself. A sentence that asks for something no bot may do is refused with the reason.

## Trust tiers

kosa8 sets each action's tier from the catalog. A spec can raise an action to T3 with `"approve": true`; nothing can lower one.

| Tier | Means | Actions |
|---|---|---|
| T0 Observe | Reads and reports. Runs on its own. | Tell the team, the cost digest, export the evidence bundle |
| T1 Fix without loss | Reversible and capped. Runs on its own and is logged. | Sleep a sandbox (with a snapshot), drain a run's sandboxes, the evidence check run, one updating comment |
| T2 Contain | Reversible. Runs on its own, tells you at once, one-click Undo. | Pause a sandbox or the costliest ones, block a host, stop new sandboxes, open a draft pull request, run your coding agent |
| T3 Propose | Asks a person first. No answer in 24 hours means no. | Delete a sandbox, unblock a host, raise the spending cap, freeze the organization |
| T4 Never | Not possible: no bot can do it, whatever its spec says. | See below |

**What bots can never do.** These actions are not in the catalog, and a spec naming one is refused (`400 forbidden_action`): merge, approve or mark ready a pull request; push to a default branch or force-push; widen a token or a permission; spend past the spending cap; email anyone; act on a comment from someone without write access; touch a sandbox labelled `protected` or `prod` (any value), or with `env` or `environment` set to `prod` or `production`.

A bot acts with its own identity: only the scopes its actions need, limited to the labels in its `scope`, so a Janitor scoped to `env=dev` cannot reach any other sandbox even if its spec were wrong. Your plan, spending cap, freeze and egress rules apply to it as they do to you, and every call it makes is in the [audit log](https://docs.kosa8.com/guides/audit/) as `bot:<id>`.

## Approvals: only a person decides

A T3 step parks its run and opens an approval with the exact arguments, the bot's reason and the role it needs (raising the cap, unblocking a host and freezing need an admin). A person approves or denies in the web app, the desktop app or the CLI. No answer in 24 hours is a rejection.

**Web app**

```
Autopilot → the approvals inbox. Each one shows the bot, the action,
its raw arguments and why it asks. Approve or Deny.
No answer in 24 hours means no.
```

**CLI**

```
kosa8 bots approvals                       # what bots are waiting on a person for
kosa8 bots approve appr_…                  # shows the raw arguments, then asks [y/N]
kosa8 bots deny appr_… --reason "keep it"
```

**Python**

```
from kosa8 import Kosa8Cloud, Kosa8HumanApprovalRequiredError

cloud = Kosa8Cloud()  # a key made for you (kosa8 login mints one)

for a in cloud.approvals.list():  # pending, by default
    print(a["id"], a["bot_name"], a["action"], a["args"])

try:
    cloud.approvals.approve("appr_…", reason="checked the sandbox list")
except Kosa8HumanApprovalRequiredError:
    print("this key is not a person's: approve in the app instead")
```

**JavaScript**

```
import { Kosa8Cloud, Kosa8HumanApprovalRequiredError } from '@kosa8/sdk';

const cloud = new Kosa8Cloud(); // a key made for you (kosa8 login mints one)

for (const a of await cloud.approvals.list()) console.log(a.id, a.bot_name, a.action, a.args);

try {
  await cloud.approvals.reject('appr_…', { reason: 'keep it' });
} catch (e) {
  if (e instanceof Kosa8HumanApprovalRequiredError) console.log('approve in the app instead');
  else throw e;
}
```

A person means a dashboard session or an API key made for a member (the one `kosa8 login` mints). Capability tokens, MCP sessions, org keys bound to no member and bots get `403 human_required`. The CLI also refuses to ask when it runs inside an agent or with nobody at the terminal. So an agent can never approve its own action, through any kosa8 surface. The same rule covers turning a bot on and `resume-all`.

## Budgets and the breaker

- **Budget.** Each bot has a monthly budget (`budget_usd`, `--budget` in the CLI). At 80% it tells you; at 100% it pauses itself as `budget_paused` and skips the rest. Steps that cost money do not run until a budget is set.

- **Breaker.** Five failed runs in a row and the bot turns itself off as `broken`. Failures caused by kosa8's own infrastructure never count, and are never billed.

- **Rate and dedup.** At most 30 runs an hour by default (`rate_per_hour`, up to 120), and once per subject per day (`dedup_s`), so one idle sandbox is one run, not sixty.

## Kill switches

From narrow to wide:

1. **One bot off**: `kosa8 bots off NAME`, or the switch in the app. Anyone with `sandboxes:write`, an agent included, may turn a bot off.

2. **Every bot**: `kosa8 bots stop-all` (`POST /v1/bots/pause-all`, the `admin` scope, any credential, so an agent can stop everything). Work already running is left alone. Bringing them back, `kosa8 bots resume-all`, needs a person.

3. **The org freeze** in the [Security Center](https://docs.kosa8.com/guides/cloud-security/): no bot runs at all.

## Run history and undo

Each run shows what started it, every step on the same live checklist the rest of kosa8 uses (pending, running, done, failed, skipped, waiting), its cost and its reason. A T1 or T2 step with an undo has an **Undo** button: it wakes the slept or paused sandbox, removes the bot's own host block, or lifts its block on new sandboxes. From the terminal, `kosa8 bots runs NAME`; over the API, `POST /v1/bot-runs/{id}/steps/{key}/undo`.

## From the CLI

```
kosa8 bots                         # your bots, one line each
kosa8 bots templates               # what you can turn on
kosa8 bots add TEMPLATE            # plan → dry run over the last 7 days → turn on? [y/N]
kosa8 bots new "describe it"       # the same, from a sentence
kosa8 bots on|off NAME
kosa8 bots run NAME [--dry-run]    # run it now and watch its steps
kosa8 bots runs NAME
kosa8 bots approvals               # what bots are waiting on a person for
kosa8 bots approve|deny ID         # a person at a terminal only
kosa8 bots stop-all | resume-all
```

Every command and flag: [`kosa8 bots`](https://docs.kosa8.com/reference/bots/).

## From your agent (MCP)

The [kosa8 Cloud MCP server](https://docs.kosa8.com/guides/cloud-mcp/) has `bot_templates`, `bots_list`, `bot_get`, `bot_propose` (saves a draft from a template or a sentence), `bot_run` (a dry run unless `dry_run: false`), `bot_runs`, `bot_run_status` and `approvals_list` (read-only). There is deliberately no tool to turn a bot on, resume all bots or decide an approval: those are a person's call, and the API refuses MCP for them anyway. An agent proposes; you review the plan and turn it on.

## n8n

The [kosa8 n8n node](https://github.com/kosa8ai/n8n-nodes-kosa8) has an **Autopilot** resource (List Bots, Run Bot with Dry Run on by default, List Runs, Get Run, List Pending Approvals) and a **kosa8 Cloud Trigger** node for **Bot Run Finished** and **Approval Needed**. There is no approve operation, by design: use Approval Needed to tell people where to decide. It comes with the node's next release.

## Webhook events

| Event | Data |
|---|---|
| `bot.run.finished` | `bot_id`, `bot_name`, `run_id`, `state` |
| `bot.approval.requested` | `approval_id`, `bot_id`, `bot_name`, `run_id`, `action`, `args`, `expires_at` |
| `bot.notification` | `bot_id`, `bot_name`, `text` |
| `sandbox.exited` | `id`, `reason`, `cause`: every way a sandbox ends |
| `fork.completed` | `parent`, `created`, `failed`, `sandboxes` |

Subscribe as with any other event: [Webhooks](https://docs.kosa8.com/guides/cloud-webhooks/). A bot's messages (*Tell the team*, the digest) also go to your Slack alert channel when one is set.

## Slack approvals

**Coming soon.** Approve and Deny buttons in a Slack channel you pick, matched to kosa8 members by their Slack email, and only for members whose role covers the action. Until it is switched on, decide in the web app, the desktop app or the CLI; bot messages already reach a Slack alert channel.

See also: [Security Center](https://docs.kosa8.com/guides/cloud-security/), [@kosa8 in issues and pull requests](https://docs.kosa8.com/guides/cloud-github-triggers/), the [HTTP API](https://docs.kosa8.com/api/) (Autopilot) and the public catalog at `GET https://api.kosa8.com/v1/bots/catalog`.

---
Source: https://docs.kosa8.com/guides/autopilot/
