Hmbown/CodeWhale · error

OpenSandbox returned HTTP

Error message

OpenSandbox returned HTTP {}: {}

What it means

The OpenSandbox HTTP endpoint answered with a non-success status while executing a command in the sandbox. The client includes the HTTP status code and the response body (best-effort) in the error so the server-side failure reason is visible. The request itself reached the server; it is the server rejecting or failing the run request.

Solutions

  1. Read the status code and body in the error message to identify the server-side cause.
  2. For 401/403, refresh the OpenSandbox credentials/token configured for the endpoint.
  3. For 404, verify the endpoint URL matches the deployed OpenSandbox server version.
  4. For 429, back off and retry; for 5xx, inspect OpenSandbox server logs and retry once the service recovers.
  5. Use the fallback backend (`sandbox_backend = none`) locally if OpenSandbox is down and sandboxing is not required.
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-flight: ensure endpoint configured and reachable
if endpoint.is_empty() { bail("OpenSandbox endpoint not configured"); }
let ok = reqwest::Client::new().get(format!("{endpoint}/health")).send().await.map(|r| r.status().is_success()).unwrap_or(false);
if !ok { bail("OpenSandbox endpoint unreachable or unhealthy"); }

Try / catch

match sandbox.exec(cmd, env).await {
    Err(e) if e.to_string().contains("OpenSandbox returned HTTP") => {
        log::warn!("OpenSandbox HTTP failure: {e:#}");
        // inspect status; retry on 429/5xx with backoff, else surface to user
    }
    other => other?,
}

Prevention

When it happens

Trigger: POST to the OpenSandbox run endpoint returns 4xx/5xx during SandboxBackend::exec; response.text() is read and bubbled into anyhow::bail! before JSON parsing.

Common situations: 401/403 from an expired or wrong API token; 404 from a wrong endpoint URL or stale server version; 429 rate limiting; 500 from a sandbox image that failed to start or a server-side crash.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/03a973cb1b624470. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/sandbox/opensandbox.rs:102

            cmd: cmd.to_string(),
            env: env.clone(),
        };

        let mut req = self.client.post(self.run_url()).json(&request_body);

        if let Some(ref api_key) = self.api_key {
            req = req.bearer_auth(api_key);
        }

        let response = req
            .send()
            .await
            .context("Failed to reach OpenSandbox endpoint")?;

        let status = response.status();
        if !status.is_success() {
            let body = response.text().await.unwrap_or_default();
            anyhow::bail!("OpenSandbox returned HTTP {}: {}", status.as_u16(), body);
        }

        let parsed: SandboxRunResponse = response
            .json()
            .await
            .context("Failed to parse OpenSandbox response")?;

        Ok(SandboxOutput {
            stdout: parsed.stdout,
            stderr: parsed.stderr,
            exit_code: parsed.exit_code,
        })
    }
}

View on GitHub (pinned to 73e0f67d83)