Repository navigation
fix(agent-server): default bind host to loopback without a session API key - #4180
Conversation
…I key The agent server previously defaulted --host to 0.0.0.0, exposing an unauthenticated server to the network whenever no SESSION_API_KEY was configured. The default is now 127.0.0.1 unless a session API key is present (via SESSION_API_KEY / OH_SESSION_API_KEYS_0 or the config file), in which case binding all interfaces is intentional. An explicit --host 0.0.0.0 without a key is still allowed (e.g. containerized sandboxes whose port is mapped to host loopback) but emits a warning. The Docker and Apptainer workspace launchers now forward SESSION_API_KEY and OH_SESSION_API_KEYS_0 by default so sandboxed servers can authenticate network-bound requests when they bind 0.0.0.0. Co-authored-by: openhands <openhands@all-hands.dev>
Adds before/after live test output and the reproduction script used to verify the default bind host change. These are PR-only artifacts and will be removed by the PR Artifacts workflow on approval. Co-authored-by: openhands <openhands@all-hands.dev>
|
✅ PR Artifacts Cleaned Up The |
Python API breakage checks — ✅ PASSEDResult: ✅ PASSED Behavioral default changes detectedThese public
|
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
Rename ambiguous loop variable `l` to `line` to satisfy ruff/pycodestyle E741 in the PR evidence script. Co-authored-by: openhands <openhands@all-hands.dev>
Coverage Report •
|
||||||||||||||||||||||||||||||||||||||||
all-hands-bot
left a comment
There was a problem hiding this comment.
🟡 QA Report: PARTIAL
Primary agent-server bind-host behavior works as described; Apptainer launcher forwarding was not verified because this environment has no Apptainer/Singularity runtime.
Does this PR achieve its stated goal?
Yes for the primary agent-server goal, and for the Docker workspace forwarding path I could exercise. Running the actual openhands.agent_server CLI showed the before-state default bound unauthenticated no-key launches to 0.0.0.0, while the PR binds the same no-key default launch to 127.0.0.1 and refuses non-loopback HTTP connections. I also verified that explicit wildcard binding still works with the new warning, and that SESSION_API_KEY, OH_SESSION_API_KEYS_0, and config-file keys keep the default at 0.0.0.0.
| Phase | Result |
|---|---|
| Environment Setup | ✅ make build completed for the PR worktree and isolated main worktree. |
| CI Status | ⏳ 22 checks successful; 6 Docker image build/push jobs still in progress; 1 skipped. |
| Functional Verification | ✅ Agent-server CLI behavior and Docker workspace env forwarding verified with real processes/HTTP/Docker inspection. |
Functional Verification
Test 1: no-key default bind changed from wildcard to loopback
Step 1 — Reproduce baseline without the fix:
Checked out origin/main in /tmp/oh-sdk-qa-base-4180 at 7c93182eb51877841a8674cf016ba3a21f452045, then ran:
uv run python -m openhands.agent_server --port 43047Observed:
Uvicorn running on http://0.0.0.0:43047
GET /docs via 127.0.0.1: HTTP/1.1 200 OK
GET /docs via 10.1.1.102: HTTP/1.1 200 OK
warning_lines: 0
This confirms the bug baseline: a no-key default launch was reachable through the host's non-loopback interface.
Step 2 — Apply the PR's changes:
Used the PR worktree at 09e3acad0b5fa903e6cca88deb114feb597ecc16.
Step 3 — Re-run with the fix in place:
Ran:
uv run python -m openhands.agent_server --port 52449Observed:
Uvicorn running on http://127.0.0.1:52449
GET /docs via 127.0.0.1: HTTP/1.1 200 OK
GET /docs via 10.1.1.102: connection-failed: ConnectionRefusedError: [Errno 111] Connection refused
warning_lines: 0
This confirms the fix works: the default no-key server still serves local users, but is no longer reachable from the non-loopback address.
Test 2: explicit wildcard bind without a key remains allowed and warns
Ran on the PR branch:
uv run python -m openhands.agent_server --port 39219 --host 0.0.0.0Observed:
WARNING: Binding to all interfaces (0.0.0.0) without a session API key: ...
Uvicorn running on http://0.0.0.0:39219
GET /docs via 127.0.0.1: HTTP/1.1 200 OK
GET /docs via 10.1.1.102: HTTP/1.1 200 OK
This matches the PR claim: explicit operator choice is preserved, but the unsafe unauthenticated network exposure is surfaced.
Test 3: configured auth keeps the default wildcard bind
Ran three PR-branch launches with default --host omitted:
# SESSION_API_KEY set
uv run python -m openhands.agent_server --port 36497
# OH_SESSION_API_KEYS_0 set
uv run python -m openhands.agent_server --port 56881
# OPENHANDS_AGENT_SERVER_CONFIG_PATH points to {"session_api_keys":["qa-config-key"]}
uv run python -m openhands.agent_server --port 40721Observed:
SESSION_API_KEY: Uvicorn running on http://0.0.0.0:36497; loopback 200; non-loopback 200; warnings 0
OH_SESSION_API_KEYS_0: Uvicorn running on http://0.0.0.0:56881; loopback 200; non-loopback 200; warnings 0
config file key: Uvicorn running on http://0.0.0.0:40721; loopback 200; non-loopback 200; warnings 0
This confirms the default remains network-bound when session authentication is configured through each advertised source.
Test 4: Docker workspace forwards session-key environment variables
Ran a real Docker workspace launch with fake SESSION_API_KEY and OH_SESSION_API_KEYS_0, then inspected the newly created container's environment variable names:
uv run python -c '<construct DockerWorkspace, inspect new docker container env, stop container>'Observed:
{
"new_container_ids": ["528ff14dcc1e"],
"inspected": {
"528ff14dcc1e": {
"has_SESSION_API_KEY": true,
"has_OH_SESSION_API_KEYS_0": true
}
}
}The container was stopped after inspection. This verifies the Docker launcher path forwards both session-key variables by default.
Unable to Verify
Apptainer workspace forwarding
I could not run the Apptainer launcher end-to-end because neither Apptainer nor Singularity is installed in this QA environment:
command -v apptainer || true
command -v singularity || true
# no outputThe Docker workspace equivalent was verified with a real container, but the Apptainer-specific runtime path remains unverified here. Future QA runs would benefit from AGENTS.md guidance for an Apptainer-capable environment or a small local SIF fixture if this path should be routinely exercised.
Issues Found
None.
This review was created by an AI agent (OpenHands) on behalf of the user.
Final verdict: PARTIAL
HUMAN:
AGENT:
Why
The agent server CLI used a fixed default host of
0.0.0.0for every launch configuration. Local runs without a session API key and sandboxed runs with a configured key need different defaults, so the host is now selected from the effective session-key configuration.Summary
127.0.0.1when noSESSION_API_KEY/OH_SESSION_API_KEYS_0is configured.0.0.0.0.--hostvalues remain supported. An explicit wildcard host without a key emits a configuration warning.SESSION_API_KEYandOH_SESSION_API_KEYS_0by default.Issue Number
N/A
How to Test
Unit tests:
Live end-to-end test:
The live test launches the actual agent server in three configurations:
--host 0.0.0.0→ binds0.0.0.0and emits the configuration warning.127.0.0.1.SESSION_API_KEYwith the default host → binds0.0.0.0.The existing live-server suite was also run:
Video/Screenshots
Live before/after results are committed under
.pr/and are auto-removed by the PR Artifacts workflow after approval.Before (
.pr/bind_host_before.json) — no key with the default host:After (
.pr/bind_host_after.json) — the same launch configuration:The after-results also record the explicit-wildcard configuration warning and confirm that the default remains
0.0.0.0when a key is configured.Type
Notes
Operators who relied on the implicit
0.0.0.0default without a session API key can pass--host 0.0.0.0explicitly. Containerized workspace launches already pass the wildcard host explicitly and now forward the session-key environment variables by default.This PR was created by an AI agent (OpenHands) on behalf of the user.
@neubig can click here to continue refining the PR
Agent Server images for this PR
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdknikolaik/python-nodejs:python3.13-nodejs22-slimgolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:acdfa52-pythonRun
All tags pushed for this build
About Multi-Architecture Support
acdfa52-python) is a multi-arch manifest supporting both amd64 and arm64acdfa52-python-amd64) are also available if needed