--- title: Set up Agent Relay --- > [!NOTE] > Agent Relay is in [beta](../reference/feature-stages.md#beta) and requires a Premium license. > To try it, [request a Premium trial](https://coder.com/trial). This guide is for Coder administrators who deploy Agent Relay against an existing Coder deployment. It covers the steps that are the same for every provider: the service account, provisioners, template rules, installation, and verification. Provider-specific steps live on the [Claude Code](./claude-code.md) and [Cursor](./cursor.md) pages. ## Before you begin > [!IMPORTANT] > Only a user with the Coder `owner` role can create service accounts and mint their tokens. You need: - A Coder deployment with a Premium license, on version 2.39 or later. - Agent Relay v0.16.0 or later. - Somewhere to run the Agent Relay container: a Kubernetes cluster that you can reach with `kubectl` and `helm`, or a Docker host. - The [Coder CLI](https://coder.com/downloads), signed in as an `owner`. - An account with the provider you want to serve. Refer to the requirements on the [Claude Code](./claude-code.md#requirements) or [Cursor](./cursor.md#requirements) page. ## Plan your deployment Choose one of these layouts: - **One relay per deployment.** One relay serves every organization and both providers with a single service account. - **One relay per organization.** Each relay has its own service account and its own provider credentials, which isolates organizations from each other. For example, a deployment with three organizations runs three relays. In either layout, never give two relays the same provider credentials. Both relays claim the same sessions and compete over the same workspaces. Plan provisioner capacity for each pool, because every pool you add can start more builds at once. Refer to [Provision capacity for Agent Relay](#step-2-provision-capacity-for-agent-relay). ## Step 1: Create a service account Agent Relay needs no site-wide role. At startup, it checks that its service account has the permissions that its pools need. In every organization that a pool names, the service account needs these permissions: | Resource | Actions | |-----------------------|-----------------------------------------------| | `organization_member` | `read` | | `workspace` | `create`, `read`, `start`, `update`, `delete` | | `workspace_secret` | `create` | On every template that a pool names, the service account needs `read` and `use`. By default, a new template grants `use`, which includes `read`, to its organization's `Everyone` group, so a service account in the organization already has both. Grant them in the template's permissions only if the template doesn't give the `Everyone` group access. The `organization-admin` role in each organization covers all of these permissions. To grant less, create an organization-scoped [custom role](../admin/users/groups-roles.md#custom-roles) with only the permissions above. 1. Create the service account in the organization that Agent Relay serves: ```shell coder users create --service-account --username agent-relay --org ``` 1. Add the service account to every other organization that a pool names. 1. Assign the `organization-admin` role, or your custom role, in each of those organizations. 1. Create a long-lived token for the service account: ```shell RELAY_TOKEN=$(coder tokens create --user agent-relay --name agent-relay-token --lifetime 8760h) ``` 1. If you install with Helm, store the token in a Kubernetes secret: ```shell kubectl create secret generic agent-relay-coderd \ --namespace coder \ --from-literal=session-token="$RELAY_TOKEN" ``` The Helm chart doesn't accept the token as a plain value. Agent Relay verifies organization permissions at startup. A missing organization permission stops the daemon. For example, a service account without the `workspace_secret` `create` permission stops it with `missing coderd capabilities [set-workspace-secrets[]]`. Agent Relay verifies template permissions per pool. A missing template permission degrades only that pool, and the pool recovers when you fix the template. Why Agent Relay needs some of these permissions: - `workspace` `update` lets it extend the autostop deadline of workspaces with an active session. It checks for this permission in every organization at startup, even if no template uses keepalive. - `workspace_secret` `create` lets it deliver each session's provider credential to the workspace as an ephemeral workspace build secret. Agent Relay checks the Coder version once, at startup, to decide how to deliver credentials, so restart Agent Relay after you upgrade Coder. ## Step 2: Provision capacity for Agent Relay Agent Relay builds run on your Coder provisioners, and time spent waiting for a free provisioner counts against each session's build deadline. We recommend dedicated [external provisioners](../install/operate/provisioners/index.md) for Agent Relay templates, so relay builds don't compete with human workspace builds. Each provider page explains how to size capacity for its pools: - [Claude Code provisioner capacity](./claude-code.md#provisioner-capacity) - [Cursor provisioner capacity](./cursor.md#provisioner-capacity) To run a dedicated set of provisioners on Kubernetes: 1. Create a provisioner key with a tag for Agent Relay: ```shell coder provisioner keys create relay-key --org --tag workload=agent-relay ``` Copy the key from the output. Coder shows it once. 1. Store the key in a Kubernetes secret: ```shell kubectl create secret generic agent-relay-provisioner-key \ --namespace coder \ --from-literal=key="" ``` 1. Create a `provisioner-values.yaml` file: ```yaml coder: env: - name: CODER_URL value: "https://coder.example.com" # One provisioner runs one build at a time. replicaCount: 10 provisionerDaemon: pskSecretName: "" keySecretName: agent-relay-provisioner-key keySecretKey: key ``` The provisioners pick up the `workload=agent-relay` tag from the key. 1. Install the `coder-provisioner` Helm chart with a version that matches your Coder server version: ```shell helm install coder-provisioner coder-v2/coder-provisioner \ --namespace coder \ --version \ --values provisioner-values.yaml ``` 1. When you push an Agent Relay template, use the same tag: ```shell coder templates push