[Bug] openshell-sandbox egress proxy kills WebSocket connections after ~2 minutes — Discord (and other WS-based plugins) cannot run inside sandbox
Summary
The HTTP egress proxy inside the sandbox (10.200.0.1:3128, implemented in /opt/openshell/bin/openshell-sandbox) hard-terminates established connections after approximately 2 minutes. This makes any WebSocket-based integration — including the native openclaw Discord plugin, WhatsApp Web (see #361), and any other long-lived TCP connection — non-functional inside the sandbox. There is no configuration option to change this behaviour.
Environment
- Platform: macOS (Apple Silicon, M-series)
openshell-sandbox: running as PID 1 in k3s pod (ghcr.io/nvidia/openshell/gateway:dev)- Cluster: Docker container
openshell-cluster-nemoclaw(k3s via Docker) - NemoClaw version: 2026.3.x
- OpenClaw version: 2026.3.11–2026.3.13
Two Distinct Failure Modes
1. EAI_AGAIN on gateway.discord.gg — permanent DNS failure
The ws library (used by discord.js for the WebSocket leg) does not honour HTTPS_PROXY. It attempts a direct socket connection and requires local DNS resolution of gateway.discord.gg. Inside the sandbox, this hostname never resolves — the cluster DNS (10.43.0.10, CoreDNS) does not forward public hostname resolution for sandbox pods.
The REST client works because it sends CONNECT discord.com:443 to the HTTP proxy, which resolves the hostname server-side. The WebSocket client bypasses the proxy and hits DNS directly, so it always fails.
Symptom: tight infinite loop in the openshell logs —
L7_REQUEST GET /api/v10/oauth2/applications/@me → discord.com:443 allow
L7_REQUEST GET /api/v10/users/@me → discord.com:443 allow
// then EAI_AGAIN on gateway.discord.gg, retry immediately, repeat
2. 2-minute hard connection cutoff — WebSocket dropped even if DNS resolves
If DNS is resolved externally (e.g. via a workaround), the WebSocket connects successfully but is terminated by the proxy after ~2 minutes 13 seconds with WebSocket close code 1006 (abnormal closure). The discord.js client attempts to reconnect; reconnect attempts also fail (same DNS/proxy issue), and the health-monitor eventually restarts the provider from scratch — resulting in ~50% uptime with 2–3 minute outage windows.
Confirmed via gateway log:
[discord] logged in to discord as <id> (Kaveri) ← 03:58:47
[discord] gateway error: AggregateError ← 04:01:00 (+2m13s)
[discord] gateway: WebSocket connection closed (1006)
[discord] gateway: Reconnecting with backoff: 1000ms
Root Cause
The cutoff lives inside /opt/openshell/bin/openshell-sandbox — the compiled Rust binary running as PID 1 in the sandbox k3s pod. Inspected via:
docker exec openshell-cluster-nemoclaw kubectl exec -n openshell kaveri \
-- /opt/openshell/bin/openshell-sandbox --help
The --help output exposes no proxy timeout flag, no --connect-timeout, no env var, no config file. The k3s pod spec for the sandbox container has no relevant environment variables. The timeout is hardcoded in the binary.
Impact
Any openclaw plugin or user workload that requires a persistent TCP/WebSocket connection is broken inside the sandbox:
- openclaw native Discord plugin
- WhatsApp Web (confirmed in #361 — same 408 timeout on WS opening handshake)
- Any long-running HTTPS stream or SSE connection
Current Workaround
Run the Discord client on the host (outside the sandbox), forwarding messages to the agent via SSH + nemoclaw-start openclaw agent. This mirrors the existing Telegram bridge architecture. It works, but duplicates logic the openclaw gateway already handles natively and requires maintaining a parallel gateway layer.
Proposed Fix
Either of the following in openshell-sandbox:
- Remove or increase the hard cutoff for CONNECT tunnel connections (or make it configurable via env var or sandbox policy).
- Add a
proxy: directmode to the sandbox network policy schema, allowing specific endpoints (e.g.gateway.discord.gg) to bypass the HTTP proxy entirely — directly through the network namespace if routing allows, or via a separate non-timeout-limited tunnel.
Option 2 is preferable long-term as it gives per-endpoint control without globally relaxing the proxy timeout.
Related
- #213 — Discord bridge proposal (workaround)
- #361 — WhatsApp Web WebSocket failure (same root cause)
- #311 — gateway manual restart after reboot (related: sandbox process lifecycle)
Opened #438 with a policy-level fix for the WebSocket timeout.
Root cause analysis: The Discord preset configures gateway.discord.gg with protocol: rest + tls: terminate, which routes the WebSocket connection through the proxy's HTTP layer. The proxy sees an idle HTTP connection after the WS upgrade handshake and kills it after its ~2-min idle timeout.
Fix: Switch WebSocket endpoints to access: full (CONNECT tunnel), which bypasses HTTP-level timeouts — the proxy just forwards raw TCP bytes. This matches the existing pattern used for github.com and registry.npmjs.org in the baseline sandbox policy.
Also applied the same fix to Slack's Socket Mode WebSocket endpoints (wss-primary.slack.com, wss-backup.slack.com) which would hit the same issue.
What remains: The hardcoded timeout in openshell-sandbox still affects protocol: rest endpoints with long-lived connections (SSE, long-polling). That needs an upstream OpenShell fix.
Root cause found + workaround confirmed working
After digging into the compiled plugin source (compact-1mmJ_KWL.js), the Discord WebSocket disconnect and EAI_AGAIN issues have the same root cause: the openclaw Discord gateway plugin only uses an HttpsProxyAgent for WebSocket connections if channels.discord.proxy is explicitly set in the config. Without it, the ws library opens a raw TCP socket and resolves DNS via /etc/resolv.conf — which inside the sandbox points to the k3s internal CoreDNS (10.43.0.10), which has no knowledge of external hosts like gateway.discord.gg.
The relevant code path in the plugin: ```js const proxy = params.discordConfig?.proxy?.trim(); if (!proxy) return new GatewayPlugin(options); // no proxy → raw WebSocket → EAI_AGAIN const wsAgent = new HttpsProxyAgent(proxy); // ... createWebSocket(url) { return new WebSocket(url, { agent: wsAgent }); // CONNECT tunnel → proxy resolves DNS } ```
Workaround: Add to openclaw.json under channels.discord:
```json
"proxy": "http://10.200.0.1:3128"
```
This activates the HttpsProxyAgent, routes the WebSocket through the sandbox's HTTP CONNECT proxy, and the proxy resolves DNS server-side. Discord bot goes from permanently offline to stable connection.
Proper fix: The plugin should auto-detect HTTPS_PROXY / HTTP_PROXY from the environment (already set in the sandbox as http://10.200.0.1:3128) and apply it to the WebSocket agent automatically — the same way it already does for HTTP REST calls via EnvHttpProxyAgent. Users running in proxy-required environments (like openshell sandboxes) have no way to know this field exists or that it's needed.
Note: PR #438 (access: full policy for gateway.discord.gg) is still correct and complementary — it ensures the CONNECT tunnel isn't killed by the proxy's HTTP idle timeout. Both fixes are needed.
Thanks for reporting this issue with the OpenShell sandbox egress proxy, I appreciate you providing detailed information about the problem, including the specific error and affected plugins like Discord.
This hardcoded 60s also seems to prevent thinking models that take longer than 60s to respond if running local models through ollama too. https://github.com/NVIDIA/OpenShell/blob/0ac1fbd21b50f3aeaf7160223bf6ea5f6061a144/crates/openshell-router/src/lib.rs#L36
Closing — the WebSocket symptoms originally reported here have been addressed by a series of merged fixes across NemoClaw and the upstream OpenShell egress proxy.
Upstream root-cause fixes in NVIDIA/OpenShell:
- NVIDIA/OpenShell#652 — egress proxy now detects HTTP 101 Switching Protocols and switches the relay to raw
tokio::io::copy_bidirectionalinstead of continuing L7 HTTP parsing on what is now WebSocket frames. (Closed 2026-04-02.) - NVIDIA/OpenShell#641 — replaced the 60s
reqwesttotal-request timeout inopenshell-routerwith a chunk-resetting read timeout, fixing the long-stream truncation @Cazforshort flagged. (Closed 2026-03-30.)
NemoClaw policy / config fixes layered on top:
- #438 — Discord (
gateway.discord.gg) and Slack (wss-primary/backup.slack.com) WebSocket endpoints switched fromprotocol: resttoaccess: full(CONNECT tunnel), bypassing HTTP-layer idle timeouts. - #1004 — applied
access: fullforgateway.discord.ggin the default sandbox policy. - #2098 — restored the L4 tunnel for WebSocket hosts via
tls: skip(regression fix). - #2187 — bakes
proxy: http://10.200.0.1:3128into the Discord account config so thewslibrary usesHttpsProxyAgent, fixing theEAI_AGAINDNS-resolution failure mode @subrih identified. - #2296 — WebSocket CONNECT tunnel preload for the Discord gateway.
If anyone still repros a 2-minute WebSocket cutoff or EAI_AGAIN on gateway.discord.gg against current OpenShell + NemoClaw, please open a fresh issue with version info — the code paths involved have changed substantially since this report.
Related: #361 (WhatsApp Web — same root cause), NVIDIA/OpenShell#913 (WSS payload token rewriting — separate, still open), NVIDIA/OpenShell#866 (per-route inference chunk-idle timeout — separate, still open).