@@ -101,6 +101,58 @@ describe("resolveSandboxContext", () => {
101101 expect ( result ) . toBeNull ( ) ;
102102 } , 15_000 ) ;
103103
104+ it ( "does not touch sandbox backends for cron or sub-agent sessions when sandbox mode is off" , async ( ) => {
105+ const backendFactory = vi . fn ( async ( ) => ( {
106+ id : "test-off-backend" ,
107+ runtimeId : "unexpected-runtime" ,
108+ runtimeLabel : "Unexpected Runtime" ,
109+ workdir : "/workspace" ,
110+ buildExecSpec : async ( ) => ( {
111+ argv : [ "unexpected" ] ,
112+ env : process . env ,
113+ stdinMode : "pipe-closed" as const ,
114+ } ) ,
115+ runShellCommand : async ( ) => ( {
116+ stdout : Buffer . alloc ( 0 ) ,
117+ stderr : Buffer . alloc ( 0 ) ,
118+ code : 0 ,
119+ } ) ,
120+ } ) ) ;
121+ const restore = registerSandboxBackend ( "test-off-backend" , backendFactory ) ;
122+ try {
123+ const cfg : OpenClawConfig = {
124+ agents : {
125+ defaults : {
126+ sandbox : {
127+ mode : "off" ,
128+ backend : "test-off-backend" ,
129+ scope : "session" ,
130+ } ,
131+ } ,
132+ } ,
133+ } ;
134+
135+ await expect (
136+ resolveSandboxContext ( {
137+ config : cfg ,
138+ sessionKey : "agent:main:cron:job:run:uuid" ,
139+ workspaceDir : "/tmp/openclaw-test" ,
140+ } ) ,
141+ ) . resolves . toBeNull ( ) ;
142+ await expect (
143+ resolveSandboxContext ( {
144+ config : cfg ,
145+ sessionKey : "agent:main:subagent:child" ,
146+ workspaceDir : "/tmp/openclaw-test" ,
147+ } ) ,
148+ ) . resolves . toBeNull ( ) ;
149+
150+ expect ( backendFactory ) . not . toHaveBeenCalled ( ) ;
151+ } finally {
152+ restore ( ) ;
153+ }
154+ } , 15_000 ) ;
155+
104156 it ( "treats main session aliases as main in non-main mode" , async ( ) => {
105157 const cfg : OpenClawConfig = {
106158 session : { mainKey : "work" } ,
0 commit comments