Skip to main content
Configure secret substitution for outbound requests. See Secrets for usage and security concepts.

SecretBuilder

Builder for one secret configuration.

secret.env()

Set the environment variable name that holds the placeholder inside the guest. The guest sees $MSB_<varName> (or a custom placeholder), never the real value. Names must be non-empty and cannot contain = or NUL; shell-identifier syntax is not required. Required.

Parameters

varNamestring
Environment variable name (non-empty, no = or NUL).

secret.value()

Set the real secret value. This is the string that replaces the placeholder when a request reaches an allowed host. It never enters the guest VM. Required.

Parameters

valuestring
The actual credential or token.

secret.placeholder()

Override the auto-generated placeholder string. By default microsandbox generates $MSB_<envVar>. Use this when you need a specific format or when the placeholder must match a particular byte length. Placeholders must be non-empty, at most 1024 bytes, and cannot contain NUL, CR, or LF.

Parameters

placeholderstring
Custom placeholder string: non-empty, up to 1024 bytes, no NUL/CR/LF.

secret.allowHost()

Add an exact host allowed to receive the real secret value. The proxy checks the host against the connection’s verified TLS identity and observed DNS history. Can be called multiple times to allow several hosts. At least one allowed host (exact, pattern, or any) is required.

Parameters

hoststring
Exact hostname, e.g. “api.example.com” (ASCII case-insensitive).

secret.allowHostPattern()

Add a wildcard host pattern. A *.suffix pattern matches the suffix itself and any single-or-multi label subdomain of it.

Parameters

patternstring
Wildcard pattern, e.g. “*.googleapis.com”.

secret.allowAnyHostDangerous()

Allow substitution on any host. Every server the guest connects to can then receive the real secret, which effectively disables host-based protection. The call is a no-op unless iUnderstand is true. Only use this when the secret is not sensitive or the sandbox network is fully locked down. This is the one allow-list pattern that skips DNS and TLS-identity pinning.

Parameters

iUnderstandboolean
Must be true to take effect.

secret.requireTlsIdentity()

When true, the secret is only substituted on TLS-intercepted connections where the proxy has verified it is performing MITM and the SNI matches an allowed host. Bypassed TLS is opaque and never receives substitution. Disable only when you know the traffic path is safe and explicitly supports non-TLS substitution. Default: true.

Parameters

enabledboolean
Require verified TLS identity. Default: true.

secret.injectHeaders()

Control whether the placeholder is replaced anywhere in HTTP headers. This is the most common injection scope, covering Authorization: Bearer $MSB_... and similar patterns. Default: true.

Parameters

enabledboolean
Substitute in headers. Default: true.

secret.injectBasicAuth()

Control whether Authorization: Basic <base64> credentials are decoded, substituted in the decoded user:password, then re-encoded. Orthogonal to injectHeaders: this flag handles the encoded-credentials case for the Basic scheme; injectHeaders handles literal substitution in any header line, including non-Basic Authorization schemes (Bearer, Digest). Default: true.

Parameters

enabledboolean
Substitute inside Basic Auth credentials. Default: true.

secret.injectQuery()

Control whether the placeholder is replaced in the URL query string (the ?key=value portion of the request line). Default: false.

Parameters

enabledboolean
Substitute in query parameters. Default: false.

secret.injectBody()

Control whether the placeholder is replaced in request bodies when microsandbox can inspect and rewrite them safely. Encoded bodies are forwarded unchanged, and body placeholders in unsupported body formats are blocked rather than leaked. Default: false.

Parameters

enabledboolean
Substitute in request bodies. Default: false.

secret.onViolation()

Configure violation behavior for this secret. Overrides the sandbox-wide secret violation policy and can let selected hosts receive the placeholder unchanged. See ViolationActionBuilder for the full set of block* and passthrough* methods. Passthrough hosts do not receive the real secret value; substitution still only happens for hosts configured with allowHost() or allowHostPattern(). When a per-secret passthrough policy does not match the request host, microsandbox falls back to the sandbox-wide secret violation action.

Parameters

Configure the per-secret violation action.

secret.build()

Materialize the SecretEntry. Called for you by SandboxBuilder.secret, so you rarely call it directly. If placeholder was not set, it defaults to $MSB_<envVar>. Throws a MicrosandboxError if env or value was not set, or if the allow-list is empty.

Returns

The materialized secret entry.

ViolationActionBuilder

Builder for secret-violation behavior.

violation.block()

Silently drop a violating request. The guest sees a connection reset. The default is blockAndLog().

violation.blockAndLog()

Drop the request and emit a warning log on the host side.

violation.blockAndTerminate()

Drop the request, log an error, and shut down the entire sandbox.

violation.passthroughHost()

Forward requests to an exact host with the placeholder unchanged, instead of blocking. The host does not receive the real value. Non-matching hosts fall back to the base block* action.

Parameters

hoststring
Exact hostname to forward unchanged.

violation.passthroughHostPattern()

Forward requests to any host matching a wildcard pattern with the placeholder unchanged.

Parameters

patternstring
Wildcard pattern, e.g. “*.internal.example.com”.

violation.passthroughAllHosts()

Forward the placeholder unchanged to every host instead of blocking. The call is a no-op unless iUnderstand is true. The real value is still never substituted on these hosts; this only stops the request from being dropped.

Parameters

iUnderstandboolean
Must be true to take effect.

SandboxBuilder

Two methods on SandboxBuilder for adding secrets without reaching into a NetworkBuilder. Both automatically enable TLS interception.

sandbox.secret()

Add a secret with full configuration via a SecretBuilder closure. The builder’s build() is called for you.

Parameters

Configure the secret.

sandbox.secretEnv()

Three-argument shorthand. Auto-generates the placeholder as $MSB_<envVar> and allows substitution only on allowedHost. The default injection scopes apply (headers and Basic Auth enabled, query and body disabled).
Plaintext at rest. The value is persisted verbatim in the durable sandbox config until a later modify rotate migrates the entry to a source reference. Use this path when you hold only a value; a future host-side secret store will switch it to import-then-reference with no signature change.

Parameters

envVarstring
Environment variable name (non-empty, no = or NUL).
valuestring
Secret value.
allowedHoststring
Allowed destination host (exact match).

NetworkBuilder

The same secret configuration is available inside SandboxBuilder.network(n => ...) for callers who are already configuring networking. These methods set the secrets and the sandbox-wide violation policy directly on the network.

network.secret()

Add a secret with full configuration via a SecretBuilder closure. Identical in behavior to SandboxBuilder.secret.

Parameters

Configure the secret.

network.secretEnv()

Four-argument shorthand. Same as the SandboxBuilder form but lets you provide the placeholder explicitly instead of auto-generating $MSB_<envVar>.

Parameters

envVarstring
Environment variable name (non-empty, no = or NUL).
valuestring
Secret value.
placeholderstring
Explicit placeholder: non-empty, up to 1024 bytes, no NUL/CR/LF.
allowedHoststring
Allowed destination host (exact match).

network.secretEnvSimple()

Three-argument shorthand on NetworkBuilder. Auto-generates the placeholder as $MSB_<envVar>, matching SandboxBuilder.secretEnv.

Parameters

envVarstring
Environment variable name (non-empty, no = or NUL).
valuestring
Secret value.
allowedHoststring
Allowed destination host (exact match).

network.onSecretViolation()

Set the sandbox-wide secret violation policy: what happens when any secret’s placeholder is sent to a host outside that secret’s allow-list. Per-secret SecretBuilder.onViolation overrides this for the secret it is set on. See ViolationActionBuilder for the available actions.

Parameters

Configure the sandbox-wide violation action.

Types

SecretEntry

Returned by SecretBuilder.build()

The object produced by SecretBuilder.build(). You normally construct one with the builder, but the shape is available for callers that prefer plain objects.

SecretInjection

Used by SecretEntry.injection

Controls where the TLS proxy substitutes the placeholder with the real value. Each field is optional; omitted fields use the default. Set through the inject* methods on SecretBuilder.

ViolationAction

Built by ViolationActionBuilder

The string identifier for the base action taken when a secret placeholder is sent to a disallowed host. Configured through ViolationActionBuilder (via SecretBuilder.onViolation or NetworkBuilder.onSecretViolation). The ViolationActions array enumerates all values.