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
Used by Secret.env() · SecretEntry.substitution
Frozen dataclass selecting where in an HTTP request the real value may replace the placeholder. At least one location must remain enabled. On credential-allowed hosts that pass the secret’s identity checks, disabled locations forward the placeholder unchanged. Other destinations must matchpassthrough or follow the violation action.
When body substitution is enabled, fixed-length HTTP/1 bodies up to 16 MiB are rewritten with an updated
Content-Length; larger fixed-length bodies are blocked. Chunked HTTP/1 bodies are decoded and re-encoded. Encoded bodies pass through unchanged. HTTP/2 DATA-frame body substitution is unsupported, and matching body placeholders are blocked.
Default settings are omitted from serialized configuration; explicitly setting headers=False is preserved. Passing a value other than SecretSubstitution 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".