Skip to content

Commit a14134b

Browse files
timrogersCopilotCopilot
authored
More flexible secrets and variables for Copilot cloud agent [2026-05-06] (#60993)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent b7e563b commit a14134b

8 files changed

Lines changed: 98 additions & 44 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
title: Configure secrets and variables for Copilot cloud agent
3+
shortTitle: Configure secrets and variables
4+
intro: 'Securely pass secrets and variables to {% data variables.copilot.copilot_cloud_agent %} so it can access private resources and configure MCP servers.'
5+
versions:
6+
feature: copilot
7+
contentType: how-tos
8+
category:
9+
- Configure Copilot
10+
---
11+
12+
## About secrets and variables for {% data variables.copilot.copilot_cloud_agent %}
13+
14+
When you delegate a task to {% data variables.copilot.copilot_cloud_agent %}, it works in its own ephemeral development environment, powered by {% data variables.product.prodname_actions %}. You may want to pass secrets and variables to the agent to:
15+
16+
* Give {% data variables.product.prodname_copilot_short %} access to private resources, such as internal package registries, when it builds, tests, or validates your code in the agent's environment.
17+
* Configure MCP servers, by passing API keys, tokens, or other configuration to the servers. For more information, see [AUTOTITLE](/copilot/how-tos/use-copilot-agents/cloud-agent/extend-cloud-agent-with-mcp).
18+
* Set environment variables that are available to scripts and tools that {% data variables.product.prodname_copilot_short %} runs in its environment, including in `copilot-setup-steps.yml`. For more information, see [AUTOTITLE](/copilot/how-tos/use-copilot-agents/cloud-agent/customize-the-agent-environment).
19+
20+
{% data variables.copilot.copilot_cloud_agent %} has its own dedicated **Agents** secrets and variables, alongside the existing **Actions**, **Codespaces**, and **Dependabot** types. You can configure Agents secrets and variables at:
21+
22+
* The **organization level**, so a single secret or variable can be shared across any or all repositories in your organization.
23+
* The **repository level**, for configuration that only applies to a single repository.
24+
25+
Variables and secrets that you configure are exposed to {% data variables.product.prodname_copilot_short %} as environment variables, except secrets and variables prefixed with `COPILOT_MCP_`, which are only available to MCP servers.
26+
27+
> [!NOTE]
28+
> If you previously configured secrets or variables in the `copilot` environment in a repository's {% data variables.product.prodname_actions %} settings, those secrets and variables have been automatically migrated to the new repository-level **Agents** type. You don't need to take any action, and you can manage them from the new location going forward.
29+
30+
## Configuring repository-level secrets and variables
31+
32+
You must be a repository administrator to configure Agents secrets and variables for a repository.
33+
34+
{% data reusables.repositories.navigate-to-repo %}
35+
{% data reusables.repositories.sidebar-settings %}
36+
1. In the "Security" section of the sidebar, click **Secrets and variables**, then click **Agents**.
37+
1. To add a secret, click the **Secrets** tab, then click **New repository secret**. To add a variable, click the **Variables** tab, then click **New repository variable**.
38+
1. Fill in the "Name" and "Value" (or "Secret") fields, and then click **Add secret** or **Add variable**.
39+
40+
## Configuring organization-level secrets and variables
41+
42+
You must be an organization owner to configure Agents secrets and variables for an organization.
43+
44+
{% data reusables.organizations.navigate-to-org %}
45+
{% data reusables.organizations.org_settings %}
46+
1. In the "Security" section of the sidebar, click **Secrets and variables**, then click **Agents**.
47+
1. To add a secret, click the **Secrets** tab, then click **New organization secret**. To add a variable, click the **Variables** tab, then click **New organization variable**.
48+
1. Fill in the "Name" and "Value" (or "Secret") fields.
49+
1. Under "Repository access", choose which repositories in your organization can access the secret or variable:
50+
51+
* **All repositories**: any repository in the organization can access the secret or variable.
52+
* **Private repositories**: any private or internal repository in the organization can access the secret or variable.
53+
* **Selected repositories**: only the repositories you specify can access the secret or variable.
54+
55+
1. Click **Add secret** or **Add variable**.
56+
57+
## Using secrets and variables
58+
59+
Once configured, Agents secrets and variables are automatically available to {% data variables.copilot.copilot_cloud_agent %} when it works on a task in the repository. They are exposed to the agent as environment variables in its development environment, so they can be used by scripts and tools that {% data variables.product.prodname_copilot_short %} runs, including by your `copilot-setup-steps.yml` workflow.
60+
61+
Secret values are masked in {% data variables.copilot.copilot_cloud_agent %} session logs.
62+
63+
> [!NOTE]
64+
> {% data variables.copilot.copilot_cloud_agent %} does not have access to {% data variables.product.prodname_actions %}, {% data variables.product.prodname_codespaces %}, or {% data variables.product.prodname_dependabot %} secrets and variables. Only Agents secrets and variables are passed to the agent.
65+
66+
## Naming requirements for secrets and variables
67+
68+
Names must:
69+
70+
* Only contain alphanumeric characters (`[A-Z]`, `[0-9]`) or underscores (`_`). Spaces are not allowed.
71+
* Not start with the `GITHUB_` prefix.
72+
* Not start with a number.
73+
74+
Names are case-insensitive. Lowercase letters are converted to uppercase. Names must be unique at the level at which they are created.
75+
76+
If a variable or secret with the same name exists at multiple levels, the value at the lowest level takes precedence. For example, a repository-level secret will override an organization-level secret with the same name.
77+
78+
For secrets and variables that you want to pass to MCP servers, the name must begin with the prefix `COPILOT_MCP_`. Only Agents secrets and variables with this prefix are available to your MCP configuration. For more information, see [AUTOTITLE](/copilot/how-tos/use-copilot-agents/cloud-agent/extend-cloud-agent-with-mcp).
79+
80+
## Further reading
81+
82+
* [AUTOTITLE](/copilot/how-tos/use-copilot-agents/cloud-agent/customize-the-agent-environment)
83+
* [AUTOTITLE](/copilot/how-tos/use-copilot-agents/cloud-agent/extend-cloud-agent-with-mcp)

content/copilot/how-tos/copilot-on-github/customize-copilot/customize-cloud-agent/customize-the-agent-environment.md

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ You can customize {% data variables.product.prodname_copilot_short %}'s developm
3131

3232
In addition, you can:
3333

34-
* [Set environment variables in {% data variables.product.prodname_copilot_short %}'s environment](#setting-environment-variables-in-copilots-environment)
34+
* [AUTOTITLE](/copilot/how-tos/copilot-on-github/customize-copilot/customize-cloud-agent/configure-secrets-and-variables)
3535
* [Disable or customize the agent's firewall](/copilot/customizing-copilot/customizing-or-disabling-the-firewall-for-copilot-cloud-agent).
3636

3737
> [!NOTE]
@@ -168,7 +168,7 @@ We recommend that you only use {% data variables.copilot.copilot_cloud_agent %}
168168
| `ssl_cert_file` | The path to the SSL certificate presented by your proxy server. You will need to configure this if your proxy intercepts SSL connections. | `/path/to/key.pem` |
169169
| `node_extra_ca_certs` | The path to the SSL certificate presented by your proxy server. You will need to configure this if your proxy intercepts SSL connections. | `/path/to/key.pem` |
170170

171-
You can set these environment variables by following the [instructions below](#setting-environment-variables-in-copilots-environment), or by setting them on the runner directly, for example with a custom runner image. For more information on building a custom image, see [AUTOTITLE](/actions/concepts/runners/actions-runner-controller#creating-your-own-runner-image).
171+
You can set these environment variables by creating Agents variables or secrets, or by setting them on the runner directly, for example with a custom runner image. For more information, see [AUTOTITLE](/copilot/how-tos/copilot-on-github/customize-copilot/customize-cloud-agent/configure-secrets-and-variables) and [AUTOTITLE](/actions/concepts/runners/actions-runner-controller#creating-your-own-runner-image).
172172

173173
## Switching {% data variables.product.prodname_copilot_short %} to a Windows development environment
174174

@@ -200,19 +200,7 @@ jobs:
200200
lfs: true
201201
```
202202

203-
## Setting environment variables in {% data variables.product.prodname_copilot_short %}'s environment
204-
205-
You may want to set environment variables in {% data variables.product.prodname_copilot_short %}'s environment to configure or authenticate tools or dependencies that it has access to.
206-
207-
You may want to set an environment variable for {% data variables.product.prodname_copilot_short %}, create a {% data variables.product.prodname_actions %} variable or secret in the `copilot` environment. If the value contains sensitive information, for example a password or API key, it's best to use a {% data variables.product.prodname_actions %} secret.
208-
209-
{% data reusables.repositories.navigate-to-repo %}
210-
{% data reusables.repositories.sidebar-settings %}
211-
{% data reusables.actions.sidebar-environment %}
212-
1. Click the `copilot` environment.
213-
1. To add a secret, under "Environment secrets," click **Add environment secret**. To add a variable, under "Environment variables," click **Add environment variable**.
214-
1. Fill in the "Name" and "Value" fields, and then click **Add secret** or **Add variable** as appropriate.
215-
216203
## Further reading
217204

205+
* [AUTOTITLE](/copilot/how-tos/copilot-on-github/customize-copilot/customize-cloud-agent/configure-secrets-and-variables)
218206
* [AUTOTITLE](/copilot/how-tos/use-copilot-agents/cloud-agent/customize-the-agent-firewall)

content/copilot/how-tos/copilot-on-github/customize-copilot/customize-cloud-agent/extend-cloud-agent-with-mcp.md

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Repository administrators can configure MCP servers by following these steps:
4949

5050
Your configuration will be validated to ensure proper syntax.
5151

52-
1. If your MCP server requires a variable, key, or secret, add a variable or secret to your {% data variables.product.prodname_copilot_short %} environment. Only variables and secrets with names prefixed with `COPILOT_MCP_` will be available to your MCP configuration. See [Setting up a {% data variables.product.prodname_copilot_short %} environment for {% data variables.copilot.copilot_cloud_agent %}](#setting-up-a-copilot-environment-for-copilot-cloud-agent).
52+
1. If your MCP server requires a variable, key, or secret, add an Agents secret or variable for {% data variables.copilot.copilot_cloud_agent %} with a name prefixed with `COPILOT_MCP_`. Only Agents secrets and variables with names prefixed with `COPILOT_MCP_` will be available to your MCP configuration. See [AUTOTITLE](/copilot/how-tos/copilot-on-github/customize-copilot/customize-cloud-agent/configure-secrets-and-variables).
5353

5454
## Writing a JSON configuration for MCP servers
5555

@@ -249,7 +249,7 @@ To use the Azure DevOps MCP server with {% data variables.copilot.copilot_cloud_
249249
```
250250
251251
This configuration ensures the `azure/login` action is executed when {% data variables.copilot.copilot_cloud_agent %} runs.
252-
1. In your repository’s {% data variables.product.prodname_copilot_short %} environment, add secrets for your `AZURE_CLIENT_ID` and `AZURE_TENANT_ID`.
252+
1. Configure secrets for your `AZURE_CLIENT_ID` and `AZURE_TENANT_ID` as Agents secrets at either the organization or repository level. For more information, see [AUTOTITLE](/copilot/how-tos/copilot-on-github/customize-copilot/customize-cloud-agent/configure-secrets-and-variables).
253253
1. Configure the Azure DevOps MCP server by adding an `ado` object to your MCP configuration with defined tools you want {% data variables.copilot.copilot_cloud_agent %} to use.
254254

255255
```json copy
@@ -313,20 +313,6 @@ To adapt the configuration for {% data variables.copilot.copilot_cloud_agent %},
313313

314314
For more information on MCP in {% data variables.product.prodname_vscode_shortname %}, see the [{% data variables.product.prodname_vscode_shortname %} docs](https://code.visualstudio.com/docs/copilot/chat/mcp-servers).
315315

316-
## Setting up a {% data variables.product.prodname_copilot_short %} environment for {% data variables.copilot.copilot_cloud_agent %}
317-
318-
Some MCP servers will require keys or secrets. To leverage those servers in {% data variables.copilot.copilot_cloud_agent %}, you can add secrets to an environment for {% data variables.product.prodname_copilot_short %}. This ensures the secrets are properly recognized and passed to the applicable MCP server that you have configured.
319-
320-
You must be a repository administrator to configure a {% data variables.product.prodname_copilot_short %} environment for your repository.
321-
322-
{% data reusables.repositories.navigate-to-repo %}
323-
{% data reusables.repositories.sidebar-settings %}
324-
{% data reusables.actions.sidebar-environment %}
325-
{% data reusables.actions.new-environment %}
326-
1. Call the new environment `copilot` and click **Configure environment**.
327-
1. Under "Environment secrets", click **Add environment secret**.
328-
1. Give the secret a name beginning `COPILOT_MCP_`, add the secret value, then click **Add secret**.
329-
330316
## Validating your MCP configuration
331317

332318
Once you've set up your MCP configuration, you should test it to make sure it is set up correctly.
@@ -376,10 +362,7 @@ If you want to allow {% data variables.product.prodname_copilot_short %} to acce
376362
For more information on toolsets, refer to the [README](https://github.com/github/github-mcp-server?tab=readme-ov-file#available-toolsets) in the {% data variables.product.github %} Remote MCP Server documentation.
377363

378364
1. Click **Save**.
379-
{% data reusables.actions.sidebar-environment %}
380-
1. Click the `copilot` environment.
381-
1. Under "Environment secrets", click **Add environment secret**.
382-
1. Call the secret `COPILOT_MCP_GITHUB_PERSONAL_ACCESS_TOKEN`, enter your {% data variables.product.pat_generic %} in the "Value" field, then click **Add secret**.
365+
1. Add an Agents secret called `COPILOT_MCP_GITHUB_PERSONAL_ACCESS_TOKEN` with your {% data variables.product.pat_generic %} as the value. You can configure this at either the organization or repository level. For more information, see [AUTOTITLE](/copilot/how-tos/copilot-on-github/customize-copilot/customize-cloud-agent/configure-secrets-and-variables).
383366

384367
For information on using the {% data variables.product.github %} MCP server in other environments, see [AUTOTITLE](/copilot/customizing-copilot/using-model-context-protocol/using-the-github-mcp-server).
385368

content/copilot/how-tos/copilot-on-github/customize-copilot/customize-cloud-agent/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ children:
1010
- /extend-cloud-agent-with-mcp
1111
- /use-hooks
1212
- /customize-the-agent-environment
13+
- /configure-secrets-and-variables
1314
- /customize-the-agent-firewall
1415
- /test-custom-agents
1516
contentType: how-tos

content/copilot/reference/custom-agents-configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ For compatibility, the `stdio` type used by Claude Code and {% data variables.pr
114114
### MCP server environment variables and secrets
115115

116116
> [!NOTE]
117-
> If your MCP server requires secrets or environment variables, these must be configured in the {% data variables.product.prodname_copilot_short %} environment in each repository where the {% data variables.copilot.copilot_custom_agent_short %} will be used. For more information on setting up environment variables, see [AUTOTITLE](/copilot/how-tos/use-copilot-agents/cloud-agent/customize-the-agent-environment#setting-environment-variables-in-copilots-environment).
117+
> If your MCP server requires secrets or environment variables, these must be configured as Agents secrets or variables at either the organization or repository level. For more information, see [AUTOTITLE](/copilot/how-tos/copilot-on-github/customize-copilot/customize-cloud-agent/configure-secrets-and-variables).
118118
119-
{% data variables.copilot.copilot_custom_agent_caps_short %} MCP configuration supports the same environment variable and secret replacement capabilities as existing repository-level MCP configurations. Similar to repository-level configurations, secrets and variables can be sourced from the "copilot" environment in the repository's settings. The syntax for referencing these values has been expanded to support common patterns used in {% data variables.product.prodname_actions %} and Claude Code.
119+
{% data variables.copilot.copilot_custom_agent_caps_short %} MCP configuration supports the same environment variable and secret replacement capabilities as existing repository-level MCP configurations. Similar to repository-level configurations, secrets and variables can be sourced from Agents secrets and variables for {% data variables.copilot.copilot_cloud_agent %}, configured at either the organization or repository level. The syntax for referencing these values has been expanded to support common patterns used in {% data variables.product.prodname_actions %} and Claude Code.
120120

121121
Both the repository-level MCP JSON configuration and the {% data variables.copilot.copilot_custom_agent_short %} YAML configuration support the following syntax patterns:
122122

content/copilot/responsible-use/copilot-cloud-agent.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Copilot only has access to the repository where it is working, and cannot access
125125

126126
Its permissions are limited, allowing it to push code and read other resources. Built-in protections mean that Copilot can only push to a single branch: the existing pull request branch when triggered via `@copilot`, or otherwise to a new `copilot/` branch. This means that Copilot cannot push directly to your default branch (for example, `main`).
127127

128-
{% data variables.copilot.copilot_cloud_agent %} does not have access to Actions organization or repository secrets or variables during runtime. Only secrets and variables specifically added to the `copilot` environment are passed to the agent.
128+
{% data variables.copilot.copilot_cloud_agent %} does not have access to {% data variables.product.prodname_actions %} secrets or variables during runtime. Only Agents secrets and variables, configured at the organization or repository level, are passed to the agent. For more information, see [AUTOTITLE](/copilot/how-tos/copilot-on-github/customize-copilot/customize-cloud-agent/configure-secrets-and-variables).
129129

130130
### Ensuring traceability
131131

content/copilot/tutorials/cloud-agent/build-guardrails.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ To adapt your rulesets for {% data variables.copilot.copilot_cloud_agent %}:
5151

5252
Continue to store data and tokens that you _don't_ want {% data variables.product.prodname_copilot_short %} to access as **{% data variables.product.prodname_actions %} variables or secrets**. {% data variables.product.prodname_copilot_short %} won't be able to access these in its sessions or environment setup steps.
5353

54-
If you need to provide data and secrets that {% data variables.copilot.copilot_cloud_agent %} _does_ need, you'll be able to do this in a specific `copilot` environment.
54+
If you need to provide data and secrets that {% data variables.copilot.copilot_cloud_agent %} _does_ need, you'll be able to do this by configuring Agents secrets and variables at the organization or repository level. For more information, see [AUTOTITLE](/copilot/how-tos/copilot-on-github/customize-copilot/customize-cloud-agent/configure-secrets-and-variables).
5555

5656
### Configure runners
5757

0 commit comments

Comments
 (0)