Skip to main content
Configure a sandbox’s network stack: a first-match-wins egress/ingress policy, published ports, DNS interception, TLS interception, and secret-violation handling. See Networking for the conceptual overview and TLS Interception for proxy details. The Go SDK exposes networking as a single NetworkConfig struct passed to WithNetwork. Common shapes come from the NetworkPolicy factory; custom firewalls are built by populating NetworkConfig.Rules directly.

Functions

m.WithNetwork()

Set the network configuration for the sandbox. Pass a profile policy from the NetworkPolicy factory, or a custom NetworkConfig value with your own rules, DNS, TLS, and port settings.

Parameters

Network stack configuration.

Returns

SandboxOption
Option to pass to CreateSandbox.

m.WithPorts()

Make TCP services running in the sandbox reachable on localhost ports on the host. Each map entry exposes the guest port (value) on the host port (key), bound to 127.0.0.1. Called multiple times, the maps merge.

Parameters

portsmap[uint16]uint16
Host port to guest port (TCP).

Returns

SandboxOption
Option to pass to CreateSandbox.

m.WithPortsUDP()

Make UDP services running in the sandbox reachable on localhost ports on the host. Each map entry exposes the guest port (value) on the host port (key), bound to 127.0.0.1. Called multiple times, the maps merge.

Parameters

portsmap[uint16]uint16
Host port to guest port (UDP).

Returns

SandboxOption
Option to pass to CreateSandbox.

m.WithPortBindings()

Make services running in the sandbox reachable on explicit host addresses and ports. Use this when the default 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

Explicit bind address, host port, guest port, and protocol.

Returns

SandboxOption
Option to pass to CreateSandbox.

NetworkPolicy

Factory namespace returning high-level *NetworkConfig values. Access through the package-level NetworkPolicy value.

NetworkPolicy.FromProfiles()

Build a deny-by-default policy from 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

Config containing canonical profile and DNS rules.
When profile names come from JSON, configuration, environment variables, or other runtime input, use the checked variant instead:

NetworkPolicy.FromProfilesChecked()

Builds the same canonical deny-by-default policy as FromProfiles, but returns an error instead of panicking when a profile is unknown. Use this method for values derived from runtime input.

Returns

Config containing canonical profile and DNS rules.
error
Non-nil when any requested profile is unknown.

NetworkPolicy.None()

Block all network traffic in both directions. The network interface remains present; Exec and FS still work because they use the host-guest channel.

Returns

Config with deny defaults in both directions.

NetworkPolicy.AllowAll()

Permit all network traffic, including private addresses and the host machine.

Returns

Config with allow defaults in both directions.

Rule

The package-level Rule 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 populating NetworkConfig.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 via WithNetwork.

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; use PolicyDirectionEgress 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 a PolicyRule.

PolicyDirection

Used by PolicyRule.Direction

The direction half of a PolicyRule. 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 a PolicyRule.

NetworkProfile

Composable profile names accepted by NetworkPolicy.FromProfiles().

Destination groups

Used by PolicyRule.Destination

The Destination 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.