@mastra/e2b 0.12.3-alpha.0 → 0.12.3-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -162,16 +162,42 @@ Error details: ${installResult.stderr || installResult.stdout}`);
162
162
  const hasSecretKey = !!config.secretAccessKey;
163
163
  if (hasAccessKey !== hasSecretKey) throw new Error("Both accessKeyId and secretAccessKey must be provided together.");
164
164
  const hasCredentials = hasAccessKey && hasSecretKey;
165
+ if (config.sessionToken && !hasCredentials) throw new Error("sessionToken requires accessKeyId and secretAccessKey.");
166
+ const useSessionToken = hasCredentials && !!config.sessionToken;
165
167
  const credentialsPath = `/tmp/.passwd-s3fs-${(0, crypto.createHash)("md5").update(mountPath).digest("hex").slice(0, 8)}`;
166
168
  if (!hasCredentials && config.endpoint) throw new Error(`S3-compatible storage requires credentials. Detected endpoint: ${config.endpoint}. The public_bucket option only works for AWS S3 public buckets, not R2, MinIO, etc.`);
169
+ let bucketArg = config.bucket;
170
+ if (config.prefix) {
171
+ const normalizedPrefix = validatePrefix(config.prefix);
172
+ bucketArg = `${config.bucket}:/${normalizedPrefix}`;
173
+ }
174
+ const removeSessionCredentials = async () => {
175
+ try {
176
+ await sandbox.commands.run(`sudo rm -f ${credentialsPath}`);
177
+ } catch {
178
+ logger.warn(`${LOG_PREFIX} Failed to remove S3 session credentials file`);
179
+ }
180
+ };
167
181
  if (hasCredentials) {
168
- const credentialsContent = `${config.accessKeyId}:${config.secretAccessKey}`;
182
+ const credentialsContent = useSessionToken ? [
183
+ `export AWSACCESSKEYID=${shellQuote$1(config.accessKeyId)}`,
184
+ `export AWSSECRETACCESSKEY=${shellQuote$1(config.secretAccessKey)}`,
185
+ `export AWSSESSIONTOKEN=${shellQuote$1(config.sessionToken)}`,
186
+ `export AWS_ACCESS_KEY_ID=${shellQuote$1(config.accessKeyId)}`,
187
+ `export AWS_SECRET_ACCESS_KEY=${shellQuote$1(config.secretAccessKey)}`,
188
+ `export AWS_SESSION_TOKEN=${shellQuote$1(config.sessionToken)}`
189
+ ].join("\n") : `${config.accessKeyId}:${config.secretAccessKey}`;
169
190
  await sandbox.commands.run(`sudo rm -f ${credentialsPath}`);
170
- await sandbox.files.write(credentialsPath, credentialsContent);
171
- await sandbox.commands.run(`chmod 600 ${credentialsPath}`);
191
+ try {
192
+ await sandbox.files.write(credentialsPath, credentialsContent);
193
+ await sandbox.commands.run(`chmod 600 ${credentialsPath}`);
194
+ } catch (error) {
195
+ if (useSessionToken) await removeSessionCredentials();
196
+ throw error;
197
+ }
172
198
  }
173
199
  const mountOptions = [];
174
- if (hasCredentials) mountOptions.push(`passwd_file=${credentialsPath}`);
200
+ if (hasCredentials) mountOptions.push(useSessionToken ? "use_session_token" : `passwd_file=${credentialsPath}`);
175
201
  else {
176
202
  mountOptions.push("public_bucket=1");
177
203
  logger.debug(`${LOG_PREFIX} No credentials provided, mounting as public bucket (read-only)`);
@@ -187,12 +213,8 @@ Error details: ${installResult.stderr || installResult.stdout}`);
187
213
  mountOptions.push("ro");
188
214
  logger.debug(`${LOG_PREFIX} Mounting as read-only`);
189
215
  }
190
- let bucketArg = config.bucket;
191
- if (config.prefix) {
192
- const normalizedPrefix = validatePrefix(config.prefix);
193
- bucketArg = `${config.bucket}:/${normalizedPrefix}`;
194
- }
195
- const mountCmd = `sudo s3fs ${shellQuote$1(bucketArg)} ${shellQuote$1(mountPath)} -o ${mountOptions.join(" -o ")}`;
216
+ const s3fsCmd = `s3fs ${shellQuote$1(bucketArg)} ${shellQuote$1(mountPath)} -o ${mountOptions.join(" -o ")}`;
217
+ const mountCmd = useSessionToken ? `sudo sh -c ${shellQuote$1(`. ${credentialsPath} && exec ${s3fsCmd}`)}` : `sudo ${s3fsCmd}`;
196
218
  logger.debug(`${LOG_PREFIX} Mounting S3:`, hasCredentials ? mountCmd.replace(credentialsPath, "***") : mountCmd);
197
219
  try {
198
220
  const result = await sandbox.commands.run(mountCmd, { timeoutMs: 6e4 });
@@ -212,6 +234,8 @@ Error details: ${installResult.stderr || installResult.stdout}`);
212
234
  error: String(error)
213
235
  });
214
236
  throw new Error(`Failed to mount S3 bucket: ${stderr || stdout || error}`);
237
+ } finally {
238
+ if (useSessionToken) await removeSessionCredentials();
215
239
  }
216
240
  if ((await sandbox.commands.run(`mountpoint -q ${shellQuote$1(mountPath)}`)).exitCode !== 0) throw new Error(`s3fs returned exit 0 but ${mountPath} is not a mountpoint. The s3fs daemon likely failed during FUSE init (common causes: region mismatch, invalid credentials, or an S3-compatible endpoint that rejects the signature). Re-run inside the sandbox with '-f -o dbglevel=info' to see the underlying error.`);
217
241
  }