Skip to content

Commit 9e04efe

Browse files
fix(exec): fail closed without sandbox runtime
1 parent 8962d35 commit 9e04efe

4 files changed

Lines changed: 54 additions & 5 deletions

File tree

‎src/agents/bash-tools.exec-runtime.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ describe("detectCursorKeyMode", () => {
108108
});
109109

110110
describe("resolveExecTarget", () => {
111+
it("defaults omitted host config to sandbox", () => {
112+
expectExecTarget(
113+
resolveExecTarget({
114+
elevatedRequested: false,
115+
sandboxAvailable: false,
116+
}),
117+
{
118+
configuredTarget: "sandbox",
119+
requestedTarget: null,
120+
selectedTarget: "sandbox",
121+
effectiveHost: "sandbox",
122+
},
123+
);
124+
});
125+
111126
it("keeps implicit auto on sandbox when a sandbox runtime is available", () => {
112127
expectExecTarget(
113128
resolveExecTarget({

‎src/agents/bash-tools.exec-runtime.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ export function resolveExecTarget(params: {
239239
elevatedRequested: boolean;
240240
sandboxAvailable: boolean;
241241
}) {
242-
const configuredTarget = params.configuredTarget ?? "auto";
242+
const configuredTarget = params.configuredTarget ?? "sandbox";
243243
const requestedTarget = params.requestedTarget ?? null;
244244
if (
245245
requestedTarget &&

‎src/agents/bash-tools.exec.path.test.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,20 @@ describe("exec host env validation", () => {
310310
}
311311
});
312312

313-
it("routes implicit auto host to gateway when sandbox runtime is unavailable", async () => {
313+
it("fails closed for the implicit sandbox default when sandbox runtime is unavailable", async () => {
314314
const tool = createExecTool({ security: "full", ask: "off" });
315315

316-
const result = await tool.execute("call1", {
316+
await expect(
317+
tool.execute("call1", {
318+
command: "echo ok",
319+
}),
320+
).rejects.toThrow(/requires a sandbox runtime/);
321+
});
322+
323+
it("routes explicit auto host to gateway when sandbox runtime is unavailable", async () => {
324+
const tool = createExecTool({ host: "auto", security: "full", ask: "off" });
325+
326+
const result = await tool.execute("call-explicit-auto", {
317327
command: "echo ok",
318328
yieldMs: FOREGROUND_TEST_YIELD_MS,
319329
});

‎src/agents/pi-tools-agent-config.exec.test.ts‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe("Agent-specific exec tool defaults", () => {
7676
expect(resultDetails?.status).toBe("completed");
7777
});
7878

79-
it("routes implicit auto exec to gateway without a sandbox runtime", async () => {
79+
it("fails closed for the implicit sandbox exec host when sandbox runtime is unavailable", async () => {
8080
const tools = createOpenClawCodingTools({
8181
config: {
8282
tools: {
@@ -92,7 +92,31 @@ describe("Agent-specific exec tool defaults", () => {
9292
});
9393
const execTool = requireExecTool(tools);
9494

95-
const result = await execTool.execute("call-implicit-auto-default", {
95+
await expect(
96+
execTool.execute("call-implicit-sandbox-default", {
97+
command: "echo done",
98+
}),
99+
).rejects.toThrow(/requires a sandbox runtime/);
100+
});
101+
102+
it("routes explicit auto exec to gateway without a sandbox runtime", async () => {
103+
const tools = createOpenClawCodingTools({
104+
config: {
105+
tools: {
106+
exec: {
107+
host: "auto",
108+
security: "full",
109+
ask: "off",
110+
},
111+
},
112+
},
113+
sessionKey: "agent:main:main",
114+
workspaceDir: "/tmp/test-main-explicit-auto-gateway",
115+
agentDir: "/tmp/agent-main-explicit-auto-gateway",
116+
});
117+
const execTool = requireExecTool(tools);
118+
119+
const result = await execTool.execute("call-explicit-auto-default", {
96120
command: "echo done",
97121
});
98122
const resultDetails = result?.details as { status?: string } | undefined;

0 commit comments

Comments
 (0)