@@ -82,6 +82,49 @@ async function loadScriptFiles(scriptPath: string): Promise<FileToWrite[]> {
8282 ] ;
8383}
8484
85+ function firstEnvValue ( ...values : Array < string | undefined > ) : string | undefined {
86+ return values . find ( ( value ) => value && value . trim ( ) !== '' ) ;
87+ }
88+
89+ function firstReusableCredential ( ...values : Array < string | undefined > ) : string | undefined {
90+ return values . find ( ( value ) => value && value . trim ( ) !== '' && ! value . trim ( ) . startsWith ( 'ags-' ) ) ;
91+ }
92+
93+ function objectStorageEnv ( ) : Record < string , string > | undefined {
94+ const bucket = firstEnvValue ( process . env . S3_BUCKET , process . env . AWS_BUCKET ) ;
95+ const endpoint = firstEnvValue ( process . env . S3_ENDPOINT , process . env . AWS_ENDPOINT ) ;
96+ const accessKeyId = firstReusableCredential (
97+ process . env . S3_ACCESS_KEY_ID ,
98+ process . env . AWS_ACCESS_KEY_ID
99+ ) ;
100+ const secretAccessKey = firstReusableCredential (
101+ process . env . S3_SECRET_ACCESS_KEY ,
102+ process . env . AWS_SECRET_ACCESS_KEY
103+ ) ;
104+
105+ if ( ! bucket || ! endpoint || ! accessKeyId || ! secretAccessKey ) return undefined ;
106+
107+ const storageEnv : Record < string , string > = {
108+ S3_BUCKET : bucket ,
109+ S3_ENDPOINT : endpoint ,
110+ S3_ACCESS_KEY_ID : accessKeyId ,
111+ S3_SECRET_ACCESS_KEY : secretAccessKey ,
112+ } ;
113+ const region = firstEnvValue ( process . env . S3_REGION , process . env . AWS_REGION ) ;
114+ if ( region ) storageEnv . S3_REGION = region ;
115+
116+ return storageEnv ;
117+ }
118+
119+ function copyObjectStorageEnv ( envVars : Record < string , string > ) : void {
120+ const storageEnv = objectStorageEnv ( ) ;
121+ if ( ! storageEnv ) return ;
122+
123+ for ( const [ key , value ] of Object . entries ( storageEnv ) ) {
124+ envVars [ key ] = value ;
125+ }
126+ }
127+
85128interface SandboxExecutionResult {
86129 readonly exitCode : number ;
87130 readonly error ?: string ;
@@ -230,23 +273,6 @@ const router = new Hono<ApiEnv>().get(
230273 envVars . AGENTUITY_CLOUD_DEPLOYMENT_ID = process . env . AGENTUITY_CLOUD_DEPLOYMENT_ID ;
231274 if ( process . env . DATABASE_URL ) envVars . DATABASE_URL = process . env . DATABASE_URL ;
232275
233- const storageEnv = {
234- AWS_BUCKET : process . env . AWS_BUCKET ?? process . env . S3_BUCKET ,
235- AWS_ENDPOINT : process . env . AWS_ENDPOINT ?? process . env . S3_ENDPOINT ,
236- AWS_ACCESS_KEY_ID : process . env . AWS_ACCESS_KEY_ID ?? process . env . S3_ACCESS_KEY_ID ,
237- AWS_SECRET_ACCESS_KEY :
238- process . env . AWS_SECRET_ACCESS_KEY ?? process . env . S3_SECRET_ACCESS_KEY ,
239- AWS_REGION : process . env . AWS_REGION ?? process . env . S3_REGION ,
240- S3_BUCKET : process . env . S3_BUCKET ,
241- S3_ENDPOINT : process . env . S3_ENDPOINT ,
242- S3_ACCESS_KEY_ID : process . env . S3_ACCESS_KEY_ID ,
243- S3_SECRET_ACCESS_KEY : process . env . S3_SECRET_ACCESS_KEY ,
244- S3_REGION : process . env . S3_REGION ,
245- } ;
246- for ( const [ key , value ] of Object . entries ( storageEnv ) ) {
247- if ( value ) envVars [ key ] = value ;
248- }
249-
250276 const scriptPath = `dist/run/${ scriptName } .js` ;
251277 const command = [ 'bun' , 'run' , scriptPath , JSON . stringify ( input ) ] ;
252278 let scriptFiles : FileToWrite [ ] ;
@@ -258,8 +284,14 @@ const router = new Hono<ApiEnv>().get(
258284 await stream . writeSSE ( { event : 'error' , data : message } ) ;
259285 return ;
260286 }
261- // Sandbox env is fixed at creation, so a reused session sandbox can predate
262- // the linked-bucket AWS_* env (e.g. storage linked after the session began).
287+
288+ if ( scriptName === 'objectstore' ) {
289+ // Some deployment-provided AWS_* values are scoped to the parent runtime
290+ // and cannot be reused inside a child sandbox. Forward only reusable
291+ // S3_* credentials for the object-storage demo.
292+ copyObjectStorageEnv ( envVars ) ;
293+ }
294+
263295 // Always run the object storage script one-shot so it sees current env.
264296 const useInteractiveSandbox = scriptName !== 'objectstore' ;
265297
0 commit comments