# Egress rules

Set `allow_hosts` to choose the hosts a sandbox can reach. Everything else is blocked.

```
curl https://api.groundbox.dev/v1/sandboxes \
  -H "Authorization: Bearer $GROUNDBOX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"cpus": 2, "allow_hosts": ["github.com", "*.npmjs.org", "140.82.112.0/20"]}'
```

Set `deny_hosts` for the opposite: the sandbox reaches everything but these.

```
curl https://api.groundbox.dev/v1/sandboxes \
  -H "Authorization: Bearer $GROUNDBOX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"cpus": 2, "deny_hosts": ["*.tracker.example.net", "203.0.113.0/24"]}'
```

An entry in either list is one of four things.

- A host name, like `github.com`. It matches that name only.
- A wildcard, like `*.npmjs.org`. It matches every name under the domain, at any depth. It does not match the domain itself, so list `npmjs.org` too if you need it.
- An IPv4 address, like `203.0.113.7`.
- An IPv4 network, like `140.82.112.0/20`.

You can set both lists. A denied entry wins: allow `*.example.com` and deny `internal.example.com` to carve one name out. Change either list while the sandbox runs. The change applies at once, and `null` removes a list.

```
curl -X PATCH https://api.groundbox.dev/v1/sandboxes/sbx_8f3k2m9x1q7w \
  -H "Authorization: Bearer $GROUNDBOX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"allow_hosts": ["github.com"], "deny_hosts": null}'
```

In the CLI it is `--allow-host` and `--deny-host` on `sandbox create`, and `groundbox sandbox egress <id>` to see or change the rules later. The SDKs have `set_egress`, and the MCP server has the `sandbox` tool's `egress` action.

## DNS

A sandbox with egress rules has its DNS answered by Groundbox, whichever DNS server it asks. With an allowlist, only the names on the list resolve. Any other name gets no answer and the lookup never leaves Groundbox, so a sandbox cannot pass data out in lookups of names you did not list. With a deny list, the denied names do not resolve.

What the rules do not do:

- A lookup under an allowed wildcard reaches that domain's own name servers. Allow a wildcard only for a domain you trust with what the sandbox knows.
- The rules match hosts, not URLs or ports. A sandbox that may reach a host may send it anything.
- Names are matched to addresses. Two names on one address, as behind a shared CDN, are allowed or denied together.
- A deny list of names holds against ordinary DNS. A sandbox with only a deny list can still reach an encrypted DNS service or connect to an address it already knows. Deny the address or network to close that, or use an allowlist when the sandbox must be sealed.
- Sandboxes have no IPv6 route out, so the rules are IPv4 only.
