Network
Used by Sandbox.create(network=…)
Sandbox network configuration.network.policy
NetworkPolicy \| None · Default: None
Concrete network policy
network.ports
Mapping[int, int] \| Sequence[PortBinding] · Default: {}
Port mappings from host to guest. Mapping form binds TCP to 127.0.0.1; PortBinding can set an explicit bind address or UDP
network.deny_domains
tuple[str, ...] · Default: ()
Deny egress to these exact domains. Each entry adds a deny Domain("...") policy rule that fires at DNS resolution (NXDOMAIN), TLS first-flight (SNI), and TCP egress (cache fallback). Prepended onto the policy so it takes precedence over later allow rules
network.deny_domain_suffixes
tuple[str, ...] · Default: ()
Deny egress to all subdomains of these suffixes. Adds deny DomainSuffix("...") rules; same enforcement layers as deny_domains
network.dns
DnsConfig \| None · Default: None
DNS interception configuration
network.tls
TlsConfig \| None · Default: None
TLS interception configuration
network.ipv4_pool
str \| None · Default: None
IPv4 pool used for per-sandbox /30 guest subnets. Defaults to 172.16.0.0/12
network.ipv6_pool
str \| None · Default: None
IPv6 pool used for per-sandbox /64 guest prefixes. Defaults to fd42:6d73:62::/48
network.max_connections
int \| None · Default: None
Maximum concurrent connections
network.rate_limiter
NetworkRateLimiter \| None · Default: None
Ingress and egress rate limits
network.on_secret_violation
ViolationAction\|ViolationPolicy · Default: BLOCK_AND_LOG
Sandbox-wide action when a secret placeholder reaches a disallowed host
Network.none()
Example
Example
exec and fs still work since they use the host-guest channel, not the network.
Returns
Network.from_profiles()
PUBLIC, PRIVATE, and HOST profiles. Duplicate profiles are ignored, generated rules use canonical order, and gateway DNS is added automatically for every non-empty profile set.
Returns
Network.allow_all()
Returns
Rule
Used by NetworkPolicy(rules=…)
Frozen dataclass for a single network policy rule. Prefer theRule.allow() / Rule.deny() class methods over the positional constructor.
rule.action
Action
What to do when this rule matches
rule.direction
Direction · Default: EGRESS
Which evaluator considers this rule. Direction.ANY matches in either direction
rule.destination
str \| NetworkDestination \| None · Default: None
Target filter. Prefer typed Destination helpers; string shorthand also works (DestGroup values, exact IPs, domains, CIDR ranges, domain suffixes prefixed with ".", or "*" for any). Domain and suffix strings are validated at sandbox creation; invalid names raise ValueError
rule.protocol
Protocol \| None · Default: None
Protocol filter
rule.port
int \| str \| None · Default: None
Single port (443) or range ("8000-9000")
Ingress rules carrying ICMP protocols are rejected at sandbox creation; the host has no inbound ICMP path. Use Direction.EGRESS for ICMP allow/deny.
A NetworkPolicy is an ordered list of Rule values plus two per-direction defaults, evaluated first-match-wins per direction. The class methods below build rules; assemble them into NetworkPolicy(rules=(...)) and pass it as Network(policy=...).
Rule order matters
The first matching rule wins, so a broad rule placed before a narrow one swallows it:Rule.allow()
Example
Example
Parameters
directionDirectionEGRESS.protocolProtocol | Noneportint | str | None443) or range (“8000-9000”).destinationstr | NetworkDestination | NoneReturns
Rule.deny()
allow().
Parameters
directionDirectionEGRESS.protocolProtocol | Noneportint | str | Nonedestinationstr | NetworkDestination | NoneReturns
Rule.allow_dns()
Example
Example
(udp_rule, tcp_rule) since this SDK’s Rule shape carries a single protocol; splat into NetworkPolicy.rules. DoT (TCP/853) is intentionally not included; add an explicit Rule.allow(destination=Destination.group(DestGroup.HOST), protocol=Protocol.TCP, port=853) if needed (and pair with TLS interception).
Rule.deny_dns()
Returns
(udp_rule, tcp_rule) for DestGroup.HOST on port 53.Destination
Returns NetworkDestination · used by Rule.allow() / Rule.deny()
Factory for typedNetworkDestination values.
Destination.any()
Destination.ip()
/32 for IPv4 or /128 for IPv6.
Parameters
ipstrDestination.cidr()
Parameters
cidrstr“10.0.0.0/8”.Destination.domain()
ValueError.
Parameters
domainstrDestination.domain_suffix()
Parameters
suffixstr“.example.com”.Destination.group()
DestGroup address group.
Parameters
groupDestGroupPortBinding
Used by Network(ports=…)
Frozen dataclass for a published host-to-guest port with an optional host bind address. Prefer thePortBinding.tcp() / PortBinding.udp() class methods.
binding.host_port
int
Port on the host
binding.guest_port
int
Port inside the sandbox
binding.bind
str · Default: "127.0.0.1"
Host address to bind. Use 0.0.0.0 for all IPv4 interfaces
binding.protocol
PortProtocol · Default: TCP
Published port protocol
PortBinding is a frozen dataclass for published ports that need an explicit host bind address or UDP. Prefer the protocol-specific constructors over building one by hand.
Network(ports=(...)). A plain dict[int, int] is also accepted for the common case, binding TCP to 127.0.0.1.
PortBinding.tcp()
Parameters
host_portintguest_portintbindstr127.0.0.1; use 0.0.0.0 for all IPv4 interfaces.Returns
PortBinding.udp()
Parameters
host_portintguest_portintbindstr127.0.0.1.Returns
NetworkPolicy
Used by Network(policy=…)
Ordered rules with per-direction defaults.policy.default_egress
Action · Default: DENY
Action when no egress-applicable rule matches
policy.default_ingress
Action · Default: ALLOW
Action when no ingress-applicable rule matches
policy.rules
tuple[Rule, ...] · Default: ()
Rules evaluated first-match-wins per direction
Class methods none() and allow_all() construct terminal whole policies. from_profiles(profiles) composes NetworkProfile values with canonical ordering and automatic gateway DNS.
NetworkPolicy.none()
Returns
NetworkPolicy
NetworkPolicy.allow_all()
Returns
NetworkPolicy
NetworkPolicy.from_profiles()
Returns
NetworkPolicy
Types
NetworkProfile
NetworkDestination
Produced by Destination helpers
Frozen dataclass produced byDestination helpers.
NetworkDestinationKind
Returned in NetworkDestination.kind
Network destination variant.DnsConfig
Used by Network(dns=…)
Frozen dataclass for DNS interception settings. The value type ofNetwork.dns; import it from microsandbox.types.
TlsConfig
Used by Network(tls=…)
Frozen dataclass for TLS interception settings withinNetwork.
ScopedUpstreamCACert
Used by TlsConfig(scoped_upstream_ca_certs=…)
A CA bundle trusted only for upstream hosts matching a pattern.ScopedVerifyUpstream
Used by TlsConfig(scoped_verify_upstream=…)
A per-host override for upstream certificate verification.NetworkRateLimiter
Used by Network.rate_limiter
Groups local network limits by traffic direction. An omitted direction is unlimited.RateLimiter
Held by NetworkRateLimiter
Limits bandwidth and packet rate for one traffic direction.TokenBucket
Used by RateLimiter
Token-bucket configuration for one rate-limiter dimension.Action
Used by NetworkPolicy · Rule
Policy action.Direction
Used by Rule
String enum for traffic direction.Protocol
Used by Rule
String enum for network protocols in policy rules.PortProtocol
Used by PortBinding
String enum for port-level protocol selection.DestGroup
Used by Destination.group()
String enum for well-known destination groups used inDestination.group() or string-shorthand Rule.destination.