Docker Sandboxes never hands real API keys to the agent. For services it doesn’t know about, you store a custom secret. The sandbox gets a placeholder in an environment variable, and the host-side proxy swaps the placeholder for the real value only in outbound requests to the hosts you named.
The 0.48.0 change is one line in the release notes:
Sandbox-scoped custom secrets can override global secrets that use the same environment variable name.
So you can set a global API_KEY for every sandbox, and give one sandbox, say the one doing a staging deploy, a different API_KEY, with no changes to agent code. Let’s prove it end to end.
How custom secrets work
┌──────────── sandbox ────────────┐ ┌──────── host proxy ────────┐
│ $API_KEY = sbx-cs-Zi26… │ HTTPS │ sees sbx-cs-Zi26… in a │──► httpbin.org
│ curl -H "X-Key: $API_KEY" │ ──────► │ header for httpbin.org → │ X-Key: <real value>
└─────────────────────────────────┘ │ swaps in the real secret │
└────────────────────────────┘
The real value never enters the sandbox VM.
Step 1: A global secret
I’m using httpbin.org/headers because it echoes request headers back, so we can see exactly what the proxy injected.
sbx secret set-custom --host httpbin.org --env API_KEY --value global-value-AAA
Generated placeholder: sbx-cs-WlHUX9AVjCGQw11p
You may need to update environment variable API_KEY inside existing sandboxes to "sbx-cs-WlHUX9AVjCGQw11p" (the placeholder value).
Use
--valueonly for demos, since it ends up in your shell history. For real keys, prefer--ref 'op://…'(1Password), an AWS Secrets Manager ARN, or--command 'gh auth token'.
Step 2: A sandbox-scoped secret with the same env var
You can scope a secret to a sandbox name before the sandbox exists, so it’s in place at create:
sbx secret set-custom --sandbox sbx-override --host httpbin.org --env API_KEY --value sandbox-value-CCC
# Generated placeholder: sbx-cs-Zi26CszvphxTlR9Y
sbx secret ls
SCOPE TARGETS ENV PLACEHOLDER SECRET
(global) httpbin.org API_KEY sbx-cs-WlHUX9AVjCGQw11p global**********
sbx-override httpbin.org API_KEY sbx-cs-Zi26CszvphxTlR9Y sandbo***********
Step 3: Two sandboxes, one control and one override
mkdir -p ws-sec ws-global
sbx create shell ./ws-sec --name sbx-override --no-progress
sbx create shell ./ws-global --name sbx-global --no-progress
(--no-progress replaces the old -q/--quiet.)
Sandboxes are deny-by-default for egress, so allow the test host for just these two sandboxes:
sbx policy allow network httpbin.org --sandbox sbx-override
sbx policy allow network httpbin.org --sandbox sbx-global
Added rule 48b8dc65-… to policy local (scope: sandbox:sbx-override): httpbin.org [tcp]
Added rule 2f8f2141-… to policy local (scope: sandbox:sbx-global): httpbin.org [tcp]
If you skip this step, you get a 403 and an entry in sbx policy log:
{"host":"httpbin.org:443","reason":"No matching allow rule (default deny)"}
Step 4: Verify the override
for s in sbx-global sbx-override; do
echo "### $s"
sbx exec $s -- sh -c 'echo "API_KEY=$API_KEY"
curl -s https://httpbin.org/headers -H "X-Key: $API_KEY" | grep -i x-key'
done
### sbx-global
API_KEY=sbx-cs-WlHUX9AVjCGQw11p
"X-Key": "global-value-AAA"
### sbx-override
API_KEY=sbx-cs-Zi26CszvphxTlR9Y
"X-Key": "sandbox-value-CCC"
The same code reads the same variable:
sbx-globalfalls back to the global secret.sbx-overridegets its own placeholder, and the proxy injects its own value.- Neither sandbox ever holds a real value, only
sbx-cs-…placeholders.
Step 5: Existing sandboxes
Placeholders are written into the environment at create. If you add a secret for a sandbox that’s already running, its environment doesn’t change. That’s what the CLI’s “You may need to update environment variable…” hint means. I checked this: after scoping a secret to an existing my-sandbox, $API_KEY was still empty inside it, even after a restart.
The proxy still replaces whichever placeholder shows up on the wire:
sbx exec my-sandbox -- sh -c 'for p in sbx-cs-WlHUX9AVjCGQw11p sbx-cs-m46XJVKHvWoQcXEs; do
echo "sent $p ->"; curl -s https://httpbin.org/headers -H "X-Key: $p" | grep -i x-key; done'
sent sbx-cs-WlHUX9AVjCGQw11p ->
"X-Key": "global-value-AAA"
sent sbx-cs-m46XJVKHvWoQcXEs ->
"X-Key": "sandbox-value-BBB"
So for an existing sandbox you have two options: export the printed placeholder inside it yourself, or (cleaner) recreate the sandbox.
Step 6: Where this is useful
| Scenario | Global secret | Sandbox-scoped override |
|---|---|---|
| Multi-tenant SaaS testing | dev tenant key | customer-a-repro sandbox gets customer A’s sandbox key |
| Staging vs. prod | read-only token | deploy-staging sandbox gets a write token |
| Cost control | shared low-limit key | bench sandbox gets a high-quota key |
| Agent evaluation | team key | each eval sandbox gets its own key, so usage is attributable |
Clean up
sbx rm sbx-override sbx-global --force
# custom secrets are removed by placeholder
sbx secret rm --placeholder sbx-cs-WlHUX9AVjCGQw11p -f
sbx secret rm --placeholder sbx-cs-Zi26CszvphxTlR9Y -f
References: v0.48.0 release notes · Docker Sandboxes docs