> ## 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

> Limit what a sandbox can connect to, and who can connect to it. boat enforces the policy on the host, outside the sandbox, also against root.

Data can leave a sandbox in three ways. A network policy closes each one.

```text theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
internet ──2──▶ ┌─────────┐ ──1──▶ any site
                │ sandbox │
                └─────────┘ ──3──▶ boat API
```

| Way out | What closes it | Read |
| - | - | - |
| 1. Code in the sandbox calls out to a site | Outbound: `deny` or `allow` | [Outbound](https://docs.boat.dev/network-policy/outbound.md) |
| 2. Someone connects to a port of the sandbox | Inbound: `boat-only` | [Inbound](https://docs.boat.dev/network-policy/inbound.md) |
| 3. Code calls the boat API with another key | Automatic with `deny` or `allow` | [The boat API](https://docs.boat.dev/network-policy/outbound.md#the-boat-api) |

Without a policy, a sandbox is open in both directions.

## Quick path

```bash One sandbox theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
boat new --network deny --inbound boat-only
boat network get bx_f7k2q9hd
boat network set bx_f7k2q9hd allow --allow github.com --allow '*.npmjs.org'
```

```bash Every sandbox of an environment theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
boat env set base --network deny --inbound boat-only
boat env upgrade base     # also move the sandboxes that already exist
```

```bash curl theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
curl -sS -X PUT "https://boat.dev/api/v1/sandboxes/bx_f7k2q9hd/network" \
  -H "Authorization: Bearer $BOAT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"mode":"deny","inbound":"boat-only"}'
```

In the dashboard, use the **Network** section of a sandbox or of an environment.

> [!WARNING]
>
> A key needs the `network.write` action to change a policy. Only the `admin` preset holds it. Read [Who can change it](https://docs.boat.dev/network-policy/reference.md#who-can-change-it).

## Learn more

> [card] [Outbound](https://docs.boat.dev/network-policy/outbound.md)
>
> Block every connection, or allow a list of domains and IP ranges.

> [card] [Inbound](https://docs.boat.dev/network-policy/inbound.md)
>
> Let only boat connect. Code inside cannot make a port public.

> [card] [Environments and organizations](https://docs.boat.dev/network-policy/environments.md)
>
> Set one policy for many sandboxes, and roll out a change.

> [card] [Run untrusted code](https://docs.boat.dev/network-policy/untrusted-code.md)
>
> The full setup, step by step.

> [card] [Reference](https://docs.boat.dev/network-policy/reference.md)
>
> Status, permissions, errors and limits.

## Related

* [Security and isolation](https://docs.boat.dev/security.md)
* [Firewall rules inside a sandbox](https://docs.boat.dev/hosting/firewall.md)
* [Set a network policy (API)](https://docs.boat.dev/api/reference/sandboxes/set-network-policy.md)


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