Skip to content

feat: add sandbox network out configuration - #1447

Merged
dobrac merged 12 commits into
mainfrom
add-allow-deny-ip-egress-limit-suport
Nov 11, 2025
Merged

dobrac merged 12 commits into
mainfrom
add-allow-deny-ip-egress-limit-suport

Conversation

@dobrac

@dobrac dobrac commented Nov 6, 2025 •

Copy link
Copy Markdown
Contributor

Add sandbox network out traffic configuration. The usage would look then something like this:

const sbx = await Sandbox.create({
  network: {
    allowOut: ['8.8.8.8'],
    blockOut: ['8.8.0.0/16'],
  },
})

Note

Adds configurable egress allow/deny for sandboxes, wires it through API → orchestrator, enforces via firewall, and persists in snapshots; updates proto/spec and tests.

  • API:
    • Add SandboxNetworkConfig (allowOut, denyOut) to spec and generated types; include network in NewSandbox. Clarify allow_internet_access semantics (equivalent to denyOut: ["0.0.0.0/0"] when false).
    • Handlers pass network to orchestrator on create/resume/connect.
  • Orchestrator:
    • Accept and translate network config; if allowInternetAccess is false, set deny 0.0.0.0/0.
    • Update network pool/slot to configure per-sandbox egress; firewall refactor to allow/deny sets, allow-list precedence, support "block all", default-allow hyperloop IP, and validate private ranges cannot be allowed.
    • Extend gRPC/proto with SandboxNetworkConfig and egress fields.
  • DB:
    • Add snapshots.config (JSONB) via migration; define PausedSandboxConfig and SandboxNetworkConfig types; store network config on pause; update queries/models.
  • Tests:
    • Integration tests for egress allow/deny, CIDR handling, precedence, persistence across pause/resume, and hyperloop accessibility with blocked internet.
    • Unit tests for firewall address validation.

Written by Cursor Bugbot for commit 738177c. This will update automatically on new commits. Configure here.

@dobrac dobrac added the feature New feature label Nov 6, 2025
@dobrac
dobrac force-pushed the add-allow-deny-ip-egress-limit-suport branch 3 times, most recently from a0928bb to 1c34d0d Compare November 6, 2025 16:18
@dobrac
dobrac force-pushed the add-allow-deny-ip-egress-limit-suport branch from 1c34d0d to 09d9394 Compare November 6, 2025 16:22
@dobrac
dobrac force-pushed the add-allow-deny-ip-egress-limit-suport branch 2 times, most recently from 8d392ab to 5c95692 Compare November 7, 2025 11:53
@dobrac
dobrac force-pushed the add-allow-deny-ip-egress-limit-suport branch 3 times, most recently from 007f4f8 to 35fdb12 Compare November 7, 2025 16:41
@dobrac
dobrac force-pushed the add-allow-deny-ip-egress-limit-suport branch from 35fdb12 to 33c5a57 Compare November 10, 2025 18:34
@dobrac dobrac changed the title feat: add sandbox egress firewall for ip addresses feat: add sandbox network out configuration Nov 10, 2025
@dobrac
dobrac force-pushed the add-allow-deny-ip-egress-limit-suport branch 5 times, most recently from 4559b70 to b74976f Compare November 11, 2025 00:05
@dobrac
dobrac force-pushed the add-allow-deny-ip-egress-limit-suport branch from b74976f to 1c4264b Compare November 11, 2025 00:20
@dobrac
dobrac marked this pull request as ready for review November 11, 2025 00:32
@dobrac
dobrac force-pushed the add-allow-deny-ip-egress-limit-suport branch 2 times, most recently from 4404e80 to abb52a3 Compare November 11, 2025 01:07
@dobrac
dobrac force-pushed the add-allow-deny-ip-egress-limit-suport branch 2 times, most recently from 4c45801 to e62ca88 Compare November 11, 2025 01:21
@dobrac
dobrac force-pushed the add-allow-deny-ip-egress-limit-suport branch from e62ca88 to d9e12b3 Compare November 11, 2025 01:28
@dobrac
dobrac force-pushed the add-allow-deny-ip-egress-limit-suport branch from 0468847 to 01a4356 Compare November 11, 2025 01:58

// Handle the case where internet access is explicitly disabled
// This should be applied after copying the network config to preserve allowed addresses
if allowInternetAccess != nil && !*allowInternetAccess {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should return error when both network egress allow/block lists and allow internet are provided. It can bring unexpected behavior for users.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The allowOut takes precedence over blockOut

also, internet is defined by default, allowInternetAccess false does the same as blockOut=[0.0.0.0/0]


network := &types.SandboxNetworkConfig{
Egress: &types.SandboxNetworkEgressConfig{
AllowedAddresses: config.GetNetwork().GetEgress().GetAllowedAddresses(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are we sure this call chain will work correctly when communicating with orchestrators that are not yet supporting network configuration?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thing was if we will not receive nil. It not, that is okay.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we'll receive nil for the list, but nil is a valid empty list


// AddBlockedIP adds a single CIDR to the block set at runtime.
func (fw *Firewall) AddBlockedIP(cidr string) error {
func (fw *Firewall) AddBlockedIP(address string) error {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We switched to inserting blocked IPs and not using CIDRs, which seems cleaner to me.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Function comment still refers to CIDRs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

you can insert:

  • One IP
  • Cidr
  • IP range (1.1.1.0-1.1.1.1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we make it cidr only to simplify thinking around? I think api should move all three types (i dont like IP range tho) to CIDR format.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed support for IP ranges, passing now addresses only as CIDR blocks to the orchestrator. In the DB, they're saved as user provided

@sitole

sitole commented Nov 11, 2025

Copy link
Copy Markdown
Member

Btw @dobrac can we check with deny all hyperloop server is still working?

@dobrac
dobrac force-pushed the add-allow-deny-ip-egress-limit-suport branch from 5857131 to a0f052f Compare November 11, 2025 13:34
@dobrac
dobrac requested a review from sitole November 11, 2025 13:35
@dobrac
dobrac force-pushed the add-allow-deny-ip-egress-limit-suport branch from a0f052f to 61047a4 Compare November 11, 2025 13:36
network.Egress = &orchestrator.SandboxNetworkEgressConfig{}
}
network.Egress.DeniedCidrs = []string{internetBlockCIDR}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Global Config Overwrites User Network Access

Global config AllowSandboxInternet can override user-provided network configuration when AllowInternetAccess is not explicitly set in the request. If a user provides custom network.denyOut addresses without setting allowInternetAccess, and the global config is false, the orchestrator overwrites DeniedCidrs with ["0.0.0.0/0"], discarding the user's explicit configuration. This logic duplicates what the API layer already does and contradicts the TODO comment indicating it should be removed now that network config is passed from the API.

Fix in Cursor Fix in Web

@sitole sitole Nov 11, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think here we should fallback to s.config.AllowSandboxInternet only when customers configuration is not provided at all (both allow internet access flag and egress internet config).

cc @dobrac

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thats desired

@sitole

sitole commented Nov 11, 2025

Copy link
Copy Markdown
Member

Looks like hyperloop server is not accessible with the internet disabled.
Just this and nit related to s.config.AllowSandboxInternet and then its ready to go. @dobrac

Comment thread spec/openapi.yml Resolved
@dobrac
dobrac requested a review from sitole November 11, 2025 14:55
@dobrac
dobrac merged commit 802fdaf into main Nov 11, 2025
@dobrac
dobrac deleted the add-allow-deny-ip-egress-limit-suport branch November 11, 2025 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants