# Deploy

Run rungent in production. The Docker image, how its environment reaches it, the database and secrets, the reverse proxy, and replicas.

An embedded rungent deploys with your JavaScript app. Beside an API in any other language, rungent runs as its own service, `rungent serve`, configured from
environment variables, with its state in Postgres, behind the reverse proxy that already serves
your product.

```text
browser ─> reverse proxy (console.example.com)
             ├─ /rungent/v0/*, /mcp, /skill.md, /llms.txt, /.well-known/… ─> rungent serve ─> Postgres
             └─ everything else ──────────────────────────────────────> your API
rungent serve ─(the user's credential + Rungent-Assertion)─> your API
```

## Run it

```bash
docker run -d --name rungent -p 8080:8080 --env-file rungent.env ghcr.io/rungent/rungent-server:v0.4.0
```

Images are tagged with each release (`v0.4.0`) and `latest`. The image runs `rungent serve` as the
`node` user on port 8080. Without Docker, `npx rungent serve` runs the same server on
Node.js 24.

`GET /healthz` answers `ok`, at the root even when rungent is served below a prefix; the image's
health check calls it. On `SIGTERM` the server stops taking requests, lets runs in progress
finish and exits. To build on your own base image, pass `--build-arg BASE_IMAGE=… --build-arg RUNGENT_VERSION=0.4.0`
to the `Dockerfile` in `packages/rungent` of the rungent repository.

## Set the environment

`rungent serve` reads its settings from `RUNGENT_*` environment variables; what each one means is on
[Configure](configure.md#where-each-setting-lives). Five are required: `RUNGENT_URL`,
`RUNGENT_HOST_ORIGIN`, `RUNGENT_SIGNING_KEY`, `RUNGENT_SECRET` and `RUNGENT_DATABASE_URL`. Most
deployments also set `RUNGENT_HOST_BASE_URL`, so rungent reaches your API on the internal network,
and `RUNGENT_MODELS`.

```bash
# rungent.env
RUNGENT_URL=https://console.example.com
RUNGENT_HOST_ORIGIN=https://console.example.com
RUNGENT_HOST_BASE_URL=http://api.internal:8000
RUNGENT_SIGNING_KEY={"kty":"OKP","crv":"Ed25519","kid":"rungent-2026-11",…}
RUNGENT_SECRET=…
RUNGENT_DATABASE_URL=postgres://rungent:…@db.internal/rungent
RUNGENT_MODELS={"chain":[…]}
```

A variable that is missing, not valid JSON or out of range stops the server at start with a
message naming it, and exit code 2. Keep `RUNGENT_SIGNING_KEY`, `RUNGENT_SECRET`,
`RUNGENT_PREVIOUS_SECRET`, `RUNGENT_DATABASE_URL` and `RUNGENT_MODELS` (it holds API keys) in your secret
store.

## Database and secrets

Use Postgres in production. rungent keeps conversations, approvals, deferred tasks, settings and the
knowledge index there, in its own `rungent_*` tables, which it creates and upgrades at start. Give it
its own database or schema. SQLite cannot be shared by replicas.

The signing key and its rotation are on [Acting as the user](acting-as-the-user.md#keys-and-rotation).
To rotate the settings secret, set the new value as `RUNGENT_SECRET` and the old one as
`RUNGENT_PREVIOUS_SECRET` and deploy: the new secret seals, both unseal, and saved settings are
sealed again with the new one when first read. Once any run has read them, remove
`RUNGENT_PREVIOUS_SECRET`. Settings sealed with a secret rungent no longer has answer
`503 settings_unreadable` until an admin calls `DELETE /rungent/v0/settings`.

## Route the rungent paths

Send these paths on your product's origin to rungent, unchanged, and everything else to your API:

| Path | What it serves |
|---|---|
| `/rungent/v0/*` | The assistant's HTTP API and its event streams |
| `/mcp` | MCP over streamable HTTP |
| `/skill.md`, `/llms.txt` | Documents generated from your catalog |
| `/.well-known/rungent-keys.json` | rungent's public keys |
| `/.well-known/oauth-protected-resource/mcp` | Only with `RUNGENT_MCP_AUTHORIZATION_SERVERS` |

Runs stream server-sent events, so turn off response buffering and allow long reads. With nginx:

```nginx
location ~ ^/(rungent/v0/|mcp$|skill\.md$|llms\.txt$|\.well-known/(rungent-keys\.json|oauth-protected-resource/mcp)$) {
    proxy_pass http://rungent:8080;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_buffering off;
    proxy_read_timeout 1h;
}
```

Forward the `Authorization` and `Cookie` headers untouched: they are the user's credential. To
serve rungent below `/assistant`, set `RUNGENT_BASE_PATH=/assistant` and
`RUNGENT_URL=https://console.example.com/assistant`, proxy `/assistant/`, and give the web client
`createClient({ baseUrl: '/assistant' })`.

## Run several replicas

Several replicas can share one Postgres: an approval runs once, and one conversation is never
driven by two replicas at a time. Two things stay in one replica's memory:

- **MCP sessions.** Route every request with the same `Mcp-Session-Id` to the same replica
  (sticky sessions, or `sessionAffinity: ClientIP` on a Kubernetes Service). Elsewhere it gets
  `404 session_not_found`, and the client opens a new session.
- **Model rests.** Each replica learns on its own that a model endpoint is failing.

On Kubernetes, run the image as a Deployment with its variables from a Secret:

```yaml
containers:
  - name: rungent
    image: ghcr.io/rungent/rungent-server:v0.4.0
    ports: [{ containerPort: 8080 }]
    envFrom: [{ secretRef: { name: rungent-env } }]
    readinessProbe: { httpGet: { path: /healthz, port: 8080 } }
```

## Check it

- `npx rungent check --openapi https://console.example.com/api/openapi.json` passes.
- `GET /rungent/v0/catalog` with a user's token lists that user's operations.
- A write through the dock shows an approval card, and your API logs `actor = rungent` with the
  approval id.
- `/skill.md` renders, and a coding agent connects to `/mcp`.

## Where to go next

- [Configure](configure.md#choose-models): the model chain, and the admin page that changes it.
- [Testing](testing.md) measures the agent against your deployment.
