fix(sandbox): 子进程环境保留 PATH,编译产物里沙箱任务恢复;编译自检加沙箱启动

清空环境后编译产物在入口按 PATH 解析 --allow-run 失败直接退出,Bangumi 热门、字幕验证码 / 解压等沙箱任务一直报错。

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Cxwgnn2pbzQ7rXv3rq7fei
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-10-08 18:08:28 +08:00
1 parent 0d796d92ef
commit 3f1c6d02f6
3 files changed
+27 -4

No files matched your search

+10 -2
View File
@@ -10,8 +10,16 @@ case "$bin" in /*) ;; *) bin="$PWD/$bin" ;; esac
out=$(cd /tmp && env -i PATH="$PATH" "$bin" --role preflight 2>&1)
code=$?
if [ "$code" -eq 2 ] && printf '%s' "$out" | grep -q '配置无效'; then
echo "check-compiled-binary: ok(模块图加载完整)"
exit 0
# 沙箱子进程:与 sandbox/client.ts 同样的环境(只有 PATH)拉起 `--role sandbox`,请求一个不存在的任务,
# 应回一行 {"ok":false,...};入口就崩(如 --allow-run 解析失败)会没有这行
sb=$(cd /tmp && printf '{"job":"__check__","input":null}' | env -i PATH="$PATH" "$bin" --role sandbox 2>&1)
if printf '%s' "$sb" | grep -q '"ok":false'; then
echo "check-compiled-binary: ok(模块图加载完整,沙箱子进程能启动)"
exit 0
fi
echo "check-compiled-binary: 沙箱子进程起不来:" >&2
printf '%s\n' "$sb" >&2
exit 1
fi
echo "check-compiled-binary: 编译产物自检失败(退出码 $code):" >&2
printf '%s\n' "$out" >&2