Sandbox: add actionable error when docker missing (#28547)

Co-authored-by: AaronWander <siralonne@163.com>
This commit is contained in:
AaronWander 2026-03-02 14:14:26 +08:00 committed by GitHub
parent 3049ca840f
commit 366374b4ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,21 @@
import { describe, expect, it } from "vitest";
import { withEnvAsync } from "../../test-utils/env.js";
import { execDockerRaw } from "./docker.js";
describe("execDockerRaw", () => {
it("wraps docker ENOENT with an actionable configuration error", async () => {
await withEnvAsync({ PATH: "" }, async () => {
let err: unknown;
try {
await execDockerRaw(["version"]);
} catch (caught) {
err = caught;
}
expect(err).toBeInstanceOf(Error);
expect(err).toMatchObject({ code: "INVALID_CONFIG" });
expect((err as Error).message).toContain("Sandbox mode requires Docker");
expect((err as Error).message).toContain("agents.defaults.sandbox.mode=off");
});
});
});

View File

@ -65,6 +65,21 @@ export function execDockerRaw(
if (signal) {
signal.removeEventListener("abort", handleAbort);
}
if (
error &&
typeof error === "object" &&
"code" in error &&
(error as NodeJS.ErrnoException).code === "ENOENT"
) {
const friendly = Object.assign(
new Error(
'Sandbox mode requires Docker, but the "docker" command was not found in PATH. Install Docker (and ensure "docker" is available), or set `agents.defaults.sandbox.mode=off` to disable sandboxing.',
),
{ code: "INVALID_CONFIG", cause: error },
);
reject(friendly);
return;
}
reject(error);
});