Skip to main content
Secrets keep credentials on the host while giving sandboxed code a placeholder to use. When you bind a secret to an environment variable, microsandbox puts a placeholder in the guest instead of the real value. By default that placeholder is $MSB_<env_var>, using the environment variable name exactly as provided, and you can provide a custom placeholder when needed. If the sandbox sends the placeholder to an allowed host and enabled request location, microsandbox swaps it for the real credential at the network boundary. Elsewhere, microsandbox blocks the placeholder by default so it cannot reveal which credentials the workload expects. Use explicit passthrough hosts only when a destination must receive the unchanged placeholder. That means the guest can call APIs without ever holding the credential itself. Allowed hosts are checked against the sandbox’s observed DNS and TLS identity. Keep allow lists narrow so placeholders can only turn into credentials at the destinations that actually need them.

Add at create time

Bind secrets to environment variables when you create the sandbox, each scoped to the hosts allowed to receive it:
In the CLI form, ENV@HOST[,HOST...] records a host-side source reference: the real value is read from the same-named host environment variable when the sandbox starts, and never lands in the durable config. The inline ENV=VALUE@HOST form is rejected on both msb create and msb modify (shell history and process listings would leak the value regardless), so providing a raw value is SDK-only. Options follow the secret name after :. body enables body substitution; no-headers, no-query, and no-body disable locations; and passthrough=HOST permits that host to receive an unchanged placeholder. For multiple passthrough hosts, use passthrough=[HOST,...], repeat the option, or repeat --secret; repeated values are merged.
The sandbox-wide --secret-violation-action accepts block, block-and-log, or block-and-terminate. Passthrough is deliberately not a violation action because it is scoped per secret and per host.

YAML configuration

YAML keeps substitution and passthrough as separate per-secret policies. Values can use the existing environment interpolation syntax:
Setting substitution.headers: false disallows substitution in all request headers, including Basic authentication. A placeholder found there still blocks unless the destination matches passthrough.
Raw values are saved to disk. When you pass a raw value through an SDK (.value(..), secret_env(), or a value-based rotate), it is stored as-is in the sandbox config file and stays there until you rotate the secret to a reference. The sandbox behaves the same either way; the only difference is what ends up on disk. Prefer references whenever the value is available in a host environment variable.

Change while running

Rotate or remove existing secrets without a restart. Adding a secret or changing its guest-visible placeholder requires a restart so the new environment reaches the guest. Later rotations keep that placeholder stable and only change the value injected at the network boundary.
Secret modification is available through every SDK and the CLI. See Tuning for how changes are planned and applied. For API details, see the SDK references: Rust | TypeScript | Python | Go.