Secret
Secret.env()
Example
Example
Sandbox.create(..., secrets=[...]).
Parameters
env_varstrEnvironment variable name. Must be non-empty and cannot contain
= or NUL; shell-identifier syntax is not required.valuestrThe real secret value. Never enters the guest VM. Keyword-only and required. Raw values are persisted in the durable sandbox configuration.
allowSequence[str]Exact hosts or wildcard patterns allowed to receive the real value. At least one exact or wildcard host is required. Default
().allow_placeholder_forSequence[str]Exact hosts or wildcard patterns allowed to receive the unchanged placeholder. Does not grant access to the real value. Default
().placeholderstr | NoneCustom placeholder string: non-empty, up to 1024 bytes, no NUL/CR/LF. Auto-generated as
$MSB_<env_var> when None. Default None.require_tls_identityboolOnly substitute on TLS-intercepted connections. Disable only if you know the traffic is safe. Default
True.violation_actionViolationAction | NonePer-secret blocking action. Default
None inherits the network setting, whose default is BLOCK_AND_LOG.substitutionSecretSubstitution | NoneWhere in the HTTP request to substitute.
None uses SecretSubstitution() defaults. Default None.Returns
Secret entry for
Sandbox.create(secrets=[…]).Validation and lifecycle
Sandbox configuration validation rejects empty environment names, names containing= or NUL, missing allowed hosts, every substitution location disabled, and placeholders that are empty, longer than 1024 bytes, or contain NUL/CR/LF. Secret.env() constructs an entry; it does not itself run all native validation.
Raw values are persisted at rest. Prefer source references through live modification when the secret is available in the host environment. Rotating or removing an existing secret does not require a restart; adding a secret or changing its guest-visible placeholder does. Live modification is local-only.
passthrough= remains a deprecated alias for allow_placeholder_for= and emits a DeprecationWarning when used with hosts. If both are supplied, the host lists are combined. The returned SecretEntry.passthrough field and serialized configuration keep their existing names.
Types
SecretEntry
Returned by Secret.env()
A single secret entry, used inSandbox.create(secrets=[...]). Construct it with Secret.env() rather than directly.
SecretSubstitution
substitution.headers
True.
substitution.header_fields
Authorization, to prevent other headers from exposing a secret in a reflected response.
substitution.query
False.
substitution.body
False. Fixed-length bodies up to 16 MiB update Content-Length; larger bodies are blocked. Chunked bodies are decoded and re-encoded. Encoded bodies pass through unchanged. HTTP/2 body substitution is unsupported, and matching placeholders are blocked.
At least one substitution location must remain enabled. On verified allowed hosts, disabled locations forward the placeholder unchanged. Other destinations must match the passthrough policy or follow the violation action.
This is a frozen dataclass. Defaults are omitted from serialized configuration; explicit headers=False is preserved. Assigning another type to SecretEntry.substitution raises TypeError when serialized.
ViolationAction
Used by Secret.env() · SecretEntry.violation_action
String enum defining the blocking action when a placeholder cannot be substituted or passed through. Set the sandbox-wide default withNetwork.secret_violation_action or the top-level Sandbox.create(secret_violation_action=...); the top-level value takes precedence if both are supplied. A secret’s violation_action overrides that default. Passthrough is a host policy, not an enum member.
SecretViolationError
Subclass of MicrosandboxError
code = "secret-violation".