Join our Discord Server
Collabnix Team The Collabnix Team is a diverse collective of Docker, Kubernetes, and IoT experts united by a passion for cloud-native technologies. With backgrounds spanning across DevOps, platform engineering, cloud architecture, and container orchestration, our contributors bring together decades of combined experience from various industries and technical domains.

Local Network Policy for Docker Sandboxes: Presets, HTTP Method and Path Rules, and Testing with sbx policy

6 min read

Terminal-style graphic showing the command sbx policy allow network api.github.com --method GET with the title Local Network Policy for Docker Sandboxes

Every Docker Sandbox sends its outbound TCP traffic through a proxy that runs on your host. That proxy is where network policy is enforced, and the sbx policy command is how you control it. The Docker docs recently reworked the Local policy page under Sandboxes Governance, with clearer guidance on first-run preset selection, non-interactive setup for CI, and HTTP method and path rules. This post walks through that page from a practitioner angle: how to pick a preset, how to write host and HTTP level rules, how to test them before an agent runs, and how the local model differs from Docker Cloud Sandboxes.

If you run coding agents like Claude Code inside sandboxes, network policy is the main control that decides what the agent can reach. Getting it right means the agent can install packages and call its model API, while it cannot quietly post data to a host you never approved.

Prerequisites

  • The sbx CLI installed and signed in. See the install guide and Get started.
  • A recent sbx release. Per-sandbox deny rules at creation time (--deny-network) need v0.38.0 or later, according to the guide.
  • An agent kit to test with, for example claude, plus credentials for that agent.
  • If your Docker organization manages sandbox governance, know that it changes how local allow rules behave (covered below).

How the local policy is evaluated

The local policy is a set of network rules stored on your machine. A rule can be global, which means it applies to every sandbox on the host, or scoped to one sandbox by name. Three sources can contribute rules: your local rules, rules added by kits (including the built-in agent kits), and organization rules when governance is turned on.

A few evaluation details from the docs are worth keeping in mind:

  • Deny rules take precedence over allow rules for the same destination.
  • Non-HTTP TCP traffic such as SSH can be allowed with a hostname rule that includes the port, for example myhost:22, or with an address based rule.
  • ICMP is always blocked. Outbound UDP is an experimental feature that is off by default.
  • With organization governance active, only organization allow rules grant access. Your local allow rules become inactive, but your local deny rules are still evaluated, so you can tighten access further than the org does.

Step 1: Choose and initialize a preset

The first time you run a sandbox in an interactive terminal with no global policy in place, the CLI asks you to pick a preset. If a policy already exists, including one left over from an older install, it is reused without a prompt. There are three presets:

  • Open (allow-all): all outbound TCP is allowed, the same as a wildcard allow rule.
  • Balanced (balanced): default deny plus a baseline allowlist for AI provider APIs, package managers, code hosts, container registries and common cloud services.
  • Locked Down (deny-all): no baseline allow rules. Every destination needs a rule from you or from a kit.

In CI pipelines and on headless servers there is no prompt, so an uninitialized policy makes sbx run fail with an error. Initialize the preset explicitly as part of your pipeline setup:

sbx policy init balanced

Initialization is a one-time step. To move to a different preset later, you reset the policy instead of running init again (see Step 5). One subtle point from the guide: the preset is not an explicit deny rule. Kits can still add per-sandbox allow rules on top of Locked Down, so a kit for an agent can open its own model endpoint even under deny-all.

Under Balanced and Locked Down, a request that matches no rule is not simply dropped. It is held for your approval, so you can grant access one destination at a time while the agent works.

Step 2: Add host level allow and deny rules

Use sbx policy allow network and sbx policy deny network to layer rules on top of the preset. Changes apply right away, and rules are global unless you scope them. You can pass several hosts as one comma separated argument:

sbx policy allow network "api.anthropic.com,*.npmjs.org,*.pypi.org"
sbx policy deny network ads.example.com

Quote any argument with a wildcard so your shell leaves it alone. To scope a rule to a single sandbox, add --sandbox:

sbx policy allow network --sandbox my-sandbox api.example.com
sbx policy deny network --sandbox my-sandbox ads.example.com

You can also attach per-sandbox deny rules when you create or start the sandbox. Repeat the flag for more hosts. These rules show up in the sandbox listing and can be removed like any other sandbox scoped rule:

sbx create --deny-network ads.example.com claude .
sbx run --deny-network ads.example.com claude

Kits add their own allow rules. To see what a kit opened for a sandbox, filter the listing by source and type, then deny anything you do not want even though the kit allowed it:

sbx policy ls my-sandbox --source kit --type network --wide
sbx policy deny network --sandbox my-sandbox openrouter.ai

Step 3: Narrow access with HTTP method and path rules

A host rule is often too coarse. An agent may need to read a repository through the GitHub API without being able to write anywhere else on that host. Adding --method turns a network rule into an HTTP rule, and --path limits it to part of the URL space:

sbx policy allow network api.github.com --method GET --path '/repos/org/project/**'

Keep the path in single quotes so the shell does not expand the glob. A few rules from the guide that are easy to trip over:

  • --method takes a comma separated list such as GET,HEAD, or ANY for every method. ANY cannot be mixed with named methods.
  • When you omit --path it defaults to /**. A path without a method is rejected.
  • Each rule holds one path. Repeating --path keeps only the last one, and a comma is treated as part of the path, so write one rule per path.
  • Paths must start with / and be canonical: no query strings, fragments, percent encoding, repeated or trailing slashes, or dot segments.
  • The host is written without a scheme, so use api.example.com, not https://api.example.com. HTTP rules take hostnames only; use a plain network rule for an IP or CIDR range.

Deny rules accept the same flags. The common pattern is to allow a host broadly and then carve out a dangerous method and path:

sbx policy allow network api.example.com
sbx policy deny network api.example.com --method POST --path '/admin/**'

HTTP rules are listed separately with --type http. In a wide listing, host level rules show empty METHOD and PATH columns:

sbx policy ls --type http
sbx policy ls --wide

Step 4: Test the policy before the agent runs

sbx policy check network tells you whether the current policy would allow a destination. The target can be a hostname, a host:port pair, an IP address or a URL. Bare hostnames and IPs are evaluated against port 443. A denied check exits with a non-zero status, which makes it handy as a guard step in scripts:

sbx policy check network api.anthropic.com
sbx policy check network --sandbox my-sandbox api.example.com

Two limits matter here. First, a check never creates an approval request; a destination that would prompt for approval simply reports as denied. Second, the check evaluates the host only, not HTTP methods or paths. A host can look allowed in a check while a specific method and path on it is denied by an HTTP rule, so test HTTP rules by listing them, not by checking the host.

Step 5: Remove rules and reset

Remove a rule by its resource or by its rule ID. Rule IDs come from sbx policy ls --wide. Add --sandbox for sandbox scoped rules:

sbx policy rm network --resource ads.example.com
sbx policy rm network --sandbox my-sandbox --resource api.example.com
sbx policy ls --wide

To remove an HTTP rule by resource, pass the same --method and --path qualifiers you used to create it, or use its ID. To wipe everything and pick a new preset, reset the policy. This deletes the local policy store and restarts the daemon, and any running sandboxes stop when the daemon shuts down, so plan for it:

sbx policy reset
sbx policy reset --force

The --force flag skips the confirmation prompt, which is what you want in automation.

Local Sandboxes vs Cloud Sandboxes

Everything above targets the local daemon. Docker Cloud Sandboxes use a separate, network-only policy store with account and per-sandbox scopes, managed with the same verbs under sbx --cloud policy. The docs are explicit that local policy is not copied to cloud sandboxes, and rules you added locally do not transfer when you move a sandbox to the cloud.

sbx --cloud policy init deny-all
sbx --cloud policy allow network api.github.com:443

The behavior differs in ways that affect how you write rules:

  • Local policy init is a one-time setup. Cloud init sets the default mode for the account, or for one sandbox with --sandbox, keeps existing rules, and can be run again.
  • Cloud rules match network destinations only. HTTP method and path restrictions and --protocol are not supported there.
  • Local rules have IDs. Cloud rules do not, so sbx --cloud policy rm network --resource removes a pattern from whichever allow or deny list holds it.
  • sbx --cloud policy reset clears the custom account policy and leaves the local daemon alone.

A practical takeaway: if a workflow relies on HTTP path rules for safety, that guarantee exists locally but not in the cloud, so define a tighter host level allowlist for the cloud copy.

Troubleshooting

  • Allow rules have no effect, or a domain stays blocked after an allow. Organization governance is probably active. Run sbx policy ls and look for a Governance line that says it is managed by your org. Then run sbx policy ls --include-inactive to confirm your rule is marked inactive. Only an admin can change the org policy; local deny rules still work.
  • A method or path is blocked on an allowed host. An HTTP rule is denying it. List HTTP rules with sbx policy ls --type http. Remember that sbx policy check network only reports the host decision.
  • A request fails with “Approval required”. No rule matched, or an org rule requires approval. Run sbx policy approval ls to see the pending request and respond to it. Approval applies to later requests, so rerun the blocked operation afterward.
  • sbx run errors in CI. The global policy is not initialized. Add sbx policy init balanced before the first run.

Key takeaways

  • All sandbox TCP egress passes a host side proxy that enforces sbx policy rules; ICMP is blocked and UDP is opt-in and experimental.
  • Initialize the preset explicitly in CI with sbx policy init; Balanced is the recommended starting point.
  • Deny beats allow, kits can add per-sandbox allows even under Locked Down, and you can deny what a kit allowed.
  • Use --method and --path to grant least privilege access to APIs such as GitHub.
  • sbx policy check network evaluates hosts, not HTTP methods or paths.
  • Cloud Sandboxes keep a separate, host-only policy store; local rules never carry over.

References

Source guide: Docker Sandboxes Local policy. Related pages: sbx policy allow network, sbx policy deny network, sbx policy check network, sbx policy init, sbx policy ls, sbx policy rm network, sbx policy reset, and Manage cloud network policy.

Have Queries? Join https://launchpass.com/collabnix

Collabnix Team The Collabnix Team is a diverse collective of Docker, Kubernetes, and IoT experts united by a passion for cloud-native technologies. With backgrounds spanning across DevOps, platform engineering, cloud architecture, and container orchestration, our contributors bring together decades of combined experience from various industries and technical domains.

Understanding AI Embeddings and Vector Search for Beginners

Explore the world of AI embeddings and vector search, learning how they transform massive data into actionable insights, driving intelligent systems.
Collabnix Team
9 min read
Join our Discord Server