Repository navigation
Require a bearer token on the sandbox API (VULN-3072) - #110
Merged
Merged
Conversation
The agent-environment API runs any MCP tool (including code execution) with the operator's API keys and had no authentication. Loopback-only port publishing (#99) narrowed exposure but left the API open to other containers, DNS-rebinding pages and non-default deployments. - main.py / new auth.py: every endpoint except `/` and `/health` requires `Authorization: Bearer $SANDBOX_AUTH_TOKEN` (constant-time compare, 401 otherwise); the service refuses to start without the token. - Harness, run_eval.py and test_servers.py send the token (env or repo .env). run_eval's pre-flight check now fails clearly on 401 instead of passing with None counts. - `make run-docker` and run_all.sh generate a random token in .env if missing; env.template and READMEs document it. - Tests: tests/test_auth.py; CI installs fastapi/httpx and also runs on auth.py/main.py changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
earakely-scale
deleted the
edgararakelyan/vuln-3072-sandbox-auth-token
branch
October 28, 2026 20:17
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.
Fixes VULN-3072. Follows up #99, which only made the documented port publishing loopback-only.
What
The sandbox API on :1984 runs any MCP tool, including code execution, with the operator's API keys, and had no auth. Loopback publishing still leaves it reachable from other containers, from browser pages via DNS rebinding, and from any non-default deployment.
main.py, newauth.py): every endpoint except/and/healthrequiresAuthorization: Bearer $SANDBOX_AUTH_TOKEN(constant-time compare,401otherwise). The dependency is attached app-wide, so endpoints added later are covered too. The service refuses to start without the token./call-tool,/list-tools,/reset-state),run_eval.py(pre-flight/enabled-servers) andtest_servers.pysend the token from the environment or the repo.env.run_eval.pynow fails with a clear message on401; before, it printedNone/None onlineand passed.make run-dockerandrun_all.shadd a random token to.envif it's missing (openssl rand -hex 32, with a Python fallback).env.templateand both READMEs document it.tests/test_auth.py. The workflow now installsfastapiandhttpxand also runs whenauth.pyormain.pychange.Compatibility
docker run: the sandbox won't start withoutSANDBOX_AUTH_TOKEN.make run-dockerandrun_all.shhandle this automatically.1.2.7image, which ignores the header.1.2.8). The docs still point at1.2.7, so bump them in the release PR./docsand/openapi.json(the FastAPI built-ins) expose only the API schema.Testing
pytest tests/: 20 passed, 18 of them new. The wiring test fails against the oldmain.py.tsc --noEmitpasses for the harness.1.2.7with this branch'smain.py/auth.pyadded and re-synced tomain'suv.lock(fastapi 0.136.3, starlette 1.0.1, mcp 1.28.1), default servers:/list-tools,/call-tool,/enabled-servers,/cache-stats,/cache-clearreturn401with no token or a wrong one, and200with the right one./and/healthstay200.mcp-server-code-runner_run-codecall that writes a file returns401, and the file is not created. With the token, the call runs.1.2.7image: both show 112 tools and 13/20 servers online.test_servers.pygives 12/36 on both with an identical failure set (missing API keys, plus 7 servers that don't start in this arm64 Docker setup on either image). Without the token it's 0/36./v2/mcp_eval/run_agentreads/data/Barber Shop.csvthrough the sandbox.Failed to fetch tools from sandbox: Unauthorized.run_all.shfrom a.envwith no token: it generates the token, then the sandbox, harness,test_servers.pyandrun_eval.pyon a 1-task CSV all complete (1/1 succeeded).make sandbox-tokenedge cases (no trailing newline, the template's emptySANDBOX_AUTH_TOKEN=line, no.env) all yield a 64-char token. Docker--env-file, Node dotenv, python-dotenv andtest_servers.pyall read the same value.🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge.Summary
Adds a required shared bearer token to the sandbox API and updates its callers.
Acknowledged by
earakely-scale: direct Docker starts now require the token; prebuilt-image protection needs a later image release;/docsand/openapi.jsonremain public.Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR Setup["Setup writes SANDBOX_AUTH_TOKEN"] --> Sandbox["Sandbox loads token"] Setup --> Callers["Harness and Python callers load token"] Callers --> Request["Sandbox request"] Request --> Check{"Public probe?"} Check -- Yes --> Probe["Return health response"] Check -- No --> Auth{"Bearer token matches?"} Auth -- No --> Reject["Return 401"] Auth -- Yes --> Route["Run API route"]Reviews (1) · Last reviewed commit: "Require a bearer token on the sandbox AP..." · Reviewed by Greptile