NetworkConfig struct passed to WithNetwork. Common shapes come from the NetworkPolicy factory; custom firewalls are built by populating NetworkConfig.Rules directly.
Functions
m.WithNetwork()
Example
Example
NetworkPolicy factory, or a custom NetworkConfig value with your own rules, DNS, TLS, and port settings.
Parameters
Returns
m.WithPorts()
Example
Example
127.0.0.1. Called multiple times, the maps merge.
Parameters
portsmap[uint16]uint16Returns
m.WithPortsUDP()
Example
Example
127.0.0.1. Called multiple times, the maps merge.
Parameters
portsmap[uint16]uint16Returns
m.WithPortBindings()
Example
Example
127.0.0.1 bind is too restrictive, for example to expose a port on 0.0.0.0. Accepts one or more PortBinding values.
Parameters
bindings…PortBindingReturns
NetworkPolicy
Factory namespace returning high-level*NetworkConfig values. Access through the package-level NetworkPolicy value.
NetworkPolicy.FromProfiles()
Example
Example
NetworkProfilePublic, NetworkProfilePrivate, and NetworkProfileHost. Duplicate profiles are ignored, rules use canonical order, and each non-empty set receives one gateway DNS rule. An empty profile set permits no egress and adds no DNS; ingress defaults to allow.
FromProfiles panics if passed a value other than the three package-defined NetworkProfile constants.
Returns
NetworkPolicy.FromProfilesChecked()
FromProfiles, but returns an error instead of panicking when a profile is unknown. Use this method for values derived from runtime input.
Returns
NetworkPolicy.None()
Example
Example
Exec and FS still work because they use the host-guest channel.
Returns
NetworkPolicy.AllowAll()
Example
Example
Returns
Rule
The package-levelRule factory provides semantic low-level rules. Rule.AllowDNS() returns a PolicyRule allowing gateway UDP/53 and TCP/53; Rule.DenyDNS() returns its deny counterpart. Put Rule.DenyDNS() before profile-generated rules when you need to override automatic DNS access.
Custom rules
Build a custom firewall by populatingNetworkConfig.Rules. Rules are evaluated first-match-wins per direction; DefaultEgress and DefaultIngress set the fall-through action. A broad rule placed before a narrow one swallows it, so put specific rules first.
Types
NetworkConfig
Used by WithNetwork() · returned by NetworkPolicy
The full network stack configuration passed viaWithNetwork.
PolicyRule
Used by NetworkConfig.Rules
A single firewall rule. Ingress rules carrying ICMP protocols are rejected at sandbox creation, since the host has no inbound ICMP path; usePolicyDirectionEgress for ICMP.
DNSConfig
Used by NetworkConfig.DNS
In-VM DNS proxy configuration.TLSConfig
Used by NetworkConfig.TLS
Transparent HTTPS inspection proxy configuration.ScopedUpstreamCACert
Used by TLSConfig.ScopedUpstreamCACerts
Host-scoped upstream CA bundle configuration.ScopedVerifyUpstream
Used by TLSConfig.ScopedVerifyUpstream
Host-scoped upstream certificate verification override.PortBinding
Used by WithPortBindings() · NetworkConfig.PortBindings
A host-to-guest port mapping with an explicit host bind address.Protocol defaults to TCP when empty. Use Bind: "0.0.0.0" to expose the published port on all IPv4 interfaces.
PortProtocol
Used by PortBinding.Protocol
Identifies the protocol for an exposed sandbox service.PolicyAction
Used by PolicyRule.Action · NetworkConfig.DefaultEgress
The action half of aPolicyRule.
PolicyDirection
Used by PolicyRule.Direction
The direction half of aPolicyRule. The Go SDK follows the Python naming (egress/ingress); the wire format carries these values.
PolicyProtocol
Used by PolicyRule.Protocol · PolicyRule.Protocols
The protocol half of aPolicyRule.
NetworkProfile
Composable profile names accepted byNetworkPolicy.FromProfiles().
Destination groups
Used by PolicyRule.Destination
TheDestination field on PolicyRule accepts these well-known group names alongside literal CIDRs and domains. A domain prefixed with . becomes a suffix match: .example.com matches api.example.com but not example.com.