---
title: "Protection and previews"
description: "Who can start a run or a conversation, and how to test a branch."
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.cloudraker.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Protection and previews

## Protection modes

`protection:` in a leaf `agent.yml` sets who can start a run with `POST /{base}/{agent}`. Every other route keeps its own rule in every mode.

| Mode              | Start a run                             | Notes                                                                                                                                                      |
| ----------------- | --------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `token` (default) | A `crk_` key with the `run` scope.      | The key can list allowed agents.                                                                                                                           |
| `public`          | Anyone, with no token.                  | The request cannot send `secrets` or `model` (422). Lint refuses `data.create_schemas` and `workspace_act_as` on a public agent.                                 |
| `access`          | A caller that passed Cloudflare Access. | The gateway verifies the Access JWT in `cf-access-jwt-assertion`. A bad JWT answers `403 access_denied`. The Access email becomes `metadata.access_email`. |

| Route                           | Auth in every mode                                                      |
| ------------------------------- | ----------------------------------------------------------------------- |
| `GET /_run/{id}` and its stream | The `rrt_` read token of the run, or a `crk_` key with `read`.          |
| `POST /_run/{id}` (next turn)   | A `crk_` key with `run`. Your backend sends turns, never the browser.   |
| `/_cv/*` (web chat)             | A Turnstile check at the start, then the `cvs_` session token of one conversation. Read [Web chat](https://docs.cloudraker.com/run/guides/web-chat). |
| `DELETE /_run/{id}`             | A `crk_` key with `cancel`.                                             |
| `/_git/*`, `/_secrets/*`        | A `crk_` key with `git` or `secrets`.                                   |

## Tokens

| Token           | Prefix | Scope                                                                                                         | Lifetime                                                       |
| --------------- | ------ | ------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
| API key         | `crk_` | `run`, `read`, `cancel`, `git`, `secrets`, `admin`, `preview`, `act_as`. Optional list of agents.             | Until revoked. Optional expiry.                                |
| Exchanged token | `crt_` | The scopes of a [trust](https://docs.cloudraker.com/run/guides/environments#add-a-trust). The same routes as a `crk_` key with those scopes. | 15 minutes by default.                                         |
| Run read token  | `rrt_` | `GET /_run/{id}` and its stream, for one run.                                                                 | Until the run is deleted.                                      |
| Embed key       | `rek_` | Starts web chat conversations on one front door, from the door origins only. Public.                          | Until revoked.                                                 |
| Session token   | `cvs_` | One web chat conversation, from one origin.                                                                   | The door `session.idle_ttl` with no renewal, 24 hours at most. |

Create and revoke `crk_` keys on the [API keys](https://app.cloudraker.com/api-keys) page of Dash. `rakerun token create` also creates a key. The value of a live key shows once, and only its hash is stored. Run has no test mode: a test key answers `403 test_key_not_allowed`. Send every token as `Authorization: Bearer <token>`. Query-string tokens are refused. A browser WebSocket never sends the `cvs_` token: it opens with a one-time socket ticket.

The `x-run-as` header names the person that a run acts as. It needs a `crk_` key with the `act_as` scope and one email address. A preview host refuses it with `act_as_preview`.

Every `POST /{base}/{agent}` answer carries the run's `read_token`. A streamed answer carries it in the `x-run-read-token` header.

## A chat for the people on your site

To let visitors of your site talk to your agents, use a [front door](https://docs.cloudraker.com/run/guides/front-doors) with `channels.web` and the [web chat](https://docs.cloudraker.com/run/guides/web-chat). The browser gets a public embed key and a short session token, never a `crk_` key. Turnstile, the door origins, the guards and the door limits protect the door.

The `rrt_` token reads one run and nothing else. Give it to a browser that shows a run that your backend started. Your backend keeps the `crk_` key and sends the turns.

## Previews

A push to a branch other than `main` deploys a preview of the whole repo. The preview host is:

```text
https://{branch}--{org}.cloudraker.run
```

| Rule        | Detail                                                                                                                                                                 |
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Branch slug | Lowercase. Each run of characters outside `a-z0-9` becomes `-`. `feature/new-intake` becomes `feature-new-intake`. The label `{slug}--{org}` is at most 63 characters. |
| Keys        | The same `crk_` keys, with the `preview` scope. A preview needs the key for every `protection:` mode, also `public` and `access`.                                      |
| Triggers    | HTTP and inbound (`/{base}/{agent}/_inbound/{source}` on the preview host). No schedule.                                                                              |
| Front doors | A preview has no doors. Phone numbers, email aliases, Slack, Teams and embed keys reach only the live doors. The preview host answers `404` on `/_cv` and `/_chat`. The console can still test an agent of the preview in a chat. |
| Data        | A preview does not sync `_schemas`. Preview runs use the live schema definitions. They do not get `data.define_schema` or `save_code`.                                  |
| Knowledge   | A preview does not index `knowledge/`. Preview runs search the live index.                                                                                             |
| Act as      | A preview run never gets act-as tools.                                                                                                                                 |
| Runs        | A preview run needs a token with the `preview` scope on every host. A preview host shows preview runs only.                                                            |
| Secrets     | The same vault as production.                                                                                                                                          |
| Delete      | Delete the branch. A removed preview answers `404 preview_not_found`.                                                                                                  |

```bash
git -c http.extraHeader="Authorization: Bearer $RUN_TOKEN" \
  push "https://$ORG.cloudraker.run/_git/hello-agents" feature/new-intake

curl -N -X POST "https://feature-new-intake--$ORG.cloudraker.run/hello-agents/hello" \
  -H "Authorization: Bearer $RUN_TOKEN" \
  -H "Accept: text/event-stream" \
  -H "Content-Type: application/json" \
  -d '{ "input": "Test the branch." }'
```

The console uses the same previews. Each saved change builds a preview of its draft branch. A failed preview does not undo the save: retry the preview from the change.

> **Note**
>
> Org slugs cannot contain `--`, so a preview host never matches an org host.

Source: https://docs.cloudraker.com/run/guides/protection-and-previews/index.mdx
