Skip to main content
Configure sandbox networking. See Networking for usage and policy concepts.

NetworkPolicy

Used by NetworkBuilder.policy() · returned by NetworkPolicy factories

Ordered rule list with per-direction defaults. First-match-wins is evaluated independently for egress and ingress.

NetworkPolicy.builder()

Start the fluent NetworkPolicyBuilder. Equivalent to new NetworkPolicyBuilder(). String inputs (.ip(), .cidr(), .domain(), .domainSuffix()) are stored raw and parsed at build(), so the chain stays clean and the first parse or validation failure surfaces there.

Returns

Empty builder.

NetworkPolicy.none()

Deny all traffic in both directions, no rules. The guest is fully offline. exec and fs still work since they use the host-guest channel, not the network.

NetworkPolicy.allowAll()

Unrestricted network access: allow everything in both directions, no rules. Includes private addresses and the host machine.

NetworkPolicy.fromProfiles()

Build a deny-by-default policy from "public", "private", and "host" profiles. Duplicate profiles are ignored, rules use canonical order, and every non-empty profile set receives one narrow gateway DNS rule. An empty set permits no egress and adds no DNS; ingress defaults to allow.

Rule

Used by NetworkPolicy.rules · built via Rule factories

A single ordered policy rule.

Rule.allowEgress()

Allow rule with direction egress. Empty protocols and ports mean “any”.

Parameters

destinationDestination
Target filter.

Rule.denyEgress()

Deny rule with direction egress.

Parameters

destinationDestination
Target filter.

Rule.allowIngress()

Allow rule with direction ingress.

Parameters

destinationDestination
Target filter.

Rule.denyIngress()

Deny rule with direction ingress.

Parameters

destinationDestination
Target filter.

Rule.allowAny()

Allow rule with direction any (matches in either direction).

Parameters

destinationDestination
Target filter.

Rule.denyAny()

Deny rule with direction any (matches in either direction).

Parameters

destinationDestination
Target filter.

Rule.allowDns()

Allow plain DNS (UDP/53 and TCP/53) to the sandbox gateway, i.e. the in-process DNS forwarder. The standard one-liner for opening DNS under a deny-by-default policy. See DNS as egress for the underlying semantics. DoT (TCP/853) is intentionally not included; add an explicit Destination.group("host") tcp/853 allow rule if needed (and pair with TLS interception).

Rule.denyDns()

Deny plain gateway DNS (UDP/53 and TCP/53). Place this rule before profile-generated rules to override their automatic DNS access.

Destination

Used by Rule.destination · built via Destination factories

Destination filter. An internally-tagged union; use the Destination factory for constructors.

Destination.any()

Match any destination.

Destination.cidr()

Match an IP range.

Parameters

cidrstring
CIDR notation, e.g. “10.0.0.0/8”.

Destination.domain()

Match an exact domain.

Parameters

domainstring
Fully qualified domain name.

Destination.domainSuffix()

Match the apex domain and every subdomain.

Parameters

suffixstring
Domain suffix.

Destination.group()

Match a predefined address group.

Parameters

Group keyword.

PortRange

Used by Rule.ports · built via PortRange factories

Inclusive port range. Always interpreted as the guest-side port.

PortRange.single()

Match a single port. start and end are set to the same value.

Parameters

portnumber
Port number.

PortRange.range()

Match an inclusive port range.

Parameters

startnumber
Lower bound (inclusive).
endnumber
Upper bound (inclusive).

NetworkBuilder

Passed to the callback you give SandboxBuilder.network(...). Every setter returns the same builder. The runtime serializes the accumulated config when the sandbox is created.

network.policy()

Set the policy. Accepts a NetworkPolicy literal or factory result, or a NetworkPolicyBuilder (routed through the native bridge so lazy parse/validation errors surface at this call site).

Parameters

Policy literal, factory result, or builder.

network.port()

Publish a TCP port from the guest to the host. The default host bind address is 127.0.0.1.

Parameters

hostnumber
Port on the host.
guestnumber
Port inside the sandbox.

network.portBind()

Publish a TCP port on a specific host bind address, such as 0.0.0.0.

Parameters

bindstring
Host bind address.
hostnumber
Port on the host.
guestnumber
Port inside the sandbox.

network.portUdp()

Publish a UDP port from the guest to the host. The default host bind address is 127.0.0.1.

Parameters

hostnumber
Port on the host.
guestnumber
Port inside the sandbox.

network.portUdpBind()

Publish a UDP port on a specific host bind address.

Parameters

bindstring
Host bind address.
hostnumber
Port on the host.
guestnumber
Port inside the sandbox.

network.dns()

Configure DNS interception. See DnsBuilder.

Parameters

configureDnsBuilder
Configure DNS.

network.tls()

Configure TLS interception. See TlsBuilder.

Parameters

configureTlsBuilder
Configure TLS.

network.trustHostCAs()

Whether to ship the host’s trusted root CAs into the guest at boot. Default: false. Opt in for corporate MITM proxies (Cloudflare Warp Zero Trust, Zscaler, Netskope, etc.) whose gateway CA is installed on the host but unknown to the guest’s stock Mozilla bundle.

Parameters

enabledboolean
Ship host CAs into the guest.

network.maxConnections()

Limit the maximum number of concurrent network connections from the sandbox.

Parameters

maxnumber
Maximum concurrent connections.

network.rateLimiter()

Configure network rate limits. Egress and ingress are independently optional; an omitted direction is unlimited. The limit applies on the next sandbox start.

network.ipv4Pool()

Set the IPv4 pool used to derive per-sandbox /30 guest subnets. Defaults to 172.16.0.0/12.

Parameters

poolstring
IPv4 CIDR pool.

network.ipv6Pool()

Set the IPv6 pool used to derive per-sandbox /64 guest prefixes. Defaults to fd42:6d73:62::/48.

Parameters

poolstring
IPv6 CIDR pool.

network.interface()

Override per-sandbox interface attributes (MAC, MTU, fixed IPv4 / IPv6 address). The InterfaceOverridesBuilder exposes .mac(), .mtu(), .ipv4(), and .ipv6().

Parameters

Configure interface overrides.

network.enabled()

Enable or disable networking entirely. When false, no network interface is created.

Parameters

enabledboolean
Master enable flag.

network.onSecretViolation()

Configure the action taken when a secret reaches a disallowed host. See ViolationActionBuilder.

Parameters

Configure the violation action.
Passthrough hosts receive placeholders unchanged. They do not receive real secret values.

network.secret()

Add a secret with full configuration. See SecretBuilder.

Parameters

configureSecretBuilder
Configure the secret.

network.secretEnv()

Four-arg explicit-placeholder shorthand for adding a secret without opening a builder callback.

Parameters

envVarstring
Environment variable name (non-empty, no = or NUL).
valuestring
Real secret value.
placeholderstring
Placeholder string: non-empty, up to 1024 bytes, no NUL/CR/LF.
allowedHoststring
Single hostname allowed to receive the real value.

network.secretEnvSimple()

Three-arg auto-placeholder shorthand. Auto-generates the placeholder as $MSB_<envVar>, so it is the terse counterpart to secretEnv() when you do not need a custom placeholder. The full secret API also lives on the secrets page.

Parameters

envVarstring
Environment variable name (non-empty, no = or NUL).
valuestring
Real secret value.
allowedHoststring
Single hostname allowed to receive the real value.

network.build()

Materialize the accumulated state into a NetworkConfig. The native bridge returns snake_case serde output, which the wrapper remaps to camelCase keys before handing back a plain JS object. Inside SandboxBuilder.network(...) the runtime calls this for you; call it directly only when you want to inspect or persist the resolved config.

Returns

The materialized network configuration.

NetworkPolicyBuilder

Fluent builder for NetworkPolicy.

policy.defaultDeny()

Set both defaultEgress and defaultIngress to "deny".

policy.defaultAllow()

Set both defaultEgress and defaultIngress to "allow".

policy.defaultEgress()

Per-direction override for the egress default action.

Parameters

action”allow” | “deny”
Default action for egress.

policy.defaultIngress()

Per-direction override for the ingress default action.

Parameters

action”allow” | “deny”
Default action for ingress.

policy.egress()

Sugar for rule() with direction pre-set to egress.

Parameters

configureRuleBuilder
Add egress rules.

policy.ingress()

Sugar for rule() with direction pre-set to ingress.

Parameters

configureRuleBuilder
Add ingress rules.

policy.any()

Sugar for rule() with direction pre-set to any. Rules committed inside apply in both directions.

Parameters

configureRuleBuilder
Add bidirectional rules.

policy.rule()

Open a multi-rule batch closure. Direction must be set inside via .egress(), .ingress(), or .any() before any rule-adder.

Parameters

configureRuleBuilder
Add rules; set direction first.

policy.build()

Materialize the accumulated state into a NetworkPolicy. Lazily parses every recorded .ip() / .cidr() / .domain() / .domainSuffix() input, validates direction-set and ICMP-egress-only invariants, and emits a host-side warning for each shadowed rule pair.

Returns

The materialized policy.

RuleBuilder

Builder for one policy-rule batch.

rule.egress()

Set direction to egress for subsequent rule-adders.

rule.ingress()

Set direction to ingress for subsequent rule-adders.

rule.any()

Set direction to any for subsequent rule-adders. Rules committed after this apply in both directions.

Protocol setters

Protocols accumulate as a set; duplicates dedupe.

rule.tcp()

Add tcp to the protocols set.

rule.udp()

Add udp to the protocols set.

rule.icmpv4()

Add icmpv4 to the protocols set. Egress-only; an ICMP rule on an ingress or any direction fails build.

rule.icmpv6()

Add icmpv6 to the protocols set. Egress-only; same rules as icmpv4().

Port setters

Ports accumulate as a set; duplicates dedupe. Always guest-side (egress destination port / ingress listening port).

rule.port()

Add a single port to the ports set.

Parameters

portnumber
Port number 0..=65535.

rule.portRange()

Add an inclusive port range. lo > hi records an error surfaced at build() time.

Parameters

lonumber
Lower bound (inclusive).
hinumber
Upper bound (inclusive).

rule.ports()

Add multiple single ports. Equivalent to calling port() once per element.

Parameters

portsnumber[]
Port numbers.

Group rule-adders

Each adder commits one rule using the current state and the named destination group.

rule.allowPublic()

Allow the public group (complement of named categories: every IP not in any other group).

rule.denyPublic()

Deny the public group.

rule.allowPrivate()

Allow the private group (RFC1918 + ULA + CGN).

rule.denyPrivate()

Deny the private group.

rule.allowLoopback()

Allow the loopback group (127.0.0.0/8, ::1). The guest’s own loopback, not the host. To reach a service on the host’s localhost, use allowHost() instead. See the loopback-vs-host watch-out.

rule.denyLoopback()

Deny the loopback group.

rule.allowLinkLocal()

Allow the link-local group (169.254.0.0/16, fe80::/10). Excludes the metadata IP 169.254.169.254.

rule.denyLinkLocal()

Deny the link-local group.

rule.allowMeta()

Allow the metadata group (169.254.169.254). Dangerous on cloud hosts (exposes IAM credentials).

rule.denyMeta()

Deny the metadata group.

rule.allowMulticast()

Allow the multicast group (224.0.0.0/4, ff00::/8).

rule.denyMulticast()

Deny the multicast group.

rule.allowHost()

Allow the host group: per-sandbox gateway IPs that back host.microsandbox.internal. This is the right shortcut for “let the sandbox reach my host’s localhost”, not allowLoopback().

rule.denyHost()

Deny the host group.

Composite rule-adders

rule.allowLocal()

Add three allow rules atomically: loopback + link-local + host. Each uses the callback’s current state. metadata is intentionally not included; opt in via allowMeta() separately.

rule.denyLocal()

Add three deny rules atomically: loopback + link-local + host. metadata is intentionally not included.

Domain rule-adders

Singular forms add one rule; plural forms add one rule per element.

rule.allowDomain()

Add one Destination::Domain allow rule.

Parameters

namestring
Fully qualified domain name.

rule.denyDomain()

Add one Destination::Domain deny rule.

Parameters

namestring
Fully qualified domain name.

rule.allowDomains()

Add one Destination::Domain allow rule per name.

Parameters

namesstring[]
Fully qualified domain names.

rule.denyDomains()

Add one Destination::Domain deny rule per name.

Parameters

namesstring[]
Fully qualified domain names.

rule.allowDomainSuffix()

Add one Destination::DomainSuffix allow rule. Matches the apex and any subdomain.

Parameters

suffixstring
Domain suffix.

rule.denyDomainSuffix()

Add one Destination::DomainSuffix deny rule. Matches the apex and any subdomain.

Parameters

suffixstring
Domain suffix.

rule.allowDomainSuffixes()

Add one Destination::DomainSuffix allow rule per suffix.

Parameters

suffixesstring[]
Domain suffixes.

rule.denyDomainSuffixes()

Add one Destination::DomainSuffix deny rule per suffix.

Parameters

suffixesstring[]
Domain suffixes.

Explicit-destination rule-adders

.allow() / .deny() open a RuleDestinationBuilder callback. Exactly one destination call commits the rule.

rule.allow()

Begin an explicit-destination rule with action allow.

Parameters

Commit exactly one destination.

rule.deny()

Begin an explicit-destination rule with action deny.

Parameters

Commit exactly one destination.

RuleDestinationBuilder

Returned by RuleBuilder.allow(d => ...) / .deny(d => ...). Exactly one destination call commits the rule; dropping without a destination call silently does nothing.

destination.ip()

Commit with Destination::Cidr of the IP as /32 or /128.

Parameters

ipstring
Single IPv4 or IPv6 address.

destination.cidr()

Commit with Destination::Cidr.

Parameters

cidrstring
CIDR notation.

destination.domain()

Commit with Destination::Domain.

Parameters

domainstring
Fully qualified domain name.

destination.domainSuffix()

Commit with Destination::DomainSuffix.

Parameters

suffixstring
Domain suffix.

destination.group()

Commit with Destination::Group. group is a DestinationGroup string.

Parameters

Group keyword.

destination.any()

Commit with Destination::Any.

DnsBuilder

Builder for DNS interception settings. Used in NetworkBuilder.dns(d => ...). Owns rebind protection, nameserver pinning, and the per-query timeout.

dns.rebindProtection()

Toggle DNS rebinding protection. When enabled, DNS responses resolving to private IPs are blocked.

Parameters

enabledboolean
Enable rebinding protection.

dns.nameservers()

Override upstream nameservers. Replaces any previously-set nameservers.

Parameters

serversstring[]
Each entry is IP, IP:PORT, HOST, or HOST:PORT.

dns.queryTimeoutMs()

Per-DNS-query timeout in milliseconds.

Parameters

msnumber
Timeout in milliseconds.

TlsBuilder

Builder for TLS interception settings. Used in NetworkBuilder.tls(t => ...).

tls.bypass()

Skip TLS interception for hosts matching this glob (e.g. "*.internal.corp"). Use for domains with certificate pinning.

Parameters

patternstring
Glob pattern.

tls.verifyUpstream()

Verify upstream server certificates. Default true. Set to false only for self-signed servers.

Parameters

verifyboolean
Verify upstream certs.

tls.verifyUpstreamFor()

Verify upstream server certificates only when the upstream SNI matches pattern. Pattern syntax matches bypass(): exact hosts and *.suffix wildcards are supported. Setting verify to false is the proxy-side equivalent of curl -k for matching hosts; TLS interception still runs.

tls.interceptedPorts()

TCP ports where interception is active. Default: [443].

Parameters

portsnumber[]
Intercepted TCP ports.

tls.blockQuic()

Block QUIC on intercepted ports, forcing TCP/TLS fallback.

Parameters

blockboolean
Block QUIC.

tls.interceptCaCert()

Path to a PEM file used as the intercepting CA’s certificate.

Parameters

pathstring
PEM cert path.

tls.interceptCaKey()

Path to a PEM file used as the intercepting CA’s private key.

Parameters

pathstring
PEM key path.

tls.upstreamCaCert()

Path to a PEM file with extra root CAs the proxy should trust when verifying every upstream server.

Parameters

pathstring
PEM cert path.

tls.upstreamCaCertFor()

Path to a PEM file with extra root CAs the proxy should trust only when the upstream SNI matches pattern. Pattern syntax matches bypass(): exact hosts and *.suffix wildcards are supported.

ViolationActionBuilder

Configures the action taken when a secret would be sent to a disallowed host. Used in NetworkBuilder.onSecretViolation(v => ...). Passthrough host calls accumulate; when passthrough hosts are configured, non-matching hosts use the default secret-violation action.

violation.block()

Block the request silently.

violation.blockAndLog()

Block the request and emit a warning log.

violation.blockAndTerminate()

Block the request and terminate the sandbox.

violation.passthroughHost()

Allow placeholders to pass through unchanged to an exact host. The host receives the placeholder, not the real secret value.

Parameters

hoststring
Exact host.

violation.passthroughHostPattern()

Allow placeholders to pass through unchanged to matching wildcard hosts.

Parameters

patternstring
Wildcard host pattern.

violation.passthroughAllHosts()

Allow placeholders to pass through unchanged to any host. The explicit iUnderstand flag must be true to acknowledge the broad scope.

Parameters

iUnderstandboolean
Must be true to opt in.

NetworkRateLimiterBuilder

Groups local rate limits by traffic direction. Supplied to NetworkBuilder.rateLimiter().

.egress()

Configure the guest-to-runtime direction.

.ingress()

Configure the runtime-to-guest direction.

RateLimiterBuilder

Builder for one direction’s rate limiter, supplied to NetworkRateLimiterBuilder.egress() or ingress(). A limiter caps bandwidth (bytes) and packet rate (frames) independently; leaving a bucket unset leaves that dimension unlimited. Buckets start full plus their one-time burst and refill continuously. Every setter returns this. Validation runs at NetworkBuilder.build(): a limiter with neither bucket, a zero bucket size or refill interval, or a burst without its bucket throws. Bucket values must be non-negative integers.

.bandwidth()

Cap bandwidth at sizeBytes bytes per refillTimeMs milliseconds.

Parameters

sizeBytesnumber
Bucket capacity in bytes.
refillTimeMsnumber
Time to refill the full bucket, in milliseconds.

.bandwidthBurst()

Grant a one-time startup burst of extra bytes on top of the bandwidth bucket. The burst is spent before the regular budget and never refills. Requires bandwidth().

.ops()

Cap packet rate at count frames per refillTimeMs milliseconds.

.opsBurst()

Grant a one-time startup burst of extra frames on top of the ops bucket. Requires ops().

InterfaceOverridesBuilder

Used by NetworkBuilder.interface()

Builder for per-sandbox network interface overrides.

interface.mac()

Set the interface MAC address

interface.mtu()

Set the interface MTU

interface.ipv4()

Pin a fixed IPv4 address

interface.ipv6()

Pin a fixed IPv6 address

Types

NetworkConfig

Returned by NetworkBuilder.build()

Built network configuration produced by NetworkBuilder.build(). Keys are camelCased from the Rust serde output.

NetworkProfile

Composable high-level access category accepted by NetworkPolicy.fromProfiles().

Action

Used by Rule.action · NetworkPolicy defaults

Action taken on a matching rule (or the per-direction default).

Direction

Used by Rule.direction

Direction the rule applies to.

DestinationGroup

Used by Destination.group() · RuleDestinationBuilder.group()

Predefined address group keyword. The runtime constant DestinationGroups lists all values.

Protocol

Used by Rule.protocols

Transport protocol filter. Empty Rule.protocols means “any protocol”.

PublishedPort

Used by NetworkConfig.ports

A published port mapping from the guest to the host.

DnsConfig

Used by NetworkConfig.dns

DNS interception configuration.

TlsConfig

Used by NetworkConfig.tls

TLS interception configuration.

ScopedUpstreamCaCert

ScopedVerifyUpstream

NetworkRateLimiterConfig

Used by NetworkConfig.rateLimiter

Local network rate limits grouped by direction. An omitted direction is unlimited.

RateLimiterConfig

Held by NetworkRateLimiterConfig

Rate limiter for one traffic direction. A missing bucket leaves that dimension unlimited.

TokenBucketConfig

Held by RateLimiterConfig

One token bucket of a rate limiter: starts full, refills continuously at size tokens per refillTimeMs, and the one-time burst never refills.