Secrets

Project secrets, delivered to a sandbox as an environment value or brokered: the sandbox sees a placeholder and Sandal adds the real key only to HTTPS requests to the hosts you allow (preview).


A secret is a value your sandboxes need but you do not want in code: an API key, a token, a password. Secrets belong to a project, are sealed before they leave your machine, and are versioned. A sandbox gets a secret by reference at create time, in one of two ways:

DeliveryWhat the sandbox seesGood forStatus
environmentThe real value, in an environment variableAny secret: database passwords, SSH keys, tokens your code readsAvailable
brokeredA placeholder (sdl_ph_…) in the variable. Sandal adds the real value only to HTTPS requests to the secret's hostsHTTP API keys you do not want an agent to be able to read or leakPreview

Create a secret#

The value comes from standard input or a file, never from an argument:

# an HTTP credential for a known provider: brokered by default
printf '%s' "$OPENAI_API_KEY" | sandal secrets create openai --value-stdin --preset openai

# any HTTPS API: name the host and how the key is sent
printf '%s' "$MY_API_KEY" | sandal secrets create my-api --value-stdin \
  --host api.example.com --header Authorization --format 'Bearer {}'

# a value your code reads from the environment
printf '%s' "$DB_PASSWORD" | sandal secrets create db-password --value-stdin --delivery environment

sandal secrets ls        # ID, NAME, TYPE, VERSION, DELIVERY, LAST USED (never the value)
sandal secrets presets   # anthropic, openai, openrouter, gemini, github, github-git, gitlab, huggingface, npm, pypi, dockerhub

An HTTP credential (--preset or --host) is brokered only, unless you add --env-allowed. A secret without hosts is delivered as an environment value. sandal secrets rotate <secret> --value-stdin --expected-version <n> writes a new version (n is the current one, so two rotations cannot race); sandal secrets show <secret> lists versions and hosts, sandal secrets events <secret> its audit trail.

Give it to a sandbox#

Pass --secret NAME=<secret id> with the delivery you want. Without @version, the sandbox gets the secret's current version; NAME=sec_…@2 pins one.

sandal create --secret OPENAI_API_KEY=sec_...:brokered       # placeholder in the sandbox
sandal create --secret DB_PASSWORD=sec_...:environment       # the value in the sandbox

Then ask how the sandbox's secrets are delivered:

sandal secrets status <sandbox>
sandbox: sandbox.d0f4…
secrets: environment (1 ref, not brokered)
names:   DB_PASSWORD
message: This Sandbox's secrets are delivered as environment values; none is brokered.

For a sandbox with brokered secrets, sandal secrets status and sandal get also list each secret's state:

secrets: brokered - active for 1 of 2 (B unavailable: requests carry the placeholder)
names:   A, B
SECRET  STATE        SINCE
A       active       2026-11-29T15:37:01.078Z
B       unavailable  2026-11-29T15:37:10.197Z

sandal get <sandbox> shows the same in its secrets: row. In the SDKs the sandbox carries it as secretBrokering (state, reason, message, and the state of each brokered secret).

Creating waits for brokering#

A new sandbox's brokered secrets can go live some seconds after it starts. sandal create and the SDKs' create calls (createSandbox(), create_sandbox(), CreateSandbox()) wait until brokering is no longer pending, for at most 60 s; from 0.1.0-beta.16 every other wait does too (a create that did not wait followed by waitUntilRunning(), the operation wait, the jobs and commands helpers). In our run on November 29, 2026 a create with two brokered secrets returned in about 22 s, with both active. What you get back:

  • active: you get the sandbox as usual, ready to use.
  • unavailable, or still pending after 60 s: you still get the sandbox, with a warning that names each secret that is not active and carries the server's reason (CLI: a secrets: warning: line on stderr; TypeScript: a SandalSecretBrokeringWarning process warning; Python: a SandalSecretBrokeringWarning warning; Go: SecretBrokeringWarning on the sandbox). Requests carry the placeholder until it turns active.

Opt out with --no-wait-secrets, waitForSecretBrokering: false, wait_for_secret_brokering=False or NoSecretBrokeringWait: true; you can wait later on the handle with waitForSecretBrokering() / wait_for_secret_brokering() / WaitForSecretBrokering(). Older clients return as soon as the sandbox is running: check sandal secrets status before you rely on brokering.

Wait for active before the first request#

Send the first request to a secret's host only once secretBrokering is active. If a process in the sandbox looked up or connected to that host earlier, its requests keep going straight to the host with the placeholder, even after the state says active: the sandbox's DNS cache and that process's open connections still point at the host itself, not at the broker, until the cached answer expires (up to 5 minutes).

If that happened, flush the sandbox's DNS cache first, on a template that allows root (sandal exec --root <sandbox> -- resolvectl flush-caches), then restart the process: a restart alone gets the same cached answer. Without root, wait until the cached answer expires (up to 5 minutes), then restart the process. A process that the sandbox's image starts at boot can call the host before brokering is active, so today it can race the broker: start such processes yourself after active instead.

Brokering states#

StateMeaning
pendingThe broker is being set up for this sandbox. Requests still carry the placeholder
activeThe real value is added to HTTPS requests to the secret's hosts. Every other host sees the placeholder
unavailableBrokering stopped or cannot start. reason and message say why, for example broker.grant-revoked after the secret was revoked or destroyed

There is no state for environment-only sandboxes; secrets status says environment instead. Each brokered secret also has its own state: after you revoke one of two brokered secrets, the sandbox says active for 1 of 2 and names the revoked one as unavailable (the other one is still injected).

What brokering does, and what it does not#

  • The key stays outside. The sandbox's environment, processes and files hold only the placeholder. Sandal's broker terminates TLS for the secret's hosts only (the sandbox trusts a Sandal broker certificate for them) and substitutes the header, basic-auth or query value. Responses are scrubbed of the real value.
  • Only the hosts you allow. Up to 16 hosts per secret, exact names or *. wildcards, never IP addresses. A request to any other host carries the placeholder.
  • Revoking is fast. sandal secrets revoke <secret> stops injection within about 10 seconds; requests then carry the placeholder. Deleting the secret (sandal secrets rm <secret> --destroy) makes requests that need it fail; they do not fall back to anything.
  • HTTP(S) only. SSH keys, database passwords and other non-HTTP secrets use environment delivery.
  • HTTP/3 falls back. UDP 443 (QUIC) to a brokered host is dropped, so clients use HTTP/2 or HTTP/1.1 over TCP.
  • No per-request log yet. The broker keeps counters, and sandal secrets events <secret> shows a secret's lifecycle and delivery events, but there is no per-request audit or network log.
  • Forks inherit. A fork gets the same brokered secrets as its source.

Clean up#

sandal secrets revoke <secret>              # stop live grants now
sandal secrets rm <secret>                  # destroyed after 24 h
sandal secrets rm <secret> --destroy        # destroyed now