You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 4d1886b
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: README.md
+6-3Lines changed: 6 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -125,18 +125,21 @@ By default, `copilot` utilizes Claude Sonnet 4.5. Run the `/model` slash command
125
125
126
126
The Copilot CLI is also available as a container image that runs the CLI as a headless server for Copilot SDK clients. Images are published to `ghcr.io/github/copilot-cli` for `linux/amd64` and `linux/arm64`. This image is for connecting SDK clients to a server, not for interactive terminal use.
127
127
128
-
Set a connection token and a GitHub token, then start the server:
128
+
Client apps use `COPILOT_CONNECTION_TOKEN` to connect to the Copilot server. Sessions use a separate GitHub token to access GitHub Copilot. To start the server, generate a random connection token:
Set `COPILOT_GITHUB_TOKEN` in your environment before running the command. For version-pinned deployments, use a release tag instead of `latest`. See the [container image guide](./container/README.md) for SDK connection examples, configuration, security considerations, and build instructions.
138
+
On Windows, use the [PowerShell example](./container/README.md#quick-start).
139
+
140
+
For a local trial, set `COPILOT_CONNECTION_TOKEN_GENERATE=true` to print a generated connection token at startup. On [Kubernetes](./container/README.md#running-on-kubernetes), set `COPILOT_CONNECTION_TOKEN` from a Secret.
141
+
142
+
For GitHub authentication, your backend can pass each user's GitHub token when it creates or resumes an SDK session. To use one default identity instead, export `COPILOT_GITHUB_TOKEN` and add `-e COPILOT_GITHUB_TOKEN` before the image name. See the [container image guide](./container/README.md) for SDK examples, multi-user deployment, and release tags.
@@ -18,25 +18,38 @@ Images are available for `linux/amd64` and `linux/arm64`. Tags are mutable: runn
18
18
19
19
## Quick start
20
20
21
-
Start the server with a secret that clients must present, and a token that lets the CLI use Copilot (see [Configuration](#configuration)):
21
+
Start the server with a random shared secret. SDK clients present this value as `connectionToken`; it controls who can connect, not which GitHub account a session uses. The entrypoint rejects values that look like GitHub tokens.
The server waits for an SDK client. No GitHub credential is needed to connect or ping. For example, install the Node.js SDK (`npm install @microsoft/copilot-sdk`) and run this client with the same `COPILOT_CONNECTION_TOKEN` in its environment.
The other Copilot SDKs can connect to a running server in the same way. See the [SDK documentation](https://github.com/github/copilot-sdk).
62
+
To use one GitHub account as the default for sessions, export `COPILOT_GITHUB_TOKEN` and add `-e COPILOT_GITHUB_TOKEN` before the image name. For a multi-user application, supply credentials per session instead.
63
+
64
+
### Generate a token for local use
65
+
66
+
With an image [built from this source](#building-locally), set `COPILOT_CONNECTION_TOKEN_GENERATE=true` to print a fresh connection token at startup:
67
+
68
+
```sh
69
+
docker run --rm --name copilot-local -p 127.0.0.1:4321:4321 \
Use the value after `Generated COPILOT_CONNECTION_TOKEN=` as the SDK's `connectionToken`. If running detached, read it with `docker logs copilot-local`. **Anyone who can read those logs can see the token**, and restarting the container generates a different one. Use a managed secret for shared deployments. `COPILOT_CONNECTION_TOKEN_GENERATE` must be `true` or `false`, and cannot be enabled when `COPILOT_CONNECTION_TOKEN` is set.
74
+
75
+
## Serving multiple users
76
+
77
+
Keep the port and connection secret private to your backend. The backend authenticates each user, records which sessions they own, and checks ownership before accessing, resuming, or deleting a session. A connection token admits a client to the server; it does not authorize access to an individual session.
78
+
79
+
Leave `COPILOT_GITHUB_TOKEN`, `GH_TOKEN`, and `GITHUB_TOKEN` unset on the server. In your backend, use `mode: "empty"` as above and pass the authenticated user's GitHub token when creating or resuming their session. For example, on a connected client:
80
+
81
+
```js
82
+
constsession=awaitclient.createSession({
83
+
github: { token:user.githubToken }, // From your backend's authentication flow
84
+
tools: { availableTools: [] },
85
+
});
86
+
```
87
+
88
+
Only enable tools that enforce the user's permissions. Sessions have separate histories and can have separate GitHub identities, but their tools run as the same OS user. If mutually untrusted tenants need shell or filesystem access, give each tenant a separate container with its own workspace, `COPILOT_HOME`, credentials, and connection secret. See the [SDK multi-tenancy guide](https://docs.github.com/en/copilot/how-tos/copilot-sdk/setup/multi-tenancy).
50
89
51
90
## Configuration
52
91
53
92
Configure the server with environment variables. Arguments after the image name are appended to the `copilot` command line, for example `--log-level debug`.
54
93
55
94
| Variable | Default | Description |
56
95
| --- | --- | --- |
57
-
|`COPILOT_CONNECTION_TOKEN`| required | Secret that clients must present to connect. The container refuses to start without it. |
96
+
|`COPILOT_CONNECTION_TOKEN`| unset | Required. Shared secret that SDK clients must present to connect. |
97
+
|`COPILOT_CONNECTION_TOKEN_GENERATE`|`false`| Set to `true` to generate and print a fresh token at startup for [local use](#generate-a-token-for-local-use). Cannot be combined with `COPILOT_CONNECTION_TOKEN`. |
58
98
|`COPILOT_PORT`|`4321`| Port the server listens on inside the container, from 1024 to 65535. |
59
-
|`COPILOT_GITHUB_TOKEN`, `GH_TOKEN`, `GITHUB_TOKEN`|| Token the CLI uses to authenticate with GitHub. The first one that is set wins. A [fine-grained personal access token with the "Copilot Requests" permission](../README.md#launching-the-cli) works. |
99
+
|`COPILOT_GITHUB_TOKEN`, `GH_TOKEN`, `GITHUB_TOKEN`|unset | Optional server-wide GitHub identity for sessions without their own credential. The first variable set wins. A [fine-grained personal access token with the "Copilot Requests" permission](../README.md#launching-the-cli) works. |
60
100
|`COPILOT_HOME`|`/home/copilot/.copilot`| Where the CLI stores its configuration and state. |
61
101
62
102
The image is pinned to one CLI version, so auto-update is off (`COPILOT_AUTO_UPDATE=false`). Any other variable listed by `copilot help environment` also works, such as the `COPILOT_PROVIDER_*` variables for using your own model provider.
@@ -66,24 +106,87 @@ Paths in the image:
66
106
-`/home/copilot/workspace` is the working directory. Mount a project here to let the agent work on it.
67
107
-`/home/copilot/.copilot` holds configuration and state. Mount a volume here to keep them across containers.
68
108
69
-
The container runs as the non-root user `copilot` (uid 10001), so bind mounts must be writable by that user. Git is configured to trust only `/home/copilot/workspace`, allowing Git operations on a mounted repository even when its host UID differs. This is an exact-path exception, not a wildcard; mount repositories at the workspace path.
109
+
The container runs as the non-root user `copilot` (uid 10001), so any mounted workspace or state directory it writes to must be writable by that user.
70
110
71
111
To run another `copilot` command instead of the server, override the entrypoint:
72
112
73
113
```sh
74
114
docker run --rm --entrypoint copilot ghcr.io/github/copilot-cli:latest --version
75
115
```
76
116
117
+
## Running on Kubernetes
118
+
119
+
Create the connection secret as a Kubernetes Secret. `--from-literal` stores it without a trailing newline:
Set `COPILOT_CONNECTION_TOKEN` from the Secret and expose the server inside the cluster:
127
+
128
+
```yaml
129
+
apiVersion: apps/v1
130
+
kind: Deployment
131
+
metadata:
132
+
name: copilot
133
+
spec:
134
+
replicas: 1
135
+
selector:
136
+
matchLabels:
137
+
app: copilot
138
+
template:
139
+
metadata:
140
+
labels:
141
+
app: copilot
142
+
spec:
143
+
containers:
144
+
- name: copilot-server
145
+
image: ghcr.io/github/copilot-cli:latest
146
+
env:
147
+
- name: COPILOT_CONNECTION_TOKEN
148
+
valueFrom:
149
+
secretKeyRef:
150
+
name: copilot-connection
151
+
key: token
152
+
ports:
153
+
- containerPort: 4321
154
+
readinessProbe:
155
+
tcpSocket:
156
+
port: 4321
157
+
---
158
+
apiVersion: v1
159
+
kind: Service
160
+
metadata:
161
+
name: copilot-server
162
+
spec:
163
+
selector:
164
+
app: copilot
165
+
ports:
166
+
- port: 4321
167
+
```
168
+
169
+
SDK clients in the same namespace connect to `copilot-server:4321` with the same token.
170
+
171
+
- **Service links.** The `copilot-server` Service generates `COPILOT_SERVER_PORT` rather than overriding the container's `COPILOT_PORT` default.
172
+
- **Rotation.** After updating the Secret, run `kubectl rollout restart deployment/copilot` so new pods pick up the token, and update clients to use the same value.
173
+
- **Replicas.** Each pod keeps its own sessions under `/home/copilot/.copilot`. Run one replica per server, or route each user's sessions to the same pod. Mount a persistent volume there to keep sessions across restarts.
174
+
- **Network access.** Keep the Service `ClusterIP` and limit which pods can reach it, for example with a NetworkPolicy.
175
+
77
176
## Security
78
177
79
178
- The server listens on all interfaces inside the container, and anyone who can reach the port and knows the token can run agent tools in the container. Publish the port on loopback (`-p 127.0.0.1:4321:4321`) or on an isolated container network, and use a long random token.
80
-
- The connection is plain TCP without TLS, so the token is sent unencrypted. Keep the traffic on a trusted network, or terminate TLS in front of the container.
179
+
- The connection is plain TCP without TLS. Both the connection secret and any GitHub credentials sent by the SDK travel unencrypted. Keep the traffic on a trusted network, or protect it with TLS.
81
180
- Agent tools run inside the container with the permissions of the `copilot` user. Treat the container as the sandbox and give it only the files and credentials the agent needs.
82
181
83
182
## Waiting for the server
84
183
85
184
A published port can accept TCP connections before the server is ready to answer, for example behind Docker Desktop's port proxy. When you wait for the container to start, for instance with Testcontainers, check with a real client call such as `ping` instead of only checking that the port is open.
86
185
186
+
## Troubleshooting on Apple Silicon
187
+
188
+
If the server logs `qemu: uncaught target signal 11`, check whether `DOCKER_DEFAULT_PLATFORM` or a `--platform` flag forces `linux/amd64`. The image includes a native ARM64 build. Remove the override or pass `--platform linux/arm64` to `docker run` before the image name.
189
+
87
190
## Verifying an image
88
191
89
192
Images are published with a build provenance attestation:
The attestation is stored in the registry next to the image, so the package's tag list also shows a `sha256-<digest>` tag. That tag holds the attestation, not an image to run.
96
199
97
-
The image contains the `copilot` binary from the matching GitHub release, which the build verifies against the release's `SHA256SUMS.txt`. The license is at `/usr/share/licenses/copilot-cli/LICENSE.md`.
200
+
The build uses curl to download the CLI release archive and verifies it against the release's `SHA256SUMS.txt`. Only the extracted `copilot` binary is copied from the download stage into the runtime image; curl is not included. The license is at `/usr/share/licenses/copilot-cli/LICENSE.md`.
98
201
99
202
## Building locally
100
203
101
-
The smoke test requires a Unix environment (Linux or macOS), Python 3, and Docker configured to run Linux containers. Native Windows Python is not supported because the bind-mounted Git check uses Unix UID/GID APIs (`os.getuid()` and `os.getgid()`). On Windows, run the commands below from a Linux environment such as WSL 2.
204
+
The smoke test requires Python 3 and Docker configured to run Linux containers.
102
205
103
206
Build from the repository root with the release version, without the leading `v`:
The smoke test checks the container's configuration, Git access to a bind-mounted repository owned by the host user, and a real client handshake with the running server. Add `--platform linux/arm64` or `--platform linux/amd64` to test a build for another architecture.
213
+
The smoke test checks the container's configuration and a real client handshake with the running server. Add `--platform linux/arm64` or `--platform linux/amd64` to test a build for another architecture.
0 commit comments