Skip to content

fix(agent-server): default bind host to loopback without a session API key - #4180

Merged
neubig merged 5 commits into
mainfrom
openhands-workspace-Gycwdfck9LsVBTH8rQt6L
Jul 23, 2026
Merged

neubig merged 5 commits into
mainfrom
openhands-workspace-Gycwdfck9LsVBTH8rQt6L

Conversation

@neubig

@neubig neubig commented Jul 21, 2026 •

Copy link
Copy Markdown
Member

HUMAN:


AGENT:

Why

The agent server CLI used a fixed default host of 0.0.0.0 for 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

  • The default host is now 127.0.0.1 when no SESSION_API_KEY / OH_SESSION_API_KEYS_0 is configured.
  • When a session API key is configured through the environment or config file, the default remains 0.0.0.0.
  • Explicit --host values remain supported. An explicit wildcard host without a key emits a configuration warning.
  • Docker and Apptainer workspace launchers now forward SESSION_API_KEY and OH_SESSION_API_KEYS_0 by default.
  • Added unit coverage for default and explicit host selection with keys supplied through both environment variables and config files.

Issue Number

N/A

How to Test

Unit tests:

uv run pytest tests/agent_server/test_preload_modules.py -q

Live end-to-end test:

uv run python .pr/live_bind_test.py

The live test launches the actual agent server in three configurations:

  1. No key with explicit --host 0.0.0.0 → binds 0.0.0.0 and emits the configuration warning.
  2. No key with the default host → binds 127.0.0.1.
  3. A configured SESSION_API_KEY with the default host → binds 0.0.0.0.

The existing live-server suite was also run:

uv run pytest tests/cross/test_remote_conversation_live_server.py -q

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:

"no_key_default": {
  "bind_line": ["... Uvicorn running on http://0.0.0.0:35025 ..."]
}

After (.pr/bind_host_after.json) — the same launch configuration:

"no_key_default": {
  "bind_line": ["... Uvicorn running on http://127.0.0.1:42373 ..."]
}

The after-results also record the explicit-wildcard configuration warning and confirm that the default remains 0.0.0.0 when a key is configured.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

Operators who relied on the implicit 0.0.0.0 default without a session API key can pass --host 0.0.0.0 explicitly. 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

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python amd64, arm64 nikolaik/python-nodejs:python3.13-nodejs22-slim Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:acdfa52-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-acdfa52-python \
  ghcr.io/openhands/agent-server:acdfa52-python

All tags pushed for this build

ghcr.io/openhands/agent-server:acdfa52-golang-amd64
ghcr.io/openhands/agent-server:acdfa52e1340a44c38a58a51b051f47c682ef3e7-golang-amd64
ghcr.io/openhands/agent-server:openhands-workspace-gycwdfck9lsvbth8rqt6l-golang-amd64
ghcr.io/openhands/agent-server:acdfa52-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:acdfa52-golang-arm64
ghcr.io/openhands/agent-server:acdfa52e1340a44c38a58a51b051f47c682ef3e7-golang-arm64
ghcr.io/openhands/agent-server:openhands-workspace-gycwdfck9lsvbth8rqt6l-golang-arm64
ghcr.io/openhands/agent-server:acdfa52-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:acdfa52-java-amd64
ghcr.io/openhands/agent-server:acdfa52e1340a44c38a58a51b051f47c682ef3e7-java-amd64
ghcr.io/openhands/agent-server:openhands-workspace-gycwdfck9lsvbth8rqt6l-java-amd64
ghcr.io/openhands/agent-server:acdfa52-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:acdfa52-java-arm64
ghcr.io/openhands/agent-server:acdfa52e1340a44c38a58a51b051f47c682ef3e7-java-arm64
ghcr.io/openhands/agent-server:openhands-workspace-gycwdfck9lsvbth8rqt6l-java-arm64
ghcr.io/openhands/agent-server:acdfa52-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:acdfa52-python-amd64
ghcr.io/openhands/agent-server:acdfa52e1340a44c38a58a51b051f47c682ef3e7-python-amd64
ghcr.io/openhands/agent-server:openhands-workspace-gycwdfck9lsvbth8rqt6l-python-amd64
ghcr.io/openhands/agent-server:acdfa52-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-amd64
ghcr.io/openhands/agent-server:acdfa52-python-arm64
ghcr.io/openhands/agent-server:acdfa52e1340a44c38a58a51b051f47c682ef3e7-python-arm64
ghcr.io/openhands/agent-server:openhands-workspace-gycwdfck9lsvbth8rqt6l-python-arm64
ghcr.io/openhands/agent-server:acdfa52-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-arm64
ghcr.io/openhands/agent-server:acdfa52-golang
ghcr.io/openhands/agent-server:acdfa52e1340a44c38a58a51b051f47c682ef3e7-golang
ghcr.io/openhands/agent-server:openhands-workspace-gycwdfck9lsvbth8rqt6l-golang
ghcr.io/openhands/agent-server:acdfa52-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:acdfa52-java
ghcr.io/openhands/agent-server:acdfa52e1340a44c38a58a51b051f47c682ef3e7-java
ghcr.io/openhands/agent-server:openhands-workspace-gycwdfck9lsvbth8rqt6l-java
ghcr.io/openhands/agent-server:acdfa52-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:acdfa52-python
ghcr.io/openhands/agent-server:acdfa52e1340a44c38a58a51b051f47c682ef3e7-python
ghcr.io/openhands/agent-server:openhands-workspace-gycwdfck9lsvbth8rqt6l-python
ghcr.io/openhands/agent-server:acdfa52-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim

About Multi-Architecture Support

  • Each variant tag (e.g., acdfa52-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., acdfa52-python-amd64) are also available if needed

…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>
@github-actions

github-actions Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Artifacts Cleaned Up

The .pr/ directory has been automatically removed.

@github-actions github-actions Bot added the release-note-required PR requires explicit release-note coverage for behavioral or default changes label Jul 21, 2026
@github-actions

github-actions Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Python API breakage checks — ✅ PASSED

Result: ✅ PASSED

Behavioral default changes detected

These public Field(default=...) changes were introduced by this PR and were auto-marked with the release-note-required label:

  • openhands.workspace.apptainer.workspace.ApptainerWorkspace.forward_env: lambda: ['DEBUG'] → lambda: ['DEBUG', 'SESSION_API_KEY', 'OH_SESSION_API_KEYS_0']
  • openhands.workspace.docker.workspace.DockerWorkspace.forward_env: lambda: ['DEBUG'] → lambda: ['DEBUG', 'SESSION_API_KEY', 'OH_SESSION_API_KEYS_0']
  • openhands.workspace.docker.workspace.DockerWorkspace.forward_env: lambda: ['DEBUG'] → lambda: ['DEBUG', 'SESSION_API_KEY', 'OH_SESSION_API_KEYS_0']

Action log

@github-actions

github-actions Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

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>
@github-actions

github-actions Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-agent-server/openhands/agent_server
   __main__.py1381391%41–42, 47, 94, 185–186, 191, 207, 266, 304, 334–335, 343
openhands-workspace/openhands/workspace/apptainer
   workspace.py1777458%162, 171, 174–175, 178–179, 186, 199, 225–226, 228, 231–233, 235–237, 239, 242, 248–250, 254–255, 263, 268–270, 328–329, 333–343, 345–348, 352–353, 355–361, 364, 366, 371–372, 376, 380, 394, 398–410
openhands-workspace/openhands/workspace/docker
   workspace.py1935074%30–32, 50, 148, 168, 189, 192, 195–196, 199–200, 207, 216, 219–220, 224, 234, 261, 290, 299, 306–307, 311–312, 316, 319–320, 322–328, 331–332, 341–343, 347–349, 353, 357, 363–364, 387, 407, 424
TOTAL384551594559% 

@neubig
neubig marked this pull request as ready for review July 22, 2026 23:01

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 43047

Observed:

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 52449

Observed:

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.0

Observed:

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 40721

Observed:

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 output

The 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

@enyst enyst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@neubig
neubig merged commit f1835d2 into main Jul 23, 2026
34 checks passed
@neubig
neubig deleted the openhands-workspace-Gycwdfck9LsVBTH8rQt6L branch July 23, 2026 09:11
@github-actions github-actions Bot mentioned this pull request Jul 24, 2026
1 of 8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note-required PR requires explicit release-note coverage for behavioral or default changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants