Skip to content

Commit d53f57c

Browse files
fix(exec): inherit configured host for per-call auto (#132100)
* fix(exec): inherit configured host for per-call auto * test(exec): cover auto host inheritance across preparation and dispatch Clarify configured host inheritance in the exec schema and documentation. Preserve required sandbox isolation and explicit host policy in regression coverage. Co-authored-by: Omar Shahine <[email protected]> * docs(exec): keep host guidance within the schema prompt budget --------- Co-authored-by: Omar Shahine <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
1 parent 10f66be commit d53f57c

5 files changed

Lines changed: 56 additions & 46 deletions

File tree

‎docs/tools/exec.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Run in a pseudo-terminal when available. Use for TTY-only CLIs, coding agents, a
4343
</ParamField>
4444

4545
<ParamField path="host" type="'auto' | 'sandbox' | 'gateway' | 'node'" default="auto">
46-
Where to execute. `auto` resolves to `sandbox` when a sandbox runtime is active and `gateway` otherwise.
46+
Where to execute. Omit `host` or use `auto` to inherit the configured exec host, including agent and session overrides. When that configured host is also `auto`, it resolves to `sandbox` when a sandbox runtime is active and `gateway` otherwise. A session that requires a sandbox stays sandboxed regardless of the configured host.
4747
</ParamField>
4848

4949
<ParamField path="security" type="'deny' | 'allowlist' | 'full'">

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ export function resolveExecTarget(params: {
268268
}
269269
// Session isolation outranks every agent, session, and request-scoped host preference.
270270
const configuredTarget = sandboxRequired ? "auto" : (params.configuredTarget ?? "auto");
271-
const requestedTarget = params.requestedTarget ?? null;
271+
const requestedTarget =
272+
params.requestedTarget === "auto" ? null : (params.requestedTarget ?? null);
272273
if (sandboxRequired && (requestedTarget === "gateway" || requestedTarget === "node")) {
273274
throw registerTrustedToolNoStartError(
274275
new Error(

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

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -177,35 +177,30 @@ describe("resolveExecTarget", () => {
177177
);
178178
});
179179

180-
it("allows explicit auto request when configured host is auto", () => {
181-
expectExecTarget(
182-
resolveExecTarget({
183-
configuredTarget: "auto",
180+
it.each([
181+
["auto", true, false, "sandbox"],
182+
["auto", false, false, "gateway"],
183+
["sandbox", true, false, "sandbox"],
184+
["gateway", true, false, "gateway"],
185+
["gateway", false, false, "gateway"],
186+
["node", false, false, "node"],
187+
["sandbox", true, true, "gateway"],
188+
["node", true, true, "node"],
189+
] as const)(
190+
"inherits configured host=%s for auto (sandbox=%s, elevated=%s)",
191+
(configuredTarget, sandboxAvailable, elevatedRequested, effectiveHost) => {
192+
const result = resolveExecTarget({
193+
configuredTarget,
184194
requestedTarget: "auto",
185-
elevatedRequested: false,
186-
sandboxAvailable: true,
187-
}),
188-
{
189-
configuredTarget: "auto",
190-
requestedTarget: "auto",
191-
selectedTarget: "auto",
192-
effectiveHost: "sandbox",
193-
},
194-
);
195-
});
196-
197-
it("requires an exact match for non-auto configured targets", () => {
198-
expect(() =>
199-
resolveExecTarget({
200-
configuredTarget: "gateway",
201-
requestedTarget: "auto",
202-
elevatedRequested: false,
203-
sandboxAvailable: true,
204-
}),
205-
).toThrow(
206-
"exec host not allowed (requested auto; configured host is gateway; set tools.exec.host=auto to allow this override).",
207-
);
208-
});
195+
elevatedRequested,
196+
sandboxAvailable,
197+
});
198+
expect(result).toEqual(
199+
resolveExecTarget({ configuredTarget, elevatedRequested, sandboxAvailable }),
200+
);
201+
expect(result.effectiveHost).toBe(effectiveHost);
202+
},
203+
);
209204

210205
it("allows exact node matches", () => {
211206
expectExecTarget(
@@ -320,12 +315,18 @@ describe("resolveExecTarget", () => {
320315
},
321316
);
322317

323-
it.each(["gateway", "node"] as const)(
324-
"keeps an implicit request sandboxed despite configured host=%s",
325-
(host) => {
318+
it.each([
319+
{ host: "gateway", requestedTarget: undefined },
320+
{ host: "gateway", requestedTarget: "auto" },
321+
{ host: "node", requestedTarget: undefined },
322+
{ host: "node", requestedTarget: "auto" },
323+
] as const)(
324+
"keeps requested=$requestedTarget sandboxed despite configured host=$host",
325+
({ host, requestedTarget }) => {
326326
expect(
327327
resolveExecTarget({
328328
configuredTarget: host,
329+
requestedTarget,
329330
elevatedRequested: false,
330331
sandboxAvailable: true,
331332
sandboxRequired: true,
@@ -348,15 +349,19 @@ describe("resolveExecTarget", () => {
348349
).toThrow(/sandbox|required|elevated/i);
349350
});
350351

351-
it("fails closed when the required sandbox runtime is unavailable", () => {
352-
expect(() =>
353-
resolveExecTarget({
354-
configuredTarget: "auto",
355-
elevatedRequested: false,
356-
sandboxAvailable: false,
357-
sandboxRequired: true,
358-
}),
359-
).toThrow(/sandbox|required|unavailable/i);
360-
});
352+
it.each([undefined, "auto"] as const)(
353+
"fails closed with requested=%s when the required sandbox is unavailable",
354+
(requestedTarget) => {
355+
expect(() =>
356+
resolveExecTarget({
357+
configuredTarget: "auto",
358+
elevatedRequested: false,
359+
sandboxAvailable: false,
360+
sandboxRequired: true,
361+
requestedTarget,
362+
}),
363+
).toThrow(/sandbox|required|unavailable/i);
364+
},
365+
);
361366
});
362367
});

‎src/agents/bash-tools.exec.resolve-env-hook.test.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ describe("exec resolve_exec_env hook wiring", () => {
235235
});
236236
});
237237

238-
it("forwards filtered plugin env to node host requests", async () => {
238+
it("inherits configured node for auto while forwarding filtered plugin env", async () => {
239239
installResolveExecEnvHook({
240240
NODE_HOST_SAFE: "yes",
241241
LD_PRELOAD: "/tmp/preload.dylib",
@@ -252,6 +252,7 @@ describe("exec resolve_exec_env hook wiring", () => {
252252
},
253253
});
254254
await tool.execute("call-node", {
255+
host: "auto",
255256
command: "echo ok",
256257
env: { REQUEST_SAFE: "request" },
257258
});
@@ -275,6 +276,8 @@ describe("exec resolve_exec_env hook wiring", () => {
275276
sender: { id: "ou_node" },
276277
});
277278
expect(mocks.nodeHostParams[0]?.env).not.toHaveProperty("LD_PRELOAD");
279+
expect(mocks.gatewayParams).toHaveLength(0);
280+
expect(mocks.spawnInputs).toHaveLength(0);
278281
});
279282

280283
it("does not forward configured gateway cwd defaults to node host requests", async () => {
@@ -690,7 +693,7 @@ describe("exec resolve_exec_env hook wiring", () => {
690693
});
691694
});
692695

693-
it("forwards private env preparation through the lazy exec tool", async () => {
696+
it("inherits configured gateway for auto through lazy exec preparation", async () => {
694697
mocks.hookRunner = {
695698
hasHooks: vi.fn(
696699
(hookName: string) => hookName === "resolve_exec_env" || hookName === "before_tool_call",
@@ -719,6 +722,7 @@ describe("exec resolve_exec_env hook wiring", () => {
719722
await expectDefined(definition, "definition test invariant").execute(
720723
"call-lazy",
721724
{
725+
host: "auto",
722726
command: "echo ok",
723727
env: { REQUEST_SAFE: "request" },
724728
yieldMs: 120_000,

‎src/agents/bash-tools.schemas.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const execSchema = Type.Object({
5353
}),
5454
),
5555
host: optionalStringEnum(EXEC_TOOL_HOST_VALUES, {
56-
description: "Exec host/target (auto|sandbox|gateway|node).",
56+
description: "Omit or use auto to inherit the configured host.",
5757
}),
5858
security: Type.Optional(
5959
Type.String({

0 commit comments

Comments
 (0)