Give a run a secret as an environment variable
This page is for a value that must be in the sandbox itself, for example:
- a key that the app uses on its own side, such as a GitHub App private key that signs a token;
- a secret that goes in a request body, such as an OAuth client secret;
- a value that a process reads when it starts, such as the URL of a test database.
For a key that goes in a request header or query parameter, use a stand-in instead, so that the value never enters the sandbox. See Give agents a secret for an API.
The agent and every process in the sandbox can read the value. The agent can print it, write it to a file, or send it to any host that egress allows. Spotlight puts the secret's stand-in in place of the value in the messages, tool output and tool calls that it records. It does not change files, attachments or commits. A file that holds the value is in the workspace archive at the end of the run. Use a credential made for development only, with the smallest access, for example a separate GitHub App for a test server.
You need Terraform set up with the Spotlight provider, using a token that has
the configure and secrets scopes. See
Manage Spotlight with Terraform.
Runs on hosts and on push pools can get the variables. They need no egress.
Let the secret enter a sandbox
Set sandbox = "env" on the secret:
data "spotlight_workspace" "acme" {
slug = "acme"
}
resource "spotlight_secret" "dev_github_app_key" {
workspace_id = data.spotlight_workspace.acme.id
name = "DEV_GITHUB_APP_KEY"
sandbox = "env"
}This secret has no value in Terraform. After terraform apply, set it in the
web app under Settings, then Secrets, or with
spotlight secret set DEV_GITHUB_APP_KEY. The Secrets page shows
Can enter sandboxes for the secret.
Name the variable in a harness profile
Add the variable and the secret to the profile's env:
data "spotlight_team" "core" {
workspace_id = data.spotlight_workspace.acme.id
key = "core"
}
resource "spotlight_harness_profile" "full_app" {
team_id = data.spotlight_team.core.id
key = "full-app"
env = {
GITHUB_APP_PRIVATE_KEY = spotlight_secret.dev_github_app_key.name
}
}If the secret does not have sandbox = "env", the write fails with 422 and
names secret DEV_GITHUB_APP_KEY, which does not allow its value in a sandbox. Set sandbox = "env" on the secret.
Both the secret and the profile must allow it, so that one change alone does
not put a value in a sandbox.
Run a station with the profile
Set the station's profile to the profile's key:
station {
key = "verify"
name = "Verify"
harness = "claude-code"
profile = spotlight_harness_profile.full_app.key
passes_to = ["code-review"]
}Run terraform apply. In the next run at that station, the repository setup
commands, the harness and the spotlight commands of the agent have
GITHUB_APP_PRIVATE_KEY set to the value. The briefing has a
Secrets in your environment section that names the variable.
A profile cannot name a variable that a harness sets itself, for example
ANTHROPIC_API_KEY. The write fails with 422 and
sets ANTHROPIC_API_KEY, which a harness sets itself: claude-code, opencode.
Use a different variable name.
A run at the station fails with
secret_awaiting_value: Secret DEV_GITHUB_APP_KEY has no value. Station: Verify
while the secret has no value.
The value must have at least 8 characters that are not whitespace, and no NUL
byte. A shorter value could match other text in what the run records, so
Spotlight cannot replace it with the stand-in. An environment variable cannot
hold a NUL byte. Setting such a value on a secret with sandbox = "env" fails
with 422 and
must have at least 8 characters that are not whitespace, and no NUL byte, since a run gets DEV_GITHUB_APP_KEY in its sandbox.
If the secret held such a value before it had sandbox = "env", the run
fails with
The runner couldn't prepare the run. Error: Secret DEV_GITHUB_APP_KEY could not be put in the sandbox: <reason>,
and the reason is
The value of secret DEV_GITHUB_APP_KEY must have at least 8 characters that are not whitespace, and no NUL byte, since a run gets DEV_GITHUB_APP_KEY in its sandbox. Set a new value.
Stop giving the value to runs
Remove the variable from the profile's env and run terraform apply. Then
you can set sandbox back to "stand-in" on the secret. While a profile's
env names the secret, that change fails with 409.
A run keeps the env of the profile from when Spotlight ordered it. A queued
run, or a new attempt of a run, still asks for the variable after you remove it
from the profile. The runner gets the value only while the secret has
sandbox = "env". To stop the value at once, also set sandbox back to
"stand-in" after you remove the variable.
Related
spotlight_harness_profile: theenvfield.spotlight_secret: thesandboxfield.- The sandbox is the security boundary