# Cloud for Bots: how to use it (for bots)

You are connected to Cloud for Bots: one key, one MCP server, many tools. Use them when your own chat session is not enough.

## Which tool when
- **sandbox**: heavy or long work (code, installs, data jobs). It pauses instead of dying, so files survive. Each `run` is up to 120 s; use `background: true` for longer jobs and check back.
- **store**: save progress and results (`set`/`get`). Save after every step so you can resume after a crash or a new session.
- **inbox, queue, cron**: wake up later. `inbox` gives you a URL that webhooks and other bots can POST to; messages land in queue `inbox.<name>`. `cron` runs on a schedule or a one-off `timer`. Read with `queue` `pull`, then `ack` when done.
- **lock, rate**: stop bots colliding. `lock` = one writer at a time. `rate` = shared limits like "6/6h" across all your bots.
- **secrets + fetch**: never paste API keys into chat or code. Store once with `secrets` `set` (with `allowed_hosts`), then call APIs with `fetch` using `{{secret:NAME}}`.
- **browser**: sites that need a login. Sessions keep cookies between calls.
- **handoff**: when a human is needed (captcha, 2FA). Watch-only on free keys.
- **ledger, replay, loop_*, budget_***: safety. Record runs in `ledger`, check repeats with `loop_check_step`, cap spend with `budget_open_budget` and `budget_reserve`, review with `replay`.

## Pattern 1: long job with resume
1. `store` get ns `jobs`, key `<job>` -> last finished step (none = start at 0).
2. For each remaining step: `sandbox` run it, then `store` set `{"step": n, "result": ...}`.
3. If you crash or the chat ends, start again at step 1. You skip finished steps.

## Pattern 2: webhook-driven bot
1. `inbox` create name `orders` -> give the URL to the other service.
2. `cron` set (or `timer`) with `{queue: "wake.orders"}` if you need a nudge, or just check on each run.
3. `queue` pull `inbox.orders`, handle each message, then `ack` its id. Un-acked messages come back.

## Pattern 3: safe posting with a rate limit
1. `lock` acquire `post` (ttl_s 60). If you do not get it, another bot is posting: stop.
2. `rate` take `posts` limit `6/6h`. If not allowed, wait `retry_after_s`.
3. `fetch` the posting API with `{{secret:POST_TOKEN}}`.
4. `ledger` record the run, then `lock` release with the token.

## Rules of thumb
- Save to `store` before and after anything slow.
- Ack queue messages only after the work is done.
- Ask your human before spending money or posting publicly.
- Full reference: https://cloudforbots.com/llms-full.txt
