Skip to main content
An egress policy limits which hosts a Sailbox can connect to, and can add credentials to the HTTPS requests it sends. Connections into the Sailbox are covered by Access control. The one setting on this page that reaches them is no_network, which stops every connection in both directions. A Sailbox gets its policy when it is created and can be given a new one at any time. Without one, it can reach any host. Changing one Sailbox’s policy does not affect any other. This page shows what a policy can say and how to set one. The reference has the exact rules for each field.

The document

A policy is a JSON document with these optional fields: An entry in allowlist or blocked is a hostname (api.github.com), a wildcard for a host’s direct subdomains (*.github.com matches api.github.com but not github.com or a.b.github.com), an IPv4 address, or an IPv4 range (203.0.113.0/24). A hostname entry allows every kind of connection to that host, including SSH and plain HTTP. Let the Sailbox reach only package registries and GitHub:
Reach GitHub and its direct subdomains, except Gist:
Reach GitHub and add a token to every request sent to its API:
${secrets.GITHUB_TOKEN} names a secret stored with Sail. The Sailbox never sees its value, and a document that references a secret must be saved before a Sailbox can use it. Credential injection walks through that flow.

No egress and no network

{"allowlist": []} stops outbound connections. {"no_network": true} also stops inbound ones.
  • No egress, {"allowlist": []}, also stops name lookups. You can still expose a port or use SSH.
  • No network, {"no_network": true}, is for work that should have no network at all. It cannot be combined with other fields or set on a Sailbox that exposes a port or SSH. Running commands, the shell, and mounted volumes keep working.

Setting a policy

Pass a document, or a saved policy, as egress_policy when you create a Sailbox (egressPolicy in TypeScript). Each SDK builds the common documents for you: allow_all() is {}, allow_only(...) is a document with only an allowlist, no_egress() is {"allowlist": []}, and no_network() is {"no_network": true}.
  • A document that breaks a rule in the reference fails the call, naming the entry to fix, before a Sailbox is created.
  • no_network cannot be combined with ingress_ports; the other documents can.
  • A Sailbox created from a checkpoint starts with the policy its source has at that moment. After that the two are independent.

Replacing the policy

set_egress_policy replaces a Sailbox’s policy and returns the new one. clear_egress_policy removes all restrictions and rules.
  • The new policy applies to connections opened after the call. Connections that are already open keep the previous policy until they close, except under no_network, which stalls them until a later policy restores network access.
  • A sleeping or paused Sailbox takes the new policy when it next runs.
  • no_network is refused while the Sailbox exposes ports or SSH.

Reading it back

Every Sailbox reports the policy it runs under: the document in force, plus the id and name of the saved policy it came from. The handle create returns does not carry the policy; fetch the Sailbox to read it.

Saved policies

A document passed straight to a Sailbox belongs to that Sailbox alone. A saved policy is a document stored under a name for your whole organization. Save a policy to reuse it across Sailboxes or to use secrets in its rules. Only a saved policy can reference a secret, and the secret must exist first.
  • A saved policy’s document cannot be edited, only its name. To change behavior, save a new policy and set it.
  • Deleting a policy fails while a Sailbox that is not terminated uses it. Give those Sailboxes another policy first. A terminated Sailbox that used the deleted policy keeps only its allowlist and blocked entries, so a Sailbox later created from one of its checkpoints starts without the policy’s rules.
  • The listing shows how many Sailboxes use each policy and which secrets it names.

Blocked

blocked removes destinations from what the Sailbox may otherwise reach. Each entry must be narrower than what covers it: a hostname under a *. wildcard in the allowlist, or an address inside an allowed range. Without an allowlist, only addresses and ranges can be blocked. The reference has every accepted form.

Rules

rules maps a host to the rules for the HTTPS requests the Sailbox sends to it. A rule can change the request, forward it to another host, or answer it. Plain HTTP and other traffic pass through untouched.
  • Hosts are exact (api.example.com), a direct-subdomain wildcard (*.example.com), or * for every host not named elsewhere. Use an exact host whenever a rule adds a credential.
  • A rule does not make its host reachable. With an allowlist, every host that has rules must also be in the allowlist.
  • match narrows a rule by method, path, headers, or query. A rule without match covers every request and must be last in its list.
Each action’s fields, templates, forwarding failures, missing_alpn, and the other details are in the reference.

Harbor

A Harbor task’s network allowlist or no-network setting becomes the Sailbox’s egress policy. A task that changes its policy mid-run changes the Sailbox’s policy at that point. See Harbor for the task features Sailboxes support.