Repository navigation
Sandbox: enforce default-deny egress with an allowlisting proxy - #16
Merged
Merged
Conversation
The task images blocked github.com & co. by appending them to /etc/hosts. That is a hostname blocklist applied inside a container where the agent is root, and agents got around it: GitHub CDN mirrors (cdn.jsdelivr.net/gh, gh-proxy.com, ghfast.top), read-through proxies (r.jina.ai), DNS-over-HTTPS + curl --resolve, LD_PRELOAD resolver shims for git, search engines to locate the task's own PR. Once the network layer was closed, two indirect channels remained through allowlisted hosts: the LLM API used as a web proxy (web-enabled `:online` models fetching the PR on the agent's behalf, with a key read from the sandbox), and the task's own package pulled from npm/PyPI as a newer release containing the fix. Enforcement now lives outside the container (enroot backend): * Each container runs in an unprivileged user+network namespace holding only loopback (`unshare -Urn`; every exec enters it with `nsenter`). The one exit is a relay to a host-side proxy over a unix socket the container cannot see. * `src/egress_policy.py` is the single default-deny allowlist: model catalog, package registries, and only the LLM host the run's backend needs (none by CONNECT for OpenRouter runs). Known leak vectors are refused with a reason the agent sees in the 403 body. `proxy.golang.org` is denied (it serves any GitHub repo verbatim); Go runs with GOPROXY=off from the pre-baked module cache. Tasks may extend the list via task.toml `[network] allow`, minus leak vectors. * `src/proxies/egress_proxy.py`: CONNECT/absolute-URI forwarding; a model-pinned `/openrouter/` reverse route that injects the real API key host-side (the sandbox only holds a placeholder; `:online`, plugins, non-function tools and foreign models are refused); registry TLS terminated with a per-job CA (`egress_ca.py`) so the task's own package names — scanned from the workspace manifests at trial start — and registry search are denied at the path level. * An in-container self-test runs before turn 0 and the trial aborts as `infra_failed(egress_policy_unenforced)` if any check fails; every proxied connection is logged to `agent/egress.log`, and an allowed connection to a leak vector is `infra_failed(egress_policy_violation)`. * `run_eval.py` refuses leaderboard trial roots (`trials/canonical_*`) on a backend without enforcement unless `--allow-porous-sandbox` is passed; the Slurm launcher preflights namespace support. docker/e2b remain all-or-nothing and are documented as such. Measured on the development cluster: inside the namespace `curl --noproxy '*'` exits 6/7 and `--resolve host:443:<ip>` exits 7; through the proxy pip, npm, cargo, apt and the pinned model work; own-package tarballs, foreign models and every GitHub route return 403.
Several task images (Rust, plain ubuntu) ship no python3. The opencode config patch was a Python heredoc, so it failed silently there and opencode kept its default https://openrouter.ai base URL — harmless before (only the explicit reasoning variants were lost), fatal under egress enforcement, which serves the model only through the relay's pinned route. The workspace package scan had the same dependency. * The config is now patched on the host (`patch_opencode_config`, the same logic as the script) and written with a `cat` heredoc. * The package scan is POSIX sh + find/sed/tr; the environment fails closed if it does not complete.
Addresses the CodeQL alerts on the PR: one shared verifying client context (TLS >= 1.2) for the proxy's upstream connections, the CA trust context and the tests, and a dict-key assertion that the substring-sanitization query misread.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The sandbox blocked
github.com& co. by pointing them at127.0.0.1in/etc/hosts. That is a hostname blocklist applied inside a container where the agent is root, and agents routinely got around it — GitHub CDN mirrors (cdn.jsdelivr.net/gh/…,gh-proxy.com,ghfast.top), read-through proxies (r.jina.ai), DNS-over-HTTPS +curl --resolve,LD_PRELOADresolver shims forgit, and web search to locate the task's own PR. With the upstream fix in hand, a trial measures nothing.Once the network layer was closed, two indirect channels remained through allowlisted hosts:
:onlinemodels fetching the PR on the agent's behalf, using a key found in the sandbox);Fix
Enforcement moves outside the container (enroot backend), default-deny with an explicit allowlist:
nsenter. The single exit is a relay to a host-side proxy over a unix socket the container cannot see. Nothing the agent does as in-container root changes this.src/egress_policy.py): model catalog, package registries, and only the LLM host the run's backend needs. Known leak vectors are refused with a reason in the 403 body.proxy.golang.orgis denied (it serves any GitHub repo verbatim); Go runs withGOPROXY=offfrom the pre-baked module cache. Tasks can extend the list viatask.toml [network] allow, never with leak vectors.src/proxies/egress_proxy.py): opencode talks to127.0.0.1:3128/openrouter/…; the proxy injects the real API key host-side (the sandbox holds a placeholder) and forwards only the run's model —:onlinevariants, plugins, non-function tools and foreign models get 403. NoCONNECTtoopenrouter.aifor OpenRouter runs.src/proxies/egress_ca.py): a per-job CA terminates TLS for registry hosts so the proxy sees paths; the workspace's own package names (scanned frompackage.json/pyproject.toml/Cargo.tomlat trial start) and registry search are denied at every version. Clients that drop the CA bundle fail closed.infra_failed(egress_policy_unenforced). Every proxied connection is logged toagent/egress.log; an allowed connection to a leak vector isinfra_failed(egress_policy_violation).run_eval.pyrefuses leaderboard trial roots on backends without enforcement unless--allow-porous-sandboxis passed; the Slurm launcher preflights namespace support.docker/e2b remain all-or-nothing (
allow_internet) and are documented as such. Trials recorded before this change carry no egress artefacts and are left untouched by the sentinel.Verification
tests/test_egress.py: policy table, proxy parsing, live unix-socket proxy, TLS interception with a local upstream, model pinning, sentinel).curl --noproxy '*'→ exit 6/7,--resolve host:443:<ip>→ exit 7; through the proxy pip/npm/cargo/apt and the pinned model work; own-package tarballs, foreign models and every GitHub route → 403.