# Control network access (https://kumoba.dev/guide/network)

A sandbox has no network device of its own. Its traffic goes through a proxy in kumobad, which enforces the sandbox's policy and logs every connection.

| Mode | The sandbox can reach |
| --- | --- |
| `open` (default) | The public internet |
| `allowlist` | Only the listed host names, `*.example.com` subdomains, IP addresses and ranges, on ports 80 and 443 or the `:port` given |
| `blocked` | Nothing |

Private and IPv6 addresses are reachable only when the operator opens them, and loopback, link-local, cloud metadata and the host's own addresses never are, whatever the mode. [Always blocked](/http-api#always-blocked) lists exactly which addresses.

## Set the policy when you create a sandbox [#set-the-policy-when-you-create-a-sandbox]

```sh
kumoba create --image default --network.mode allowlist --network.hosts pypi.org,files.pythonhosted.org -q
```

`kumoba run` takes the same options.

In `allowlist` mode the proxy only tunnels connections, so a plain `http://` request through it gets `405 Method Not Allowed`. Use `https://` URLs, and install packages from sources that are `http://`, such as Debian's apt sources, while the mode is `open`.

An entry can be an IP address or a CIDR range, and any entry can name one port instead of 80 and 443:

```sh
kumoba create --image default --network.mode allowlist \
  --network.hosts 10.20.0.0/16,git.example.com:7999,'[2001:db8::/32]:443' -q
```

Address and range entries match connections to an IP address; a host name is matched only by a name entry, even when it resolves into a listed range. A private range such as `10.20.0.0/16`, and any IPv6 address, is reachable only when the operator also opens it, on that port, with `KUMOBAD_ALLOW_PRIVATE_HOSTS`, and the [always blocked](/http-api#always-blocked) addresses never are. Write IPv6 entries in brackets, `[2001:db8::7]` or `[2001:db8::/32]:443`. The CLI reads a list that starts with `[` as JSON, so pass a lone bracketed IPv6 entry as `'["[2001:db8::7]:8443"]'`. See [Allowlist entries](/http-api#allowlist-entries) for the full syntax.

## Change the policy of a sandbox [#change-the-policy-of-a-sandbox]

Update it, started or stopped:

```sh
kumoba update "$id" --network.mode allowlist --network.hosts pypi.org
```

On a started sandbox the new policy applies without a restart: new connections follow it, and open connections it no longer allows are closed promptly and logged as `revoked`. This holds for a sandbox started with `blocked` too: its proxy refuses everything until the network is turned on. See [Change the network of a started sandbox](/http-api#change-the-network-of-a-started-sandbox).

A stopped sandbox with secrets can't switch to `blocked`, because secrets are injected by the HTTPS proxy; remove its secrets first with `kumoba set-secrets "$id" secrets='[]'`. A started one can, to cut its network at once, but it won't start again until its network is opened or its secrets are removed.

A new policy must still reach a host of each of the sandbox's secrets. To take away a host that a secret is for, drop the secrets it no longer reaches in the same call:

```sh
kumoba update "$id" --network.mode allowlist --network.hosts pypi.org --drop-unreachable-secrets
```

The answer lists the removed secrets in `droppedSecrets`. Either the new policy and the removal both apply, or nothing changes. See [Narrow the network and drop secrets in one call](/http-api#narrow-the-network-and-drop-secrets-in-one-call).

## See what a sandbox connected to [#see-what-a-sandbox-connected-to]

```sh
kumoba access-log
```

Each entry has the sandbox, host (the address, for a connection to an IP address), port, whether the connection was allowed, denied, or allowed but failed to connect (`failed`), and the bytes in each direction. By default you get the last two hours; `--since-ms` and `--until-ms` choose another window.

## Reach an intranet or go through a corporate proxy [#reach-an-intranet-or-go-through-a-corporate-proxy]

These are daemon settings, set in kumobad's environment:

- `KUMOBAD_ALLOW_PRIVATE_HOSTS=gitlab.corp.example,10.20.0.0/16,10.30.0.0/16:5432` lets sandboxes reach those private hosts and ranges, on ports 80 and 443 unless an entry adds `:port` or `:*`. IPv6 ranges, always in brackets (`[2600:1f18:abcd::/56]:443`), are reachable only when listed here. The [always blocked](/http-api#always-blocked) addresses stay blocked.
- `KUMOBAD_UPSTREAM_PROXY=http://proxy.corp.example:3128` sends outbound traffic through your proxy, except hosts in `KUMOBAD_NO_PROXY`. A host name in `KUMOBAD_ALLOW_PRIVATE_HOSTS` is reached directly, but a range there is not: connections to its addresses still go through the proxy unless `KUMOBAD_NO_PROXY` lists each exact address, since `KUMOBAD_NO_PROXY` takes names and single addresses, not ranges.

See [Configuration](/configuration) for every setting.