← ClaudeAtlas

git-push-in-sandboxlisted

在沙箱(WorkBuddy / CodeBuddy 等受限执行环境)里推送 Git 仓库失败时的网络诊断与绕行。当 git push 报 `502 CONNECT tunnel failed`、`Operation timed out`、`ssh_dispatch_run_fatal`,而 `gh api` 却完全正常时使用。触发词:push 失败、推不上去、502 CONNECT tunnel、push 超时、git push 报错、沙箱网络。
xingtu1996/xingtu-skills · ★ 2 · Code & Development · score 74
Install: claude install-skill xingtu1996/xingtu-skills
# 沙箱内 `git push` 失败的诊断与绕行 ## 一、症状签名(一眼识别) **`gh api` / `gh repo create` 全正常,唯独 `git push` 失败。** 典型报错: - `fatal: unable to access 'https://github.com/<o>/<r>.git/': CONNECT tunnel failed, response 502` - `ssh_dispatch_run_fatal: Connection to <ip> port 443: Operation timed out` - `ssh: connect to host github.com port 22: Operation timed out` 这**不是** GitHub 的问题,也**不是**用户代理配置的问题——是**沙箱出口白名单**只放行了 `api.*`, 没放行 git 协议通道(SSH 与 HTTPS 的 git 端点都被拦)。 ## 二、30 秒确诊(照抄) ```bash # 1) 代理 → github.com 预期:502 curl -x "$HTTPS_PROXY" -sS -o /dev/null -w "%{http_code}\n" --max-time 15 https://github.com # 2) 直连 → github.com 预期:000(timeout) curl --noproxy '*' -sS -o /dev/null -w "%{http_code}\n" --max-time 15 https://github.com # 3) 代理 → api.github.com 预期:200 ← 关键对照组 curl -x "$HTTPS_PROXY" -sS -o /dev/null -w "%{http_code}\n" --max-time 15 https://api.github.com ``` **判读**:`1 失败 + 2 失败 + 3 成功` → **确诊沙箱白名单**。 不要去折腾 `http.proxy`、`gh auth setup-git`、证书或换 SSH 端点——那些是被"看起来像代理问题"误导的弯路。 > 若 `3` 也失败,才说明是代理/网络本身的问题,另作排查。 ## 三、⚠️ 两个假阳性陷阱 1. **`nc -z` 不可信**:`nc -z ssh.github.com 443` 可能报 succeeded,但 SSH 握手数据照样被拦。 **不要用端口探测下结论,要用完整协议握手验证**:`ssh -T -o ConnectTimeout=12 git@github.com`。 2. **`gh repo create --push` 中途被杀**(如 exit 137 / SIGTERM):仓库会**建成功但为空**。 此时不要再建一次,直接补 `git push` 即可。 ## 四、解法 ### 首选:让 push 跳出沙箱 在该条 Bash 调用上设 `dangerouslyDisableSandbox: true`(会向用户弹授权,属正常流程): ```bash cd <repo> && git push -u origin main ``` **不需要**改任何代理配置。跳出沙箱后直连即可通。 ### 备用:SSH over 443 若跳