Skip to content

Make unrestricted sandbox network access explicit - #59385

Merged
MartinYe1234 merged 16 commits into
mainfrom
proxy-follow-ups
Jun 15, 2026
Merged

Make unrestricted sandbox network access explicit#59385
MartinYe1234 merged 16 commits into
mainfrom
proxy-follow-ups

Conversation

@rtfeldman

Copy link
Copy Markdown
Contributor

This makes unrestricted sandbox network access an explicit sandbox mode instead of a fallback when the enforcing proxy is unavailable. Host-specific network access still uses the proxy, while approved arbitrary network access skips proxy setup and maps directly to unrestricted egress.

Release Notes:

  • Improved agent terminal sandbox network permission handling.

rtfeldman and others added 13 commits June 12, 2026 22:22
First of a stack adding hostname-allowlisted network access to agent
terminal sandboxing. This PR adds a new `http_proxy` crate containing only
the allowlist policy types: `HostPattern` (exact hostnames or leading-`*.`
subdomain wildcards, with IDN-to-punycode normalization and IP-literal /
localhost rejection) and `Allowlist`, plus host-pattern subsumption
(`covers`) used later to decide when an already-granted permission covers a
new request.

Pure, self-contained logic with no callers yet; the upstream-proxy config
and the proxy server that enforces these policies land in later PRs.

Release Notes:

- N/A
Second of the stack. Adds `UpstreamProxy`: parsing of an upstream HTTP
proxy from the environment (`HTTPS_PROXY` / `HTTP_PROXY` / `ALL_PROXY` and
lowercase forms) with `NO_PROXY` bypass matching delegated to the
`proxyvars` crate, basic-auth credentials (kept out of `Debug`/`Display`),
and IPv6/default-port normalization. Used by the proxy server in the next
PR to chain outbound connections through a corporate proxy when one is
configured.

Release Notes:

- N/A
Final piece of the crate: the in-process HTTP/HTTPS proxy server that
enforces an `Allowlist`. It speaks HTTP CONNECT for HTTPS tunnels and
forward proxying for plain HTTP, vets resolved addresses against
loopback/private/link-local ranges to prevent DNS-rebinding past the
sandbox, pins each connection to the destination approved for its first
request (so later keep-alive requests can't escape the policy decision),
optionally chains through the `UpstreamProxy`, and bounds header sizes,
connection counts, and connect/handshake waits since its sole client is
untrusted model-driven code running inside the editor process. Includes
end-to-end tests covering allowed/denied CONNECT and HTTP forward,
IP-literal handling, DNS-rebinding denial, and upstream chaining.

Still has no callers; wired into the agent terminal sandbox in later PRs.

Release Notes:

- N/A
Replace the `allow_network: bool` field on the Seatbelt `SandboxPermissions`
with a `NetworkAccess` enum: `None` (block all egress), `All` (the previous
`allow_network: true` behavior), and `LocalhostPort(u16)`, which confines a
sandboxed command to a single loopback port. The new variant emits a
Seatbelt rule permitting outbound TCP only to `localhost:<port>` and isn't
used yet; it exists to pin sandboxed commands to the in-process network
proxy in a later commit.

The sole consumer, `acp_thread`'s terminal wrap, maps its existing boolean
to `All`/`None`, so behavior is unchanged.

Release Notes:

- N/A
Replace the boolean `allow_network` terminal-sandbox escalation with a
hostname allowlist. The `terminal` tool now takes `allow_hosts` (exact
hostnames or leading-`*.` subdomain wildcards, validated up front via
`http_proxy::HostPattern`) and `allow_all_hosts` as a broad escape hatch.
Approval prompts name the requested hosts, thread grants and persistent
"allow always" settings (`network_hosts` / `allow_all_hosts`, replacing
`allow_network`) cover requests via host-pattern subsumption the same way
write paths use subtree containment, and the authorization card in the
agent panel lists the requested hosts in a collapsible section.

Host allowlists aren't enforced yet: `SandboxWrap` carries the allowlist,
but any network request still maps to unrestricted egress at the Seatbelt
layer, matching previous behavior. Enforcement via an in-process proxy
lands in the next commit. For non-local projects (where that proxy won't
apply), host requests are widened to "arbitrary network access" before
prompting so approvals match enforcement.

Old persisted `network: bool` authorization details still deserialize via
a serde alias.

Release Notes:

- N/A
Spawn the `http_proxy` allowlisting proxy for sandboxed terminal commands
that request network, and pin the Seatbelt policy to its loopback port
(`NetworkAccess::LocalhostPort`) so all egress is forced through it. The
child's proxy environment variables are pointed at the proxy and any
inherited `NO_PROXY` is blanked so nothing connects direct; a real upstream
proxy from the environment is chained through when present. The proxy and
its Seatbelt config file share one RAII handle so both live exactly as long
as the command. Per-connection events are drained to the log.

The proxy binds loopback, so it only applies to local projects and macOS
hosts; elsewhere the wrap falls back to unrestricted egress as before
(callers widen the request accordingly).

Release Notes:

- N/A
Thread project locality through SandboxWrap instead of re-reading
project.is_local() at proxy-spawn time, and have setup_network_proxy
return a resolved NetworkPolicy that apply_sandbox_wrap maps directly.
This keeps the enforced egress policy in lockstep with the locality
decision the agent layer used when prompting the user, and removes the
duplicated macos/is_local/wants_network gating between the two functions.
On command completion the proxy handle was dropped inside this.update on
the foreground thread, where its Drop joins the listener thread (after a
loopback wakeup connect). Take the handle and drop it on a background
task so a slow shutdown can't stall the UI.
@rtfeldman rtfeldman self-assigned this Jun 15, 2026
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jun 15, 2026
@zed-community-bot zed-community-bot Bot added the staff Pull requests authored by a current member of Zed staff label Jun 15, 2026
@rtfeldman
rtfeldman marked this pull request as ready for review June 15, 2026 21:17
Base automatically changed from http-proxy-04-proxy-enforcement to main June 15, 2026 22:25
@MartinYe1234
MartinYe1234 enabled auto-merge June 15, 2026 22:34
@MartinYe1234
MartinYe1234 added this pull request to the merge queue Jun 15, 2026
Merged via the queue into main with commit 2c0a044 Jun 15, 2026
32 checks passed
@MartinYe1234
MartinYe1234 deleted the proxy-follow-ups branch June 15, 2026 22:42
@WaryaWayne WaryaWayne mentioned this pull request Jun 18, 2026
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
This makes unrestricted sandbox network access an explicit sandbox mode
instead of a fallback when the enforcing proxy is unavailable.
Host-specific network access still uses the proxy, while approved
arbitrary network access skips proxy setup and maps directly to
unrestricted egress.

Release Notes:

- Improved agent terminal sandbox network permission handling.

---------

Co-authored-by: Martin Ye <martin@zed.dev>
Co-authored-by: MartinYe1234 <52641447+MartinYe1234@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants