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

# Network policy reference

> Status values, who can change a network policy, what keeps it, errors with their fix, and the limits of a policy.

## Status

`boat network get <id>` and `GET /sandboxes/{id}/network` show `network.status`.

| Status | Meaning |
| - | - |
| `enforced` | The host confirmed the policy |
| `pending` | boat saved the policy. The host has not fully applied it. boat retries by itself. |
| `none` | Both sides are `open`. Nothing is blocked. |

With `pending`, `network.pendingReason` gives the cause:

| Reason | Until it ends, the sandbox has |
| - | - |
| `host` | Its previous rules. A stopped sandbox gets the policy before its next start. |
| `transfer` | The new rules. A restore or a snapshot still runs. |

`PUT` answers `200` for `enforced` or a stopped sandbox, and `202` for `pending`. `boat network set --wait` waits for `enforced`.

## Who can change it

| Policy of | Who |
| - | - |
| A personal environment | You |
| An organization environment | Its owners and admins |
| A sandbox | Its creator. In an organization environment, also owners and admins. |

A key also needs the `network.write` action. Only the `admin` preset holds it. An environment needs `environment.write` too.

A key **without** `network.write` never changes a policy, by any route. The sandbox gets the policy that it has without the key. Another policy, also a tighter one, gets `403 api_key_action_forbidden`. This includes a new sandbox from a saved snapshot that holds a policy, unless the environment sets the same policy.

The key inside a sandbox never holds `network.write`.

## What keeps the policy

| Action | The policy |
| - | - |
| Stop, resume, host move | Stays |
| Fork | The fork has the policy of its source |
| Saved snapshot | A sandbox from it starts with the policy that the saved sandbox had at capture |
| Resume or fork with `--environment` | A sandbox that follows its environment takes the new one's policy |
| Boat CI runner | Always `open` |

* A fork, or a sandbox from a saved snapshot, follows its own environment when its source followed one.
* A policy in the create or fork request applies instead.

## Errors

* `400 invalid_network_policy`: An entry is bad, covers the boat API, or the `allow` list is empty. Fix the entry that the message names.
* `403 api_key_action_forbidden`: The key lacks `network.write`. Use a session or an `admin` key.
* `403 network_policy_managed`: The organization environment sets the policy. Ask an owner or an admin.
* `403 inbound_closed`: The sandbox has `inbound: boat-only`. Use `boat exec`, and [publish ports from outside](https://docs.boat.dev/network-policy/inbound.md#publish-a-port).
* `403 sandbox_bound`: The call comes from inside a [bound sandbox](https://docs.boat.dev/network-policy/outbound.md#the-boat-api). Run it from outside.
* `409 network_policy_unsupported`: No host can enforce the policy for this sandbox now. Stop it, set the policy, resume it. On create, try again later.
* `409 network_policy_agent_outdated`: The sandbox started before network policies. Stop it, set the policy, resume it.
* `409 network_policy_changed`: Another request changed the policy during a resume or a policy change. Run the command again.

Inside the sandbox:

| What you see | Fix |
| - | - |
| A connection fails at once, or a name does not resolve | Add the host to the allow list. `boat network get <id>` shows the entries. |
| `https://boat.dev` does not answer | Use the `boat` CLI or `$ASCII_API_URL` |
| An environment change did not reach a running sandbox | Run `boat env upgrade <name>` |

## Limits

Know these before you rely on a policy.

> [accordion] An allowed site is a way out
>
> Code that can reach `github.com` can push data to any repository that it has credentials for. Allow only sites that you trust with the data.

> [accordion] A domain entry matches the name, not the content
>
> boat reads the server name of a TLS connection and does not decrypt it. A CDN can serve another of its sites on a connection that names an allowed one (domain fronting). With Encrypted Client Hello, boat sees the outer name only. Allow a CDN domain only if you accept this.

> [accordion] An IP entry allows every port and every site on that address
>
> Do not allow a range that holds the addresses of `boat.dev`. The sandbox then reaches the boat API directly, and boat does not limit it to its own credentials.
>
> Do not allow the address of a public DNS resolver, such as `1.1.1.1` or `8.8.8.8`. Code can then send data out in DNS queries for any name.

> [accordion] A domain entry allows TCP 443 and 80 only
>
> HTTP/3 (QUIC) clients fall back to HTTP/2. On port 80, boat accepts one request per connection, no chunked request body and no WebSocket. Use HTTPS for these.

> [accordion] A sandbox restricted while it runs is not bound to the boat API
>
> Until its next start, code in it can use a key of any boat account. Check `network.apiBound`. Read [The boat API](https://docs.boat.dev/network-policy/outbound.md#the-boat-api).

> [accordion] A snapshot or a restore in progress keeps the storage servers reachable
>
> The status is `pending` with `pendingReason: transfer` until it ends. During that time, boat matches its storage servers by name only. Other customers of the storage provider use the same servers.

> [accordion] Inbound is open by default
>
> A person or a program that connects to the sandbox can read data from it. Set [`inbound: boat-only`](https://docs.boat.dev/network-policy/inbound).

> [accordion] The owner can read the sandbox
>
> `boat exec` and the file API return data from the sandbox to a key that holds these actions. A port that you publish serves what listens on it.

> [accordion] DHCP host name
>
> A cooperating sandbox on the same host can read the DHCP host name of a restricted sandbox. The bandwidth is very low.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.