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 -1
View File
@@ -51,6 +51,15 @@ function command(memoryMb: number): { cmd: string; args: string[] } {
return { cmd: exe, args: ["--role", "sandbox"] };
}
/**
* 子进程环境:清空,只留 PATH。编译产物启动时要按 PATH 解析 --allow-run 里的命令名(ffprobe、cat…),
* 没有 PATH 会在进程入口报「no path to search」直接退出,所有沙箱任务都失败(2026-10 Bangumi 热门、字幕验证码即此)。
* 子进程随后撤销全部权限,PATH 不放大能力。
*/
export function sandboxEnv(): Record<string, string> {
return { PATH: Deno.env.get("PATH") || "/usr/local/bin:/usr/bin:/bin" };
}
/** 子进程实际内存(KB);读不到返回 null */
async function rssKb(pid: number): Promise<number | null> {
const s = await readProcText(`/proc/${pid}/status`);
@@ -75,7 +84,7 @@ export async function runSandbox<J extends SandboxJobName>(
stdin: "piped",
stdout: "piped",
stderr: "piped",
env: {},
env: sandboxEnv(),
clearEnv: true,
}).spawn();
} catch (e) {