@@ -91,6 +91,7 @@ function tomlInlineTable(entries: Record<string, string>): string {
9191
9292export function buildAppServerArgs (
9393 options : CodexAppServerProcessOptions ,
94+ environment : NodeJS . ProcessEnv = process . env ,
9495) : string [ ] {
9596 const args : string [ ] = [ "app-server" ] ;
9697
@@ -130,6 +131,16 @@ export function buildAppServerArgs(
130131 // still override it via configOverrides, which the trailing loop appends last.
131132 args . push ( "-c" , `approvals_reviewer="user"` ) ;
132133
134+ // Codex snapshots shell state only for the thread's initial cwd. Cloud tasks
135+ // can work in additional checkouts, so pin the backend-controlled BASH_ENV
136+ // path into every tool shell instead of relying on snapshot restoration.
137+ if ( environment . IS_SANDBOX && environment . BASH_ENV ) {
138+ args . push (
139+ "-c" ,
140+ `shell_environment_policy.set.BASH_ENV=${ tomlBasicString ( environment . BASH_ENV ) } ` ,
141+ ) ;
142+ }
143+
133144 // Disable the user's ambient ~/.codex MCP servers so the adapter only exposes
134145 // MCP servers PostHog injects per-thread; otherwise codex fails connecting to them.
135146 for ( const name of new CodexSettingsManager (
@@ -199,7 +210,7 @@ export function spawnCodexAppServerProcess(
199210 }
200211 env . PATH = `${ dirname ( options . binaryPath ) } ${ delimiter } ${ env . PATH ?? "" } ` ;
201212
202- const args = buildAppServerArgs ( options ) ;
213+ const args = buildAppServerArgs ( options , env ) ;
203214
204215 logger . info ( "Spawning codex app-server process" , {
205216 command : options . binaryPath ,
0 commit comments