Skip to content

[Sandbox] Add network policies: no internet access, or an allowlist - #5303

Open
Wauplin wants to merge 6 commits into
mainfrom
sandbox-network-policies
Open

Wauplin wants to merge 6 commits into
mainfrom
sandbox-network-policies

Conversation

@Wauplin

@Wauplin Wauplin commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Sandboxes can now run without internet access, or with access to an allowlist only. This follows the plan from this Slack thread (plan) and covers #5261 for the Sandbox API.

  • New network argument on Sandbox.create and SandboxPool.create: "none", or {"allow": [...]} with IP ranges, IPs (with an optional port) and hostnames.
  • New --network option on hf sandbox create: none, or a comma-separated allowlist. It also works with --pool.
  • The server sends the policy back, and the client checks it. If it does not match (an older server ignores the policy), creation fails and the job is canceled.
  • Docs: Sandbox guide, concepts page and CLI guide.
sbx = Sandbox.create("python:3.12", network="none", volumes=[...])  # volumes still work
sbx = Sandbox.create("python:3.12", network={"allow": ["10.0.0.0/8", "203.0.113.10:443", "huggingface.co"]})
agent = pool.create(network="none")  # pools can mix isolated and connected sandboxes
hf sandbox create --network none
hf sandbox create --network 10.0.0.0/8,huggingface.co:443

This needs a sandbox-server release with huggingface/sandbox-server#32, then a bump of SANDBOX_SERVER_SHA256 / SANDBOX_SERVER_VERSION. Until then, network= fails with a clear error.

Decisions

  • No Jobs backend change. The backend team said in the thread that no egress plus volumes is hard to do there. The sandbox server takes the network away from the commands it runs, with seccomp and Landlock, and keeps its own.
  • API shape comes from the plan, which the requester approved in the thread.
  • TCP only, even with an allowlist, so DNS tunnels stay closed. Allowlisted hostnames are resolved by the server and written to /etc/hosts.
  • One --network CLI option rather than two flags.
  • Out of scope: run_job / hf jobs run --network (from [Jobs] Option to run a job without outbound network access #5261) need backend support. Keeping a vLLM token inside the server, as the plan mentions, is not done here.

Tested end to end on HF Jobs (dedicated and pool) with a build of the new server.

🤖 Generated with Claude Code


Note

Medium Risk
Changes sandbox security boundaries and pins a new sbx-server version; creation fails safely when servers are too old, but policy enforcement depends on correct server rollout and pool host recycling.

Overview
Adds configurable outbound network policies for Sandboxes: network="none" blocks all egress, or {"allow": [...]} permits only listed TCP destinations (ranges, IPs with ports, or hostnames). The same option works on Sandbox.create, SandboxPool.create, and hf sandbox create --network (including pooled sandboxes).

Policies are sent to sbx-server 0.8.0 (pinned digest updated) via SBX_NETWORK on dedicated jobs or the pool create API body. The client verifies the server echoes the policy after create; mismatches (e.g. older hosts) raise SandboxError, cancel the job where applicable, and for pools delete a wrongly provisioned sandbox before failing.

Documentation covers the feature end-to-end (guide, concepts Network policies, CLI reference) and updates isolation/limitation text so unrestricted egress is only the default, not the only mode.

Reviewed by Cursor Bugbot for commit 0ddfe92. Bugbot is set up for automated code reviews on this repo. Configure here.

Wauplin and others added 3 commits November 4, 2026 15:49
Sandbox.create / SandboxPool.create take network="none" or
network={"allow": [...]}, and hf sandbox create takes --network. The
client checks that the sandbox server applied the policy and refuses the
sandbox otherwise. Requires a sandbox-server release with network policies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…isor

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 31d6c5e. Configure here.

Comment thread src/huggingface_hub/_sandbox.py Resolved
@bot-ci-comment

bot-ci-comment Bot commented Nov 4, 2026

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Pages changed in this PR:

Wauplin and others added 2 commits November 5, 2026 01:30
…nores the network policy

The DELETE /v1/sandboxes/{id} route is scoped since sbx-server 0.7.0 and refuses the host token,
so the cleanup failed, the outdated-server error never surfaced, and the unrestricted sandbox stayed
on the host. Also tailor the remedy per mode, and drop the review notes committed by mistake.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…case for 'none', document supervisor limits

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Built from huggingface/sandbox-server@ef31b89 (v0.8.0), which includes
huggingface/sandbox-server#32.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Wauplin
Wauplin marked this pull request as ready for review November 19, 2026 11:40

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant