---
title: "Network defenses"
description: "Egress filtering, SSRF, DNS rebinding, and cloud-metadata protection"
icon: "network-wired"
---

All sandbox traffic flows through a host-side network stack. From inside the VM it looks like a normal network interface. On the host side, a user-space stack terminates every packet and checks it against policy before anything leaves. There is no host kernel routing or NAT in the path. The host process is the sandbox's entire view of the network.

This is the network chapter of the security model: the threats the stack is built to stop and where each defense lives. For day-to-day configuration like policies, ports, DNS knobs, and TLS inspection, see the [Networking guide](/networking/overview).

## Default posture

With no custom policy, a sandbox can reach the public internet and nothing inward:

- **Egress is deny-by-default** with one allowance: the public internet, plus DNS through the gateway. Private ranges, loopback, link-local, cloud metadata, and your host are all denied.
- **Ingress only reaches ports you publish**, and published ports bind to `127.0.0.1` on your host by default.

Everything below is about the threats that posture is designed to withstand.

## Private IPs and your local network

The largest class of real damage comes from a workload reaching things *inside* your network: the host itself, a local database, another machine on the same subnet. The default policy denies egress to everything that isn't the public internet, which covers:

- `10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`, `100.64.0.0/10`, `fc00::/7` (RFC 1918 + carrier-grade NAT + IPv6 ULA)
- `127.0.0.0/8`, `::1` (loopback)
- `169.254.0.0/16`, `fe80::/10` (link-local)
- `169.254.169.254` (cloud metadata, which takes precedence over link-local)
- the per-sandbox gateway, meaning your host (the `host` group)

So microsandbox drops `curl http://192.168.1.10` (a machine on your LAN) or `curl http://host.microsandbox.internal:5432` (a service on your host) at the gateway before it reaches the destination.

<Warning>
**`localhost` inside the guest is not your host.** `curl http://localhost:5432` from inside a sandbox does *not* reach a service on your machine. Inside the guest, `localhost` and `127.0.0.1` are the sandbox's own loopback, handled entirely by the guest kernel, so the request never reaches the host stack at all. To reach a service on your host, a workload would have to use `host.microsandbox.internal` (the `host` group), which the default policy denies. The `Loopback` group exists only to catch the unusual case of a guest crafting a raw packet addressed to `127.0.0.1` out its network interface, and the default policy denies that too.
</Warning>

<Frame>
  <img className="block dark:hidden" src="/images/security/curl-destinations-light.svg" alt="From inside a sandbox, localhost stays in the guest while host.microsandbox.internal and LAN addresses are dropped at the gateway." />
  <img className="hidden dark:block" src="/images/security/curl-destinations-dark.svg" alt="From inside a sandbox, localhost stays in the guest while host.microsandbox.internal and LAN addresses are dropped at the gateway." />
</Frame>

Override the default with allow-all egress only when a workload genuinely needs broad reach, or [turn networking off](/security/hardening#turn-the-network-off) when it needs none.

## Cloud metadata endpoints

On AWS, GCP, Azure, and similar platforms, `169.254.169.254` is the instance metadata service. It's a classic SSRF target because it hands temporary credentials to anything that can connect. The default policy blocks it. For custom policies that flip egress to allow-by-default, deny it explicitly:

<CodeGroup>
```typescript TypeScript
NetworkPolicy.builder()
  .defaultAllow()
  .egress((rule) => rule.denyMeta())
  .build();
```

```rust Rust
NetworkPolicy::builder()
    .default_allow()
    .rule(|r| r.egress().deny_meta())
    .build()?
```

```python Python
from microsandbox import Action, Destination, DestGroup, NetworkPolicy, Rule

policy = NetworkPolicy(
    default_egress=Action.ALLOW,
    default_ingress=Action.ALLOW,
    rules=(Rule.deny(destination=Destination.group(DestGroup.METADATA)),),
)
```

```go Go
network := &m.NetworkConfig{
    DefaultEgress: m.PolicyActionAllow,
    DefaultIngress: m.PolicyActionAllow,
    Rules: []m.PolicyRule{
        {
            Action: m.PolicyActionDeny,
            Direction: m.PolicyDirectionEgress,
            Destination: "metadata",
        },
    },
}
```

```bash CLI
msb create python --name worker \
    --net-default-egress allow \
    --net-rule "deny@meta"
```
</CodeGroup>

NAT64-translated access to IPv4 metadata and private ranges is treated the same way for NAT64 prefixes. The well-known `64:ff9b::/96` prefix is configured by default, and operators can add routed environment-specific `/96` prefixes with `--net-nat64-prefix`.

## DNS rebinding

An attacker who controls a domain can make it resolve to a public IP during the allowlist check, then flip to a private IP on a later lookup. The guest ends up making a request that *looked* bound for `evil.example.com` but actually lands on `192.168.1.10`.

Rebind protection catches this at the response level. microsandbox rewrites a private, loopback, or link-local answer to `NXDOMAIN` unless the first matching explicit, address-only egress rule permits the returned address. For example, the `private` profile allows private DNS answers while retaining protection against loopback, link-local, metadata, and unspecified addresses. Ordered address-specific denies still win; policy defaults, `Any` rules, and port-scoped rules do not disable the check. Disable rebind protection globally only when policy-aware exceptions cannot represent the intended access. See [DNS](/networking/dns).

Through the gateway, private reverse lookups (`in-addr.arpa`, `ip6.arpa`) require explicit access to the address they describe. A zone covering both public and private addresses, such as `172.in-addr.arpa`, requires access to the entire zone. `.local` discovery requires broad private-network access, as provided by the `private` profile; allowing only one subnet does not enable it. Platform policy can further restrict these permissions. This prevents PTR, SRV and TXT queries from using the host resolver to discover networks the sandbox cannot access.

Gateway replies are checked for restricted names and addresses in every record section, including aliases and configured NAT64 translations. Restricted extra records are removed only when a complete successful answer can stand on its own; otherwise the lookup returns `NXDOMAIN`. Replies changed by this filtering lose whole-message authentication and the DNSSEC authenticated-data flag, so clients that need those records may fail validation. Explicitly selected resolvers keep their existing routing and answer-address checks. Disabling rebinding protection disables these checks too.

## DNS-to-IP binding (TOCTOU)

Even without rebinding, a time-of-check to time-of-use race exists: an allowed domain resolves to an allowed IP when policy is checked, then the guest looks it up again at connect time and reaches a different IP.

Domain rules require a live DNS binding between the allowed name and destination IP. When an allowed TLS SNI name has no live binding, microsandbox re-resolves it through the policy-filtered resolver and requires the answer to contain the chosen IP. No prior guest lookup is required; connections without SNI still need a live binding. The same pin set gates [secret injection](/security/secrets).

## SNI spoofing

A TLS client picks the SNI in its ClientHello, and it's plaintext and unsigned. Some servers don't reject a mismatched SNI and complete the handshake against their default certificate anyway. That gives a workload a way to claim an allowed name while actually connecting elsewhere.

With SNI, both the name match and DNS-to-IP binding must pass. Refreshing a missing binding does not authorize an IP absent from the fresh answer. Intercepted HTTP also requires `Host` or `:authority` to match SNI, preventing domain-fronting.

## The DNS bypass surface

DNS-based defenses like block lists, rebind protection, and domain pinning only act on queries the interceptor sees. The gateway intercepts UDP/53 and TCP/53 directly, and DoT (TCP/853) when TLS inspection is enabled. microsandbox either refuses other transports at the port layer (DoQ, mDNS, LLMNR, NetBIOS-NS) or cannot distinguish them from ordinary traffic (DoH on TCP/443). Tunneled DNS (VPN, SOCKS5 hostname mode, HTTP `CONNECT`) rides inside the outer encrypted flow and never reaches the forwarder.

Where DNS integrity matters, pair DoT interception with a policy that denies egress UDP/53, TCP/53, and TCP/853 to everything except the gateway, and close tunnels by restricting egress to an allowlist. See [DNS](/networking/dns) for the transport-by-transport breakdown.

## Trusting host CAs

TLS inspection uses an auto-generated CA the guest trusts. A separate option, `trust_host_cas`, additionally ships your host's trusted root CAs into the guest so outbound TLS keeps working behind a corporate MITM proxy. It is **off by default** for a reason: anything in your host trust store becomes trusted inside every sandbox, so a CA an attacker managed to plant on your host would be trusted by your guests too. Leave it off unless you specifically need it. See [TLS inspection](/networking/tls).

## Out of scope

The network stack does not try to defend against:

- **Kernel exploits inside the guest.** The [microVM boundary](/security/isolation) is what contains a compromised guest.
- **Raw packet crafting from privileged host processes.** Host-side privileged code is on the trusted side.
- **Deep ICMP behavior.** Supported ICMP is limited to unprivileged echo, and traceroute-style flows aren't proxied.
- **Host trust store integrity** once `trust_host_cas` is opted in, as covered above.

## See also

- [Networking overview](/networking/overview): policies, ports, reaching the host
- [DNS](/networking/dns): interception and the controls that ride on it
- [TLS inspection](/networking/tls): plaintext visibility for per-host policy and secret injection
- [Secret handling](/security/secrets): how the same DNS and SNI machinery gates credential injection
