> ## Documentation Index
> Fetch the complete documentation index at: /llms.txt
> Use this file to discover all available pages before exploring further.

# Egress allowlist

> Limit what a machine can reach on the internet, from the console, the CLI, or the SDKs.

By default a machine can reach anything on the internet. An egress allowlist narrows that to the hosts and addresses you name. Everything else is refused at the edge of the machine, before it leaves the host.

The allowlist is set from the outside: the machine's **Networking** tab in the console, `boxd machine egress` on your laptop, the SDKs, or a [machine spec](#from-birth-with-a-machine-spec). There is deliberately no way to change it from inside the machine. A process with root in the machine cannot widen its own allowlist, and an SDK running inside the machine on the machine's own credentials is refused when it tries to change that machine's allowlist, directly or through its spec.

The allowlist is one of two egress controls. See [Egress control](/guides/egress) for how it combines with host-bound secrets, forks, snapshots and isolation.

## Entries

An entry is one of:

| Entry | Example | Matches |
| - | - | - |
| A hostname | `api.stripe.com` | That host exactly. |
| A wildcard | `*.npmjs.org` | Any host under that domain (`registry.npmjs.org`), but `npmjs.org` itself needs its own entry. |
| An IPv4 address | `203.0.113.7` | That address. |
| An IPv4 range | `203.0.113.0/24` | Every address in the range. |
| `none` | `none` | Nothing. The allowlist is on with nothing in it, so the machine reaches nothing. |

Entries are bare hosts and addresses, without a scheme, port, or path. An allowlist holds at most 256 entries.

`none` is how you cut a machine off from the internet entirely, since an empty allowlist means unrestricted. It only means something on its own: next to any other entry it adds nothing and is dropped, because the other entries already confine the machine.

An internationalized name is kept in its ASCII (punycode) form, which is what the machine looks up: `bücher.de` becomes `xn--bcher-kva.de`, under a wildcard too. A name that isn't a valid internationalized domain name is refused.

**Wildcards** are allowed when every host under the domain belongs to one party. `*.npmjs.org` only reaches hosts npm runs.

They are refused on domains where anyone can get a subdomain, because that opens a way out to a host an attacker controls:

* `*.amazonaws.com` would admit every S3 bucket.
* `*.vercel.app` would admit every Vercel deployment.
* The same goes for `*.cloudfront.net`, `*.herokuapp.com`, `*.workers.dev`, `*.github.io`, `*.pages.dev` and other shared-hosting or CDN domains.

Name the exact host instead, such as `my-bucket.s3.amazonaws.com`. Top-level wildcards like `*.com` are refused as well.

**Addresses** must be public. Private, link-local, loopback and multicast ranges are refused, as is anything overlapping them, `0.0.0.0/0` included. IPv6 is refused too, because machines have no IPv6 egress.

## How it works

Web requests (HTTP and HTTPS) are admitted by the hostname they name, so `api.stripe.com` works whichever address it resolves to. Everything else, an SSH connection or a database port for example, is admitted by destination address. The addresses of an allowlisted name count as allowlisted too, so a plain `curl` to an allowlisted host works without you listing its addresses.

What a blocked request sees depends on the protocol: HTTP gets a `403`, HTTPS has its connection closed during the handshake, and anything else is dropped.

DNS follows the allowlist too. The machine's resolver answers only the names the machine may reach: the hosts and wildcards on the list, and the hosts of its host-bound secrets. A lookup of any other name is answered `REFUSED` without leaving boxd, so a lookup can't carry data out in the name itself. DNS to any other resolver is blocked like any other destination.

The hosts of any [host-bound secret](/guides/env-secrets.md#host-bound-secrets) the machine holds are always admitted, on top of the list, so a secret bound to `api.stripe.com` keeps working under an allowlist that does not name it.

## Set it

From your laptop:

```bash
boxd machine egress myapp                                  # show the current allowlist
boxd machine egress myapp api.stripe.com,*.github.com      # replace it (comma-separated)
boxd machine egress myapp none                             # nothing is reachable
boxd machine egress myapp --clear                          # back to unrestricted
```

The list you pass is the complete new allowlist. It replaces the old one. An empty allowlist means unrestricted, which is how every machine starts, and `none` means nothing is reachable.

In the console, open the machine, then **Networking**, then **Edit** next to the egress allowlist. A change takes effect within a second on a running machine, without a restart, and shows up in the console, the CLI and the SDKs at once.

## Read it from inside the machine

The machine can read its own policy but not change it. Inside a machine:

```bash
boxd machine egress          # the allowlist and the hosts of host-bound secrets
boxd info                    # the same, as a one-line summary
```

## From the SDKs

```typescript TypeScript
await boxd.machines.setEgressAllow("myapp", ["api.stripe.com", "*.github.com", "203.0.113.0/24"]);
(await boxd.machines.get("myapp")).egressAllow;      // what is in effect
await boxd.machines.setEgressAllow("myapp", ["none"]); // nothing is reachable
await boxd.machines.setEgressAllow("myapp", []);     // clear: unrestricted again
```

```python Python
boxd.machines.set_egress_allow("myapp", ["api.stripe.com", "*.github.com", "203.0.113.0/24"])
boxd.machines.get("myapp").egress_allow              # what is in effect
boxd.machines.set_egress_allow("myapp", ["none"])    # nothing is reachable
boxd.machines.set_egress_allow("myapp", [])          # clear: unrestricted again
```

Each call replaces the whole list.

## From birth, with a machine spec

A [machine spec](/guides/machine-specs.md) can carry the allowlist, so the machine has it from its first boot and never runs unrestricted:

```typescript TypeScript
import { Machine } from "@boxd-sh/sdk";

const spec = Machine.spec().egress("api.stripe.com", "*.ubuntu.com");
await boxd.machines.create({ name: "myapp", spec });
```

```python Python
from boxd import Machine

spec = Machine.spec().egress("api.stripe.com", "*.ubuntu.com")
boxd.machines.create("myapp", spec=spec)
```

The same rules apply, and a spec's entries can't be empty: leave `egress` out for no allowlist, or use `.egress("none")` for a machine that reaches nothing. Change the list later as usual, or with `updateSpec`. The machine's spec follows either way. A snapshot keeps its machine's spec, so a machine created from a snapshot of this one gets the allowlist too, where a snapshot of a machine without a spec gives none.

## What to use it for

An allowlist turns a machine into a place where an agent or a job can run with a known set of destinations: the model provider, your own API, the package registry. Combine it with an isolated machine and with host-bound secrets, and the machine can neither reach what it should not nor leak a credential to where it should not go. See [Sandboxes](/use-cases/sandboxes.md).
