# Connect to Pyrula Cloud

> Scaffold an app, export one key, run pyrula dev and open the run in Pyrula Cloud.

Source: https://docs.pyrula.io/getting-started/cloud/

Pyrula Cloud is invite-only during the beta. Join the beta access list at
[cloud.pyrula.io/signup](https://cloud.pyrula.io/signup) and Pyrula emails your invite when it is ready.

## Scaffold, connect and run

In Cloud, open **Setup** for your project and environment and copy the key. A key is for one
environment; its runs appear only there.

A worker sends prompts, replies and tool traffic by default (`full`); to lower that, see
[What leaves your runtime](https://docs.pyrula.io/getting-started/what-leaves-your-runtime.md#who-sets-it).

```bash
pip install "pyrula[agents,cloud]"
pyrula init
export PYRULA_CLOUD_API_KEY="<key>"
pyrula dev app.py
```

`pyrula init` prints `wrote app.py`; the scaffold talks to a scripted model, so no provider key is needed. `pyrula dev` runs the agent once and prints a link to the run:

```text
Target: app.py:support
Using SQLite store .pyrula/dev.db - runs survive a restart; --fresh starts empty
Cloud: connecting to <origin>
Cloud: connected to <origin> as worker <worker-id> (project <project-id>, environment <environment>)
  support  submitted  <run-id>
  tool  lookup_order
  completed - Order A-1042 has shipped. Total $42.00.
Cloud: run <run-id> -> <link>
```

## When it does not connect

If Cloud is unreachable or refuses the key, `pyrula dev` keeps running locally and prints one
line saying why. It retries an unreachable Cloud with backoff and sends the runs that finished
meanwhile once connected. To check setup without starting anything:

```bash
pyrula dev --check
```

It exits 1 if a check failed. Fixes, and what to check when nothing appears in the UI, are in [Troubleshooting](https://docs.pyrula.io/getting-started/troubleshooting.md).

Next: [Add one boundary to an existing app](https://docs.pyrula.io/getting-started/existing-app.md), or
[send existing traces](https://docs.pyrula.io/getting-started/otel.md) without installing pyrula.

## In your own code

For an existing runtime, `pip install "pyrula[cloud]"` and set `PYRULA_CLOUD_API_KEY` where your
workers start. A malformed key stops start-up with a `ConnectConfigError` naming the variable.

## Settings

| Variable | Effect |
|---|---|
| `PYRULA_CLOUD_URL` | Cloud to connect to. Defaults to `https://api.pyrula.io`; set it for self-hosting. |
| `PYRULA_CLOUD_CONTROL` | Unset, `derived` or `full`: report and accept cloud commands. `telemetry`: report only. `off`: no connector is built. |
| `PYRULA_SERVICE_NAME` | The service your workers report under: 1 to 63 letters, digits, `.`, `_` and `-`, starting with a letter or digit, lowercased. Falls back to `OTEL_SERVICE_NAME`, then `default`. See [Worker identity](#worker-identity). |
| `PYRULA_CLOUD_CAPTURE` | Cap on the data-sent setting (capture level), see [What leaves your runtime](https://docs.pyrula.io/getting-started/what-leaves-your-runtime.md#who-sets-it). |
| `PYRULA_CLOUD_LIVE_TEXT` | `on` (default) or `off`. Forwards live text (`block:start`, `block:delta`, `block:stop`) while a reply streams, at `full` only. |
| `PYRULA_CLOUD_ALLOWED_RUNNERS` | Comma-separated workflow/agent names Cloud may act on. Unset allows all. |
| `PYRULA_CLOUD_OUTBOX_PATH` | Outbox location, or `off` to keep delivery to the life of the process. |
| `PYRULA_CLOUD_OUTBOX_HIGH_WATER_BYTES` | Default 256 MB. Above it, `submit()` raises `BackpressureRejected`; claimed work keeps running and drains the backlog. |
| `PYRULA_CLOUD_OUTBOX_HARD_CAP_BYTES` | Default 2x high water. Above it, the outbox refuses new events and claiming stops. |
| `PYRULA_CLOUD_OUTBOX_SYNC` | `full` fsyncs every outbox write. |
| `PYRULA_CLOUD_OUTBOX_MAX_AGE_S` | How long an unacked stored event is kept. Default 7 days. |
| `PYRULA_CLOUD_DRAIN_DEADLINE_S` | Most time a shutdown spends sending buffered events. Default 5. |
| `PYRULA_REDACT_KEYS` | Extra field names to redact ([redaction policy](https://docs.pyrula.io/getting-started/what-leaves-your-runtime.md#your-redaction-policy)). |

## Worker identity

Cloud's Workers page lists one row per logical worker, named by a service and a component, and
each running process is an instance of it. `PYRULA_SERVICE_NAME` names the service, shared by
every replica of a deployable. The component is the kind of worker (`agents`, `router`,
`workflows`, `kafka-workflows` and so on), so an agent worker and a workflow worker in one
process are two logical workers of one service. Restarts and rollouts reuse an instance's slot
and add no rows; in a container, keep `PYRULA_CLOUD_OUTBOX_PATH` on a persistent volume so a
restart after a crash can find it.

When two workers of one kind in one process serve different workflows, give each its own name
with `component=` (every worker class takes it):

```python
orders = WorkflowWorker(workflows=[charge_order], store=store, component="orders")
refunds = WorkflowWorker(workflows=[issue_refund], store=store, component="refunds")
```

## Not losing events

Critical events (run lifecycle, step results, tool and usage results, terminals) go to a local
outbox before they're sent, and are deleted once Cloud accepts them or
`PYRULA_CLOUD_OUTBOX_MAX_AGE_S` passes. Token deltas and other live-stream events aren't
stored; when one is dropped, Cloud is told where the gap is. A restarted runtime sends the rows
a killed process left for the same project and environment.

The outbox is on by default at `$XDG_STATE_HOME/pyrula/` (`~/.local/state/pyrula/`), one file per
project, holding events already redacted for your capture level as plaintext SQLite (file `0600`,
directory `0700`).

- **Containers:** put `PYRULA_CLOUD_OUTBOX_PATH` on a persistent volume, or the outbox dies with the container.
- **Power loss:** set `PYRULA_CLOUD_OUTBOX_SYNC=full` to fsync each event.
- **Shutdown:** the runtime drains for up to `PYRULA_CLOUD_DRAIN_DEADLINE_S`; with an outbox, whatever is left goes out on the next start.

Cloud answers over its ingest limits (1,200 requests a minute per runtime, 12,000 per project)
with a `429`, and the connector backs off and retries without losing stored events. Over the
monthly run quota a run still executes on your worker, but Cloud stores none of its events.

### One store per project and environment

A run store belongs to one project and environment. The first runtime to register against an
unbound store binds it. Bind a production store first, so a laptop or CI job holding a
production key can't do it by accident:

```bash
pyrula store binding show
pyrula store binding set --project P --environment E
pyrula store binding clear
```

`clear` warns that the store's history will go to whichever environment binds next. Stop that
store's workers first.

Give each environment's workers their own store: a separate Valkey, a separate database index
on a standalone server, or a key namespace (`PYRULA_VALKEY_NAMESPACE` or `--namespace`), the
only option on a cluster. A worker whose key belongs to another project or environment runs
nothing from the store, accepts no control, logs an ERROR and reports not ready on `/readyz`.

- A Valkey ACL limiting a runtime to `~<namespace>:*` keeps it out of other namespaces. The
  store needs `+eval +evalsha +script|load` and sends no `FUNCTION` command
  ([recipe](https://docs.pyrula.io/getting-started/managed-valkey.md#when-the-server-refuses-scripts)).
