Skip to content

Commit 14dea0c

Browse files
committed
fix(codex): expose docker sandbox fallback tools
1 parent aa68711 commit 14dea0c

2 files changed

Lines changed: 63 additions & 4 deletions

File tree

‎extensions/codex/src/app-server/run-attempt.test.ts‎

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ describe("runCodexAppServerAttempt", () => {
744744
);
745745
});
746746

747-
it("does not expose sandbox shell tools unless non-Docker sandbox routing is available", async () => {
747+
it("keeps Docker sandbox shell tools hidden when native Code Mode can honor sandbox paths", async () => {
748748
testing.setOpenClawCodingToolsFactoryForTests(() => [
749749
createRuntimeDynamicTool("exec"),
750750
createRuntimeDynamicTool("process"),
@@ -765,11 +765,69 @@ describe("runCodexAppServerAttempt", () => {
765765
effectiveWorkspace: workspaceDir,
766766
sandboxSessionKey,
767767
sandbox: { enabled: true, backendId: "docker" } as never,
768+
nativeToolSurfaceEnabled: true,
768769
runAbortController: new AbortController(),
769770
sessionAgentId: "main",
770771
pluginConfig: {},
771772
onYieldDetected: () => undefined,
772773
});
774+
775+
expect(dockerTools.map((tool) => tool.name)).toEqual(["message"]);
776+
});
777+
778+
it("exposes Docker sandbox shell tools when native Code Mode cannot honor sandbox paths", async () => {
779+
testing.setOpenClawCodingToolsFactoryForTests(() => [
780+
createRuntimeDynamicTool("exec"),
781+
createRuntimeDynamicTool("process"),
782+
createRuntimeDynamicTool("message"),
783+
]);
784+
const sessionFile = path.join(tempDir, "session.jsonl");
785+
const workspaceDir = path.join(tempDir, "workspace");
786+
const params = createParams(sessionFile, workspaceDir);
787+
params.disableTools = false;
788+
const sandboxSessionKey = params.sessionKey;
789+
if (!sandboxSessionKey) {
790+
throw new Error("createParams must provide a sessionKey for Codex dynamic tool tests.");
791+
}
792+
793+
const tools = await testing.buildDynamicTools({
794+
params,
795+
resolvedWorkspace: workspaceDir,
796+
effectiveWorkspace: workspaceDir,
797+
sandboxSessionKey,
798+
sandbox: {
799+
enabled: true,
800+
backendId: "docker",
801+
docker: { binds: ["/tmp/openclaw-data:/data:rw"] },
802+
} as never,
803+
nativeToolSurfaceEnabled: false,
804+
runAbortController: new AbortController(),
805+
sessionAgentId: "main",
806+
pluginConfig: {},
807+
onYieldDetected: () => undefined,
808+
});
809+
810+
expect(tools.map((tool) => tool.name)).toEqual(["message", "sandbox_exec", "sandbox_process"]);
811+
expect(tools.find((tool) => tool.name === "sandbox_exec")?.description).toContain(
812+
"Docker container-path bind layout",
813+
);
814+
});
815+
816+
it("does not expose sandbox shell tools when sandbox routing is disabled", async () => {
817+
testing.setOpenClawCodingToolsFactoryForTests(() => [
818+
createRuntimeDynamicTool("exec"),
819+
createRuntimeDynamicTool("process"),
820+
createRuntimeDynamicTool("message"),
821+
]);
822+
const sessionFile = path.join(tempDir, "session.jsonl");
823+
const workspaceDir = path.join(tempDir, "workspace");
824+
const params = createParams(sessionFile, workspaceDir);
825+
params.disableTools = false;
826+
const sandboxSessionKey = params.sessionKey;
827+
if (!sandboxSessionKey) {
828+
throw new Error("createParams must provide a sessionKey for Codex dynamic tool tests.");
829+
}
830+
773831
const disabledSandboxTools = await testing.buildDynamicTools({
774832
params,
775833
resolvedWorkspace: workspaceDir,
@@ -782,7 +840,6 @@ describe("runCodexAppServerAttempt", () => {
782840
onYieldDetected: () => undefined,
783841
});
784842

785-
expect(dockerTools.map((tool) => tool.name)).toEqual(["message"]);
786843
expect(disabledSandboxTools.map((tool) => tool.name)).toEqual(["message"]);
787844
});
788845

‎extensions/codex/src/app-server/run-attempt.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,7 @@ export async function runCodexAppServerAttempt(
915915
effectiveWorkspace,
916916
sandboxSessionKey,
917917
sandbox,
918+
nativeToolSurfaceEnabled,
918919
runAbortController,
919920
sessionAgentId,
920921
pluginConfig,
@@ -3155,6 +3156,7 @@ type DynamicToolBuildParams = {
31553156
effectiveWorkspace: string;
31563157
sandboxSessionKey: string;
31573158
sandbox: Awaited<ReturnType<typeof resolveSandboxContext>>;
3159+
nativeToolSurfaceEnabled?: boolean;
31583160
runAbortController: AbortController;
31593161
sessionAgentId: string;
31603162
pluginConfig: CodexPluginConfig;
@@ -3371,7 +3373,7 @@ function addSandboxShellDynamicToolsIfAvailable(
33713373
...execTool,
33723374
name: "sandbox_exec",
33733375
description:
3374-
"Run a shell command through OpenClaw's configured sandbox backend for this session. Use only when the command must execute in the OpenClaw sandbox backend, such as an SSH-backed sandbox. Use Codex's native shell for normal local workspace commands.",
3376+
"Run a shell command through OpenClaw's configured sandbox backend for this session. Use only when the command must execute in the OpenClaw sandbox backend, such as an SSH-backed sandbox or Docker container-path bind layout that Codex's native shell cannot represent. Use Codex's native shell for normal local workspace commands.",
33753377
execute: async (toolCallId, args, signal, onUpdate) => {
33763378
const result = await execTool.execute(toolCallId, args, signal, onUpdate);
33773379
return {
@@ -3400,7 +3402,7 @@ function addSandboxShellDynamicToolsIfAvailable(
34003402

34013403
function shouldExposeSandboxExecDynamicTool(input: DynamicToolBuildParams): boolean {
34023404
const backendId = input.sandbox?.enabled ? input.sandbox.backendId.trim().toLowerCase() : "";
3403-
return Boolean(backendId && backendId !== "docker");
3405+
return Boolean(backendId && (backendId !== "docker" || input.nativeToolSurfaceEnabled === false));
34043406
}
34053407

34063408
function isSandboxShellDynamicToolExcluded(config: CodexPluginConfig): boolean {

0 commit comments

Comments
 (0)