Network Egress Policy

adk_core::egress decides which hosts, ports and addresses a connection may reach. One EgressPolicy describes the destinations; framework HTTP clients enforce it through GuardedClient; one address classifier, classify, is shared by every check in the workspace.

PartTypeFeature
Policy and decisionEgressPolicy, EgressRule, EgressTarget, EgressDenial—
Address classifierclassify, is_non_public, AddressClass—
Name resolutionHostResolver, StaticResolver, SystemResolverSystemResolver: egress-dns
Guarded HTTP clientGuardedClient, GuardedClientBuilder, EgressResolveregress-client
Egress proxy for sandboxed processesadk_sandbox::egress_proxy::EgressProxy, EgressRecord, EgressAuditadk-sandbox: egress-proxy
[dependencies]
adk-core = { version = "3.0.0", features = ["egress-client"] }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

Rules

A policy is a list of rules plus two switches. A rule without a port admits every port.

RuleTextAdmits
Any host*, *:443Every host name, and IP literals whose address passes the address check
Exact hostapi.example.com, api.example.com:443That name
Subdomains*.example.com, *.example.com:443Every name below example.com, not example.com itself
CIDR10.0.0.0/8, 10.0.0.5:5432, fd00::/8, [fd00::/8]:443IP literals in the range on the port, and names that resolve into the range
ConstructorAdmits
EgressPolicy::deny_all()Nothing until rules are added
EgressPolicy::public_only() (the default)Any host over https, on public addresses
EgressPolicy::allowlist(rules)Exactly the rules, over https
EgressPolicy::allow_private_networks()Any host over http or https, on any address except cloud metadata; for in-cluster receivers and tests
SwitchEffect
with_private_networks()Admits loopback, private and other non-public addresses for admitted hosts
with_plain_http()Admits http URLs

Decisions

EgressPolicy::decide is a pure function of the policy and an EgressTarget:

TargetCheckedWhen
Name { host, port }A host rule admits the name and portBefore resolution
Address { host, address }The address passes the address checkFor every address the name resolves to, at connect time
Literal(address)A CIDR rule admits the address and port, or an any-host rule admits the port and the address passes the address checkBefore connecting
Address classAddress check
MetadataAlways refused, whatever the rules say
PublicAdmitted
Every other classAdmitted only inside a CIDR rule, or with with_private_networks()

EgressPolicy::check_url combines the scheme check with the Name or Literal check of a URL. localhost and *.localhost names are checked as loopback before resolution. A host name whose last label is numeric (127.1, 0x7f.1, 2130706433) is refused, since inet_aton-style resolvers read it as an IPv4 address.

Every refusal is an EgressDenial whose Display form is the guidance a caller reads and whose code() is a stable identifier such as egress.host_not_allowed. find_denial recovers it from an error's source chain.

use adk_core::egress::{EgressDenial, EgressPolicy, EgressTarget};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let policy = EgressPolicy::allowlist(["api.github.com:443", "*.pythonhosted.org:443"])?;

    assert!(policy.check_url("https://files.pythonhosted.org/simple/").is_ok());
    assert!(matches!(
        policy.check_url("https://example.com/"),
        Err(EgressDenial::HostNotAllowed { .. })
    ));
    assert!(matches!(
        policy.decide(&EgressTarget::Address {
            host: "api.github.com",
            address: "10.0.0.7".parse()?,
        }),
        Err(EgressDenial::AddressNotAllowed { .. })
    ));
    Ok(())
}

Narrowing

narrow intersects two policies: a destination passes the result only when it passes both, and both switches stay on only when both policies set them. An operator's policy is the ceiling; every lower layer narrows it and none can widen it. A narrowed policy can only be narrowed further: allow and the switches leave it unchanged.

use adk_core::egress::EgressPolicy;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let operator = EgressPolicy::allowlist(["*.example.com:443"])?;
    let tool = EgressPolicy::allowlist(["api.example.com", "evil.test"])?;
    let effective = operator.narrow(&tool);

    assert!(effective.check_url("https://api.example.com/v1").is_ok());
    assert!(effective.check_url("https://evil.test/").is_err());
    assert!(effective.check_url("https://docs.example.com/").is_err());
    Ok(())
}

Address classes

classify is the one classifier every egress check uses — webhook delivery, AWP event delivery, the A2A push sender, Web Bot Auth directories, website migration, graph HTTP action nodes, the harness web_fetch tool and browser navigation. An IPv6 address embedding an IPv4 address — IPv4-mapped, NAT64 or 6to4 — has the class of the address it embeds.

ClassIPv4IPv6
Metadata169.254.169.254, 169.254.170.2, 169.254.170.23, 100.100.100.200, 168.63.129.16fd00:ec2::254, fd00:ec2::23
Unspecified0.0.0.0/8::
Loopback127.0.0.0/8::1
Private10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16fc00::/7, fec0::/10
LinkLocal169.254.0.0/16fe80::/10
SharedAddressSpace100.64.0.0/10—
Multicast224.0.0.0/4ff00::/8
Reserved240.0.0.0/4, 198.18.0.0/15, 192.0.0.0/24100::/64, IPv4-compatible and IPv4-translated forms
Tunnel—Teredo 2001::/32, local-use NAT64 64:ff9b:1::/48
Publiceverything elseeverything else

Guarded HTTP client

GuardedClient (feature egress-client) enforces a policy on every request it sends:

CheckWhere
Scheme, host name and port, IP literalsBefore the request is built (check_url)
Every address a name resolves toAt connect time, through EgressResolver: the address checked is the address connected to, and one refused address refuses the whole answer
Every redirect hopScheme, host, port and literal again, then resolution again
ProxiesNone: environment and system proxy settings are ignored, since a proxy resolves names itself
Build failureEgressClientError; no unguarded client is used in its place
use std::time::Duration;

use adk_core::egress::{EgressPolicy, GuardedClient, find_denial};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = GuardedClient::builder(EgressPolicy::allowlist(["api.github.com:443"])?)
        .timeout(Duration::from_secs(10))
        .redirects(3)
        .build()?;

    let request = client.get("https://api.github.com/zen")?;
    match request.send().await {
        Ok(response) => println!("{}", response.status()),
        Err(error) => match find_denial(&error) {
            Some(denial) => println!("refused ({}): {denial}", denial.code()),
            None => println!("failed: {error}"),
        },
    }
    Ok(())
}

GuardedClientBuilder::resolver takes any HostResolver; StaticResolver maps fixed names to addresses for tests. A crate that needs its own reqwest client options sets EgressResolver with ClientBuilder::dns_resolver and ClientBuilder::no_proxy, and checks URLs and redirect hops with check_parsed_url itself.

Egress proxy for sandboxed processes

adk_sandbox::egress_proxy::EgressProxy (feature egress-proxy of adk-sandbox) enforces a policy on a child process's connections. The sandbox lets the process reach only the proxy's loopback port (network access Proxied), and the standard proxy variables point it there.

RequestHandling
CONNECT host:portThe name and port are checked; the proxy resolves the name itself, checks every address, and connects only to an address it checked. The TLS ClientHello must name host in its SNI: no SNI, Encrypted Client Hello, or a stream that is not TLS is refused. A CONNECT to an IP literal is admitted by the policy's address rules alone
GET http://host/path (absolute form)Only when the policy admits plain http; checked the same way, forwarded with Host set to the checked authority and hop-by-hop headers removed
Loopback or unspecified destinationsAlways refused, so the proxy never connects to itself or to the host's local services
Anything else400 Bad Request

A refusal answers 403 Forbidden with the reason and an X-Adk-Egress-Denied header carrying the denial code (egress.host_not_allowed, egress.sni_mismatch, …). Every connection is one EgressRecord — call id, host, port, connected address, SNI, outcome and byte counts — for the proxy's EgressAudit, and one tracing event. Start one proxy per sandboxed call so each record names its call; dropping the proxy closes its listener and every open connection.

use std::sync::Arc;

use adk_core::egress::EgressPolicy;
use adk_sandbox::egress_proxy::{EgressProxy, InMemoryEgressAudit};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let audit = Arc::new(InMemoryEgressAudit::new());
    let proxy = EgressProxy::builder(EgressPolicy::allowlist(["pypi.org:443", "*.pythonhosted.org:443"])?)
        .call_id("call-42")
        .audit(audit.clone())
        .bind()
        .await?;
    println!("HTTPS_PROXY=http://127.0.0.1:{}", proxy.port());
    // Run the sandboxed command; then read what it reached.
    for record in audit.records() {
        println!("{:?} {}:{} {:?}", record.protocol, record.host, record.port, record.outcome);
    }
    Ok(())
}

Tool declarations

An operator sets the egress ceiling for a run on the runner or the run's configuration; every lower layer can only narrow it.

WhereEffect
Runner::builder().egress_policy(policy)The ceiling of every run; a run's own policy is intersected with it
RunConfig::builder().egress_policy(policy)Sets the run's policy, or narrows the one already set
ToolContext::egress_policy()The run's policy, for a tool that opens its own connections, for example through a GuardedClient built from it

A tool declares the destinations of a call with Tool::egress(&args). Under a run egress policy, authorize_tool_call checks the declaration before the tool policy, guardrails, or confirmation, and no approval admits a call it refuses:

ToolEgressUnder a run egress policy
Undeclared (the default)Refused
NoneAdmitted: the call opens no network connection
ConfiguredAdmitted: the call reaches only endpoints the operator fixed when building the tool, such as a database or a model provider (AgentTool declares this; the delegate's own calls are checked against the policy the delegation carries)
EnforcedAdmitted: every connection is checked when it is made, by a GuardedClient built from the run's policy or by a sandbox's egress proxy
Destinations(rules)Admitted when the policy covers every rule (EgressPolicy::covers); ToolEgress::for_urls builds the rules from URLs

FunctionTool::with_egress and with_egress_fn declare a function tool's destinations, the second from its arguments. A tool wrapper forwards its inner tool's declaration.

use std::sync::Arc;

use adk_core::egress::{EgressPolicy, ToolEgress};
use adk_core::{RunConfig, Tool};
use adk_tool::FunctionTool;
use serde_json::json;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let fetch = Arc::new(
        FunctionTool::new("fetch_page", "Fetches a page", |_ctx, args| async move { Ok(args) })
            .with_egress_fn(|args| ToolEgress::for_urls([args["url"].as_str().unwrap_or_default()])),
    );
    let config = RunConfig::builder()
        .egress_policy(EgressPolicy::allowlist(["docs.rs:443", "*.github.com:443"])?)
        .build();
    let policy = config.egress_policy.as_ref().expect("set above");

    assert!(policy.admits_tool(&fetch.egress(&json!({ "url": "https://docs.rs/adk-core" }))).is_ok());
    assert!(policy.admits_tool(&fetch.egress(&json!({ "url": "https://evil.test/" }))).is_err());
    Ok(())
}

Framework tools declare:

ToolDeclaration
AgentToolConfigured; the delegate's calls are checked against the policy the delegation carries
FunctionToolWhat with_egress or with_egress_fn sets; otherwise Undeclared
adk-devtools file tools (read_file, write_file, edit_file, glob, grep, apply_patch)None
bash (adk-devtools)Its launcher's (CommandLauncher::egress): Undeclared on the host
Harness bashEnforced when sandboxed: under a run egress policy each command reaches the network only through its own egress proxy (Harness Shell and Sandbox); Undeclared on the host, for the unsandboxed retry, and under the Windows restricted token
Harness web_fetchThe URL's host and port; every redirect hop is checked against the run's policy too
Harness web_searchConfigured (the search provider the harness was built with)
Harness to-dos, plan, help, shell outputNone; memory and facts: Configured
Kernel driver toolsEnforced under the driver's egress proxy (network = { hosts = [...] }), None sandboxed with allow_network = false, otherwise Undeclared
MCP tools, browser tools, other harness toolsUndeclared: a run egress policy refuses them. The browser loads subresources and runs scripts no declaration can bound

What a declaration does not cover:

  • A declaration is the tool author's statement. Only connections made through a GuardedClient or a sandbox's egress proxy are enforced when they are made.
  • The declaration is computed from the arguments the agent built; arguments a tool guardrail rewrites or an approver edits are not declared again.
  • Provider-executed built-in tools (GoogleSearchTool, OpenAIWebSearchTool, …), model providers, and stores the operator configures are outside the policy.
  • Governed graph nodes and native realtime handlers declare nothing, so a run egress policy refuses them.

URL provenance

An egress policy decides which hosts a call may reach; it cannot tell a URL the user gave from one a model composed to carry data to an admitted host. ContextUrls answers that: it collects the URLs a conversation's sources hold, and a fetch tool admits only those.

use adk_core::Content;
use adk_core::egress::{ContextUrls, UrlSources};

fn main() {
    let history = [
        Content::new("user").with_text("Summarize https://docs.example.com/guide"),
        Content::new("model").with_text("Fetching https://collect.example/?k=secret"),
    ];
    let urls = ContextUrls::collect(&history, &UrlSources::default());
    assert!(urls.contains("https://docs.example.com/guide"));
    assert!(!urls.contains("https://docs.example.com/guide?k=secret"));
    assert!(!urls.contains("https://collect.example/?k=secret"));
}
SourceCounts
User-role text, file references and embedded resourcesUrlSources::user_input
Tool results, by tool nameUrlSources::tool_results: All, None, Only(..) or Except(..)
Model text, thinking, tool calls; the system instructionNever

Two URLs match when they are equal after normalize_url: scheme and host lowercased, default port dropped, dot segments resolved, fragment removed; the query and path are compared exactly. ContextUrls::from_tool_context reads a call's session history on its branch and the invocation's user message. The harness web_fetch and browser navigation apply it under WebConfig::url_provenance (URL provenance), and adk-browser's BrowserToolset::with_url_provenance outside the harness.

Limits

  • Not data-loss prevention. An admitted host receives whatever is sent to it.
  • Not proof against domain fronting. A host rule matches the name a client asks for; a shared CDN can route that connection to another tenant.
  • Only checked connections are covered. A socket opened by code that does not consult the policy — including third-party code running in the agent's process — is not contained. A child process is contained only when its sandbox enforces Proxied network access, so that the proxy is the one destination it can reach.