Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions nemo_gym/sandbox/providers/opensandbox/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,14 @@ def _connection_config(
kwargs["request_timeout"] = timedelta(seconds=request_timeout_s)
if self._connection.use_server_proxy:
kwargs["use_server_proxy"] = True
# The SDK's execd-facing clients (health ping, commands, files)
# send only ConnectionConfig.headers — api_key alone never reaches
# proxied /proxy/* routes, so servers that enforce auth there 401
# every health ping and create times out at ready_timeout. Inject
# the key only in proxy mode: a direct sandbox endpoint runs
# untrusted code and must never see it.
if self._connection.api_key is not None:
kwargs["headers"] = {"OPEN-SANDBOX-API-KEY": self._connection.api_key}
if self._connection.keepalive_expiry_s is not None or self._connection.disable_connection_pooling:
kwargs["transport"] = self._get_transport()
return ConnectionConfig(**kwargs)
Expand Down
11 changes: 11 additions & 0 deletions tests/unit_tests/test_opensandbox_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,21 @@ def test_connection_config_and_image_policy(fake_opensandbox_sdk: None) -> None:
"protocol": "https",
"request_timeout": timedelta(seconds=10),
"use_server_proxy": True,
# The API key must also travel as a header: the SDK's execd clients
# (health ping, commands, files) send only ConnectionConfig.headers,
# and proxied /proxy/* routes may enforce auth.
"headers": {"OPEN-SANDBOX-API-KEY": "key"}, # pragma: allowlist secret
}
short_timeout_config = provider._connection_config(request_timeout_s=3)
assert short_timeout_config.kwargs["request_timeout"] == timedelta(seconds=3)

# Direct-endpoint mode must NOT carry the key: the sandbox runs untrusted
# code and would be able to read it.
direct = opensandbox_provider.OpenSandboxProvider(
connection={"domain": "sandbox.example", "api_key": "key"} # pragma: allowlist secret
)
assert "headers" not in direct._connection_config().kwargs


def test_connection_transport_backends(fake_opensandbox_sdk: None, monkeypatch: pytest.MonkeyPatch) -> None:
# Default backend is httpx, with the configured keepalive expiry on the pool.
Expand Down
Loading