@@ -49,7 +49,10 @@ import { createOpenClawTools } from "./openclaw-tools.js";
4949import { expectReadWriteEditTools } from "./test-helpers/agent-tools-fs-helpers.js" ;
5050import { createAgentToolsSandboxContext } from "./test-helpers/agent-tools-sandbox-context.js" ;
5151import { stubTool } from "./test-helpers/fast-tool-stubs.js" ;
52- import { createHostSandboxFsBridge } from "./test-helpers/host-sandbox-fs-bridge.js" ;
52+ import {
53+ createHostSandboxFsBridge ,
54+ createSandboxFsBridgeFromResolver ,
55+ } from "./test-helpers/host-sandbox-fs-bridge.js" ;
5356import { buildEmptyExplicitToolAllowlistError } from "./tool-allowlist-guard.js" ;
5457import { DEFAULT_PLUGIN_TOOLS_ALLOWLIST_ENTRY , normalizeToolPolicyName } from "./tool-policy.js" ;
5558import { replaceWithEffectiveCronCreatorToolAllowlist } from "./tools/cron-tool.js" ;
@@ -1082,6 +1085,54 @@ describe("createOpenClawCodingTools", () => {
10821085 expect ( latestCreateOpenClawToolsOptions ( ) . fsPolicy ) . toEqual ( { workspaceOnly : true } ) ;
10831086 } ) ;
10841087
1088+ it ( "allows workspace-only reads from declared sandbox bind mounts" , async ( ) => {
1089+ const workspaceDir = tempDirs . make ( "openclaw-sandbox-workspace-" ) ;
1090+ const bindRoot = tempDirs . make ( "openclaw-sandbox-bind-" ) ;
1091+ const boundFile = path . join ( bindRoot , "example" , "tree-index.json" ) ;
1092+ await fs . mkdir ( path . dirname ( boundFile ) , { recursive : true } ) ;
1093+ await fs . writeFile ( boundFile , '{"ready":true}\n' , "utf8" ) ;
1094+
1095+ const sandbox = createAgentToolsSandboxContext ( {
1096+ workspaceDir,
1097+ workspaceAccess : "none" ,
1098+ dockerOverrides : { binds : [ `${ bindRoot } :/cache/repos:ro` ] } ,
1099+ } ) ;
1100+ sandbox . fsBridge = createSandboxFsBridgeFromResolver ( ( filePath ) => {
1101+ const relativePath = path . posix . relative ( "/cache/repos" , filePath ) ;
1102+ return {
1103+ hostPath : path . join ( bindRoot , relativePath ) ,
1104+ relativePath,
1105+ containerPath : filePath ,
1106+ } ;
1107+ } ) ;
1108+
1109+ const tools = createOpenClawCodingTools ( {
1110+ workspaceDir,
1111+ config : { tools : { fs : { workspaceOnly : true } } } ,
1112+ sandbox,
1113+ } ) ;
1114+
1115+ const { readTool, writeTool, editTool } = expectReadWriteEditTools ( tools ) ;
1116+ const result = await readTool . execute ( "read-declared-bind" , {
1117+ path : "/cache/repos/example/tree-index.json" ,
1118+ } ) ;
1119+ expect ( extractToolText ( result ) ) . toContain ( '{"ready":true}' ) ;
1120+ await expect (
1121+ writeTool . execute ( "write-declared-bind" , {
1122+ path : "/cache/repos/example/tree-index.json" ,
1123+ content : "overwritten" ,
1124+ } ) ,
1125+ ) . rejects . toThrow ( / P a t h e s c a p e s s a n d b o x r o o t / i) ;
1126+ await expect (
1127+ editTool . execute ( "edit-declared-bind" , {
1128+ path : "/cache/repos/example/tree-index.json" ,
1129+ oldText : "true" ,
1130+ newText : "false" ,
1131+ } ) ,
1132+ ) . rejects . toThrow ( / P a t h e s c a p e s s a n d b o x r o o t / i) ;
1133+ await expect ( fs . readFile ( boundFile , "utf8" ) ) . resolves . toBe ( '{"ready":true}\n' ) ;
1134+ } ) ;
1135+
10851136 it ( "uses the canonical spawn workspace for follow-up task suggestions" , ( ) => {
10861137 const createOpenClawToolsMock = vi . mocked ( createOpenClawTools ) ;
10871138 createOpenClawToolsMock . mockClear ( ) ;
0 commit comments