The codex-network-proxy crate is a local network policy enforcement engine designed to sandbox agent processes. It acts as a gatekeeper for all outbound network traffic initiated by tools or shell commands within the Codex environment. By providing both HTTP and SOCKS5 proxy interfaces, it ensures that sandboxed processes comply with the security constraints defined in the active Permissions Profile
The proxy serves three primary functions:
BlockedRequest buffer codex-rs/network-proxy/src/runtime.rs175-176Full (read/write) and Limited (read-only) network modes codex-rs/network-proxy/src/config.rs130CONNECT tunnels and enforce method-level policies (e.g., blocking POST in limited mode) codex-rs/network-proxy/README.md36-39x-unix-socket header codex-rs/network-proxy/README.md75-77The proxy is typically managed by codex-core, which initializes the proxy using NetworkProxyBuilder and configuration derived from the session's permissions profile via NetworkProxySpec codex-rs/core/src/config/network_proxy_spec.rs100-132
This diagram shows how a sandboxed process interacts with the proxy and how the proxy validates requests against the ConfigState.
Title: Network Proxy Data Flow
Sources: codex-rs/network-proxy/src/proxy.rs189-224 codex-rs/network-proxy/src/http_proxy.rs92-110 codex-rs/network-proxy/src/runtime.rs230-240 codex-rs/network-proxy/src/socks5.rs64-87
The proxy configuration is nested within the permissions table of config.toml. Policies are compiled into GlobSet structures for high-performance matching during initialization in build_config_state codex-rs/network-proxy/src/state.rs60-93
Sources: codex-rs/network-proxy/README.md18-77 codex-rs/network-proxy/src/config.rs115-144
The policy evaluation determines the fate of a request based on the following hierarchy:
deny_set, it is immediately blocked with HostBlockReason::Denied codex-rs/network-proxy/src/runtime.rs67allow_set, it is allowed codex-rs/network-proxy/src/runtime.rs90allow_local_binding is false, any request resolving to a non-public IP is blocked even if allowlisted by hostname codex-rs/network-proxy/README.md41-46Limited mode, non-safe methods (POST, PUT, DELETE) are blocked unless a MITM hook explicitly allows them codex-rs/network-proxy/src/socks5.rs122-127| Entity | File Path | Role |
|---|---|---|
NetworkProxy | codex-rs/network-proxy/src/proxy.rs224 | Main handle for the proxy server; manages listener lifecycles. |
ConfigState | codex-rs/network-proxy/src/runtime.rs168 | Contains the compiled GlobSet for allow/deny rules, MITM state, and hook configs. |
NetworkPolicyDecider | codex-rs/network-proxy/src/network_policy.rs50 | Trait for custom logic to override allowlist misses (used for approval flows). |
NetworkProxyBuilder | codex-rs/network-proxy/src/proxy.rs117 | Builder for initializing NetworkProxy with specific listeners and policies. |
BlockedRequest | codex-rs/network-proxy/src/runtime.rs95 | Struct representing a policy violation, used for auditing and UI notifications. |
NetworkProxyState | codex-rs/network-proxy/src/runtime.rs230 | Thread-safe shared state holding the ConfigState and ConfigReloader. |
codex-core manages the proxy via NetworkProxySpec, which handles the mapping of PermissionProfile to NetworkProxyConfig codex-rs/core/src/config/network_proxy_spec.rs100-132
Title: Code Entity Relationship: Core to Proxy
Sources: codex-rs/network-proxy/src/proxy.rs224-235 codex-rs/network-proxy/src/runtime.rs168-177 codex-rs/network-proxy/src/runtime.rs230-240 codex-rs/network-proxy/src/state.rs60-93
In NetworkMode::Limited, the proxy enforces a read-only policy. Only GET, HEAD, and OPTIONS methods are permitted codex-rs/network-proxy/README.md104-111 SOCKS5 UDP and non-HTTPS SOCKS5 TCP are blocked in limited mode codex-rs/network-proxy/src/socks5.rs122-127 For HTTPS traffic, this requires mitm = true because the proxy cannot see the HTTP method inside an encrypted CONNECT tunnel without terminating the TLS connection codex-rs/network-proxy/src/http_proxy.rs152-172
The MITM system uses rustls via the rama framework to terminate TLS codex-rs/network-proxy/src/mitm.rs153-185
mitm_hooks to determine if headers should be injected or the request modified codex-rs/network-proxy/src/runtime.rs9 codex-rs/network-proxy/src/mitm.rs88-93ManagedMitmCa) to issue per-host leaf certificates for TLS termination codex-rs/network-proxy/src/certs.rs51-64NetworkProxyBuilder::build() begins by resolving the current configuration from the provided state codex-rs/network-proxy/src/proxy.rs189-198WindowsProxyIngress codex-rs/network-proxy/src/proxy.rs207-219; on other platforms, it uses ephemeral listeners codex-rs/network-proxy/src/proxy.rs223-224run_http_proxy and run_socks5 begin serving traffic on the reserved listeners codex-rs/network-proxy/src/http_proxy.rs92-110 codex-rs/network-proxy/src/socks5.rs64-87The proxy supports dynamic policy updates without restarting the listeners via NetworkProxy::replace_config_state codex-rs/network-proxy/src/proxy.rs268 This is used by NetworkProxySpec to update proxy state when permission profiles change codex-rs/core/src/config/network_proxy_spec.rs191-203
Sources: codex-rs/network-proxy/src/proxy.rs189-224 codex-rs/network-proxy/src/proxy.rs268-275 codex-rs/core/src/config/network_proxy_spec.rs100-132
Refresh this wiki
This wiki was recently refreshed. Please wait 5 days to refresh again.