Skip to content

Secrets

A team secret is a named value the platform keeps for you, such as a registry password, a git token or an API key. Its value never enters a sandbox. The sandbox sends a placeholder. The egress proxy swaps the placeholder for the secret inside the sandbox’s TLS tunnel, and only for the host you bound the secret to.

import os
from svm import Sandbox, Secret
NAME = "DOCS_GITHUB_TOKEN"
Secret.create(NAME, os.environ["GITHUB_TOKEN"], "GitHub token for the docs sample")
try:
print(Secret.exists(NAME)) # True
Secret.update(NAME, os.environ["GITHUB_TOKEN_ROTATED"]) # rotate the value
for info in Secret.list().items:
print(info.name, info.version, info.updated_at)
# The value never enters the sandbox: it holds a placeholder, and the egress
# proxy puts the secret in the Authorization header for api.github.com only.
with Sandbox.create(template="base", envs={"GH_TOKEN": Secret.fill(NAME)}) as sandbox:
sandbox.update_egress(enabled=True, default="deny", rules=[
{"action": "allow", "domain": "api.github.com", "inject": Secret.inject(NAME, ["Authorization"])},
])
egress = sandbox.egress() # the proxy URL and the CA certificate the guest trusts
sandbox.files.write("/tmp/egress-ca.pem", egress["ca_certificate"])
result = sandbox.commands.run(
'curl -s --cacert /tmp/egress-ca.pem -H "Authorization: Bearer $GH_TOKEN" https://api.github.com/user',
envs={"HTTPS_PROXY": egress["proxy_url"]},
)
print(result.stdout)
finally:
Secret.destroy(NAME)
  • Bind a secret to a host with an allow egress rule that carries inject. Give the rule an exact domain and the headers to fill.
  • In the sandbox, send Secret.fill(name) as the header value, for example Authorization: Bearer <placeholder>.
  • The value is read on every request, so a rotation applies at once. If the secret is gone, the request is refused with 503, never sent with the placeholder.
  • Injection works only over HTTPS and only while egress rules are enabled.

create refuses a name that already exists, and update refuses one that does not, so a typo never makes a second secret. Values are never read back. get_info returns the name, description, metadata and version only.

From the CLI. The value is never a command-line argument:

Terminal window
printf %s "$TOKEN" | svm secret set GITHUB_TOKEN --description "CI token"
svm network egress set <id> --inject api.github.com:Authorization=GITHUB_TOKEN