Network model¶
Every connection a sandbox opens goes through the proxy of Docker Sandboxes, which applies the network policy of the daemon. fastsandbox adds rules to that policy for one sandbox at a time; it does not replace the policy, and it cannot choose it. This page explains how the rules combine, when each kind applies, and how to check what a sandbox can reach.
Two levels of rules¶
direction: down
request: A connection from the sandbox
proxy: The proxy of Docker Sandboxes {shape: hexagon}
deny: "A deny rule matches?\nglobal, kit or sandbox" {shape: diamond}
refused: "Refused: HTTP 403"
allow: "An allow rule matches?\nglobal, kit or sandbox" {shape: diamond}
reached: Reached
preset: "The preset of the global policy decides:\nreached under Open, refused or prompted otherwise"
request -> proxy -> deny
deny -> refused: "yes"
deny -> allow: "no"
allow -> reached: "yes"
allow -> preset: "no"
- The global policy holds for every sandbox of the user.
sbxsets it up with one of three presets, chosen the first time it runs in a terminal: Open, which allows all outbound traffic; Balanced, which denies by default and allows a baseline of AI services, package managers, code hosts and registries; Locked Down, which allows nothing. See the Docker documentation. fastsandbox never sets up the global policy, and changes it only when you callclient.policy, which affects every sandbox. - The rules of a sandbox come from its kit, such as the hosts the kit of an agent declares, and from what fastsandbox adds for it. They go with the sandbox.
The rules combine in two ways:
- A deny rule wins, whatever its source: no allow rule, host or HTTP, reopens a host a rule denies.
- An allow rule adds; it does not restrict. Allowing
pypi.orglets the sandbox reachpypi.org; it does not keep the sandbox from other hosts. Under the Open preset, every host is allowed already, so the allow rules of a sandbox change nothing: only its deny rules restrict it.
An allow list is not an allowlist
A sandbox is confined to the hosts it allows only when the global policy
denies the rest: under the Balanced or Locked Down preset. fastsandbox
cannot pick the preset for you. A launch whose spec allows hosts while
the global policy allows every host says so in
lease.report.network.warning, and a run of a task logs it as a warning
on the logger of the task, fastsandbox.task.<name>.
The kinds of rules¶
| Kind | Matches | Set with | In force |
|---|---|---|---|
| Host rule | A host, by pattern, on TCP (a deny also covers UDP) | Network.allow(), Network.deny(), SandboxSpec.with_network_allow() / with_network_deny() |
From the creation of the sandbox: forged into its kit, the daemon creates them with it |
| HTTP rule | Methods and a path on a host, HTTP and HTTPS only | Network.allow_http(), Network.deny_http(), SandboxSpec.with_http_allow() / with_http_deny() |
Before the start of the sandbox: its startup commands included, not its install commands |
| A rule of a running sandbox | A host | sandbox.allow_hosts(), sandbox.deny_hosts() |
From the call |
A host is written as the sbx command line takes it: api.example.com,
api.example.com:443, *.example.com for one label, **.example.com for
any number, an IPv4 address or prefix, ** for every host. fastsandbox
refuses any other form, a URL for instance, before it reaches the daemon,
which would store it and never apply it. See
The hosts a rule names.
Beyond the rules, Docker Sandboxes blocks UDP (unless an experimental feature allows it) and ICMP, and sandboxes cannot reach each other, according to its documentation.
Two setups, with their conditions¶
Keep a sandbox from some hosts. This works under every preset:
The sandbox cannot reach the denied hosts; every other host stays as the global policy has it, all of them under Open.
Confine a sandbox to some hosts. This needs the Balanced or Locked Down preset:
Under those presets the sandbox reaches the allowed hosts, those its kit
declares and those of the baseline of Balanced; a host no rule decides is
refused, or raises an approval prompt that
client.prompts streams. Under Open, the same
task can reach every host. A refusal is answered by the proxy with HTTP 403.
Checking what a sandbox can reach¶
| To know | Ask | Limits |
|---|---|---|
| The rules the daemon holds | client.policy.rules(), or sbx policy ls |
Every rule, global and scoped to a sandbox |
| The rules scoped to one sandbox | sandbox.network_rules() |
Not the global rules, which apply too |
| Whether a host is allowed | client.policy.check() |
The global policy only: the rules of a sandbox are not taken into account |
| What sandboxes reached, or were refused | client.policy.log(), filtered with for_sandbox(name) |
It keeps a removed sandbox, by name: a later sandbox of the same name continues its counts. Read it in the task, before it returns, to see what that run alone reached |
| Whether the allowances of a launch restrict anything | lease.report.network.warning, ctx.lease.report in a task, a warning on fastsandbox.task.<name> for a run |
Set only when the spec allows hosts |
The only proof of what a sandbox reaches is a request sent from inside it, or the activity log. Restrict network access does both for an agent.
Limits¶
- A rule refused by the daemon fails the call that adds it; a launch checks
its hosts first and raises
InvalidSpecError. - A creation cut short, by a program killed during it for instance, can leave the kit rules of that sandbox name in the policy, where the next sandbox of the same name finds them. FastSandbox and the client give each sandbox a unique name by default.
- The proxy can forward a request of a sandbox to a service on the loopback
of the host,
host.docker.internal:<port>, which is how an MCP server of the host is reached: deny that host when a task does not need it. - Whether an HTTP allow rule narrows a host under the Open preset was not measured.
Next¶
- Network rules: the rules of a task.
- Network and policy: the rules of a sandbox and the global policy, with the client.
- Restrict network access: the network of an agent, and what it reached.