@mastra/e2b 0.17.0 → 0.18.0-alpha.0
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/_types/@internal_workspace@0.0.21/dist/commands-api-process-manager.d.ts +11 -1
- package/dist/index.cjs +43 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +43 -6
- package/dist/index.js.map +1 -1
- package/dist/sandbox/index.d.ts +11 -0
- package/dist/sandbox/index.d.ts.map +1 -1
- package/dist/sandbox/mounts/gcs.d.ts +6 -1
- package/dist/sandbox/mounts/gcs.d.ts.map +1 -1
- package/dist/sandbox/mounts/s3.d.ts +6 -1
- package/dist/sandbox/mounts/s3.d.ts.map +1 -1
- package/dist/sandbox/mounts/types.d.ts +15 -0
- package/dist/sandbox/mounts/types.d.ts.map +1 -1
- package/dist/sandbox/process-manager.d.ts +2 -0
- package/dist/sandbox/process-manager.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { E2BSandboxFilesystem } from './sandbox/filesystem.js';
|
|
|
3
3
|
export { E2BProcessManager } from './sandbox/process-manager.js';
|
|
4
4
|
export { createDefaultMountableTemplate, isNamedTemplateSpec, isDeferredNamedTemplateSpec, DEFAULT_NODE_VERSION, type TemplateSpec, type NamedTemplateSpec, type DeferredNamedTemplateSpec, type MountableTemplateResult, type MountableTemplateOptions, } from './utils/template.js';
|
|
5
5
|
export { createRepoTemplate, refreshRepoTemplate, repoTemplateRef, type RepoTemplateOptions, type RepoTemplateRepository, type RepoTemplateIdentity, type RepositoryAccess, type RefreshRepoTemplateResult, } from './utils/repo-template.js';
|
|
6
|
-
export { type E2BS3MountConfig, type E2BGCSMountConfig, type E2BAzureBlobMountConfig, type E2BMountConfig, } from './sandbox/mounts/index.js';
|
|
6
|
+
export { type E2BS3MountConfig, type E2BGCSMountConfig, type E2BAzureBlobMountConfig, type E2BMountConfig, type MountOwner, } from './sandbox/mounts/index.js';
|
|
7
7
|
export { e2bSandboxProvider } from './provider.js';
|
|
8
8
|
export { E2BFactorySandbox, type E2BFactorySandboxOptions, type E2BFactorySandboxSettings } from './factory-sandbox.js';
|
|
9
9
|
export { E2BCodeModeTransport } from './code-mode/transport.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EACL,8BAA8B,EAC9B,mBAAmB,EACnB,2BAA2B,EAC3B,oBAAoB,EACpB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,GAC9B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,yBAAyB,GAC/B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,uBAAuB,EAC5B,KAAK,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EACL,8BAA8B,EAC9B,mBAAmB,EACnB,2BAA2B,EAC3B,oBAAoB,EACpB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,GAC9B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,yBAAyB,GAC/B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,uBAAuB,EAC5B,KAAK,cAAc,EACnB,KAAK,UAAU,GAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,KAAK,wBAAwB,EAAE,KAAK,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AACrH,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -648,7 +648,8 @@ var CommandsApiProcessHandle = class extends ProcessHandle {
|
|
|
648
648
|
await (await commands.run(killDescendants(this.inner.pid), {
|
|
649
649
|
background: true,
|
|
650
650
|
stdin: false,
|
|
651
|
-
timeoutMs: KILL_DESCENDANTS_TIMEOUT_MS
|
|
651
|
+
timeoutMs: KILL_DESCENDANTS_TIMEOUT_MS,
|
|
652
|
+
...this.manager.defaultUser !== void 0 && { user: this.manager.defaultUser }
|
|
652
653
|
})).wait();
|
|
653
654
|
} catch {}
|
|
654
655
|
return commands.kill(this.inner.pid);
|
|
@@ -669,9 +670,12 @@ var CommandsApiProcessHandle = class extends ProcessHandle {
|
|
|
669
670
|
*/
|
|
670
671
|
var CommandsApiProcessManager = class extends SandboxProcessManager {
|
|
671
672
|
defaultTimeout;
|
|
672
|
-
|
|
673
|
+
/** Read by {@link CommandsApiProcessHandle.kill}, which must run as the same user. */
|
|
674
|
+
defaultUser;
|
|
675
|
+
constructor({ defaultTimeout, user, ...options } = {}) {
|
|
673
676
|
super(options);
|
|
674
677
|
this.defaultTimeout = defaultTimeout;
|
|
678
|
+
this.defaultUser = user;
|
|
675
679
|
}
|
|
676
680
|
/** Wrap a started or attached command. Providers override this to supply their own handle. */
|
|
677
681
|
createHandle(inner, stdinMode, options) {
|
|
@@ -691,6 +695,7 @@ var CommandsApiProcessManager = class extends SandboxProcessManager {
|
|
|
691
695
|
cwd: options.cwd ?? this.defaultCwd(),
|
|
692
696
|
envs,
|
|
693
697
|
timeoutMs: options.timeout ?? this.defaultTimeout,
|
|
698
|
+
...this.defaultUser !== void 0 && { user: this.defaultUser },
|
|
694
699
|
onStdout: output.onStdout,
|
|
695
700
|
onStderr: output.onStderr
|
|
696
701
|
});
|
|
@@ -829,6 +834,14 @@ function validateRegion(region) {
|
|
|
829
834
|
if (typeof region !== "string" || !SAFE_REGION.test(region)) throw new Error(`Invalid region: ${JSON.stringify(region)}. Region must be a string of lowercase alphanumeric or hyphens (e.g., "us-east-1", "ap-northeast-1", "auto").`);
|
|
830
835
|
}
|
|
831
836
|
/**
|
|
837
|
+
* Validate a mount owner before interpolating uid/gid into shell commands.
|
|
838
|
+
*/
|
|
839
|
+
function validateOwner(owner) {
|
|
840
|
+
if (owner === void 0) throw new Error("Invalid mount owner: expected an object with numeric \"uid\" and \"gid\".");
|
|
841
|
+
const { uid, gid } = owner;
|
|
842
|
+
if (!Number.isInteger(uid) || uid < 0 || !Number.isInteger(gid) || gid < 0) throw new Error(`Invalid mount owner: ${JSON.stringify(owner)}. "uid" and "gid" must both be non-negative integers.`);
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
832
845
|
* Validate and normalize a mount prefix before interpolating into shell commands.
|
|
833
846
|
* Returns the normalized prefix (no leading/trailing slashes).
|
|
834
847
|
*
|
|
@@ -864,6 +877,7 @@ async function mountS3(mountPath, config, ctx) {
|
|
|
864
877
|
validateS3BucketName(config.bucket);
|
|
865
878
|
validateRegion(config.region);
|
|
866
879
|
if (config.endpoint) validateEndpoint(config.endpoint);
|
|
880
|
+
if (config.owner) validateOwner(config.owner);
|
|
867
881
|
if ((await sandbox.commands.run("which s3fs || echo \"not found\"")).stdout.includes("not found")) {
|
|
868
882
|
logger.warn(`${LOG_PREFIX} s3fs not found, attempting runtime installation...`);
|
|
869
883
|
logger.info(`${LOG_PREFIX} Tip: For faster startup, use createMountableTemplate() to pre-install s3fs in your sandbox template`);
|
|
@@ -880,7 +894,15 @@ Option 2: Customize the base template:
|
|
|
880
894
|
|
|
881
895
|
Error details: ${installResult.stderr || installResult.stdout}`);
|
|
882
896
|
}
|
|
883
|
-
|
|
897
|
+
let uid;
|
|
898
|
+
let gid;
|
|
899
|
+
if (config.owner) {
|
|
900
|
+
uid = String(config.owner.uid);
|
|
901
|
+
gid = String(config.owner.gid);
|
|
902
|
+
} else {
|
|
903
|
+
const idResult = await sandbox.commands.run("id -u && id -g");
|
|
904
|
+
[uid, gid] = idResult.stdout.trim().split("\n");
|
|
905
|
+
}
|
|
884
906
|
const hasAccessKey = !!config.accessKeyId;
|
|
885
907
|
const hasSecretKey = !!config.secretAccessKey;
|
|
886
908
|
if (hasAccessKey !== hasSecretKey) throw new Error("Both accessKeyId and secretAccessKey must be provided together.");
|
|
@@ -973,11 +995,20 @@ Error details: ${installResult.stderr || installResult.stdout}`);
|
|
|
973
995
|
async function mountGCS(mountPath, config, ctx) {
|
|
974
996
|
const { sandbox, logger } = ctx;
|
|
975
997
|
validateGCSBucketName(config.bucket);
|
|
998
|
+
if (config.owner) validateOwner(config.owner);
|
|
976
999
|
if ((await sandbox.commands.run("which gcsfuse || echo \"not found\"")).stdout.includes("not found")) {
|
|
977
1000
|
const codename = (await sandbox.commands.run("lsb_release -cs 2>/dev/null || echo jammy")).stdout.trim() || "jammy";
|
|
978
1001
|
await sandbox.commands.run(`curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/gcsfuse.gpg && echo "deb [signed-by=/etc/apt/keyrings/gcsfuse.gpg] https://packages.cloud.google.com/apt gcsfuse-${codename} main" | sudo tee /etc/apt/sources.list.d/gcsfuse.list && sudo apt-get update && sudo apt-get install -y gcsfuse`, { timeoutMs: 12e4 });
|
|
979
1002
|
}
|
|
980
|
-
|
|
1003
|
+
let uid;
|
|
1004
|
+
let gid;
|
|
1005
|
+
if (config.owner) {
|
|
1006
|
+
uid = String(config.owner.uid);
|
|
1007
|
+
gid = String(config.owner.gid);
|
|
1008
|
+
} else {
|
|
1009
|
+
const idResult = await sandbox.commands.run("id -u && id -g");
|
|
1010
|
+
[uid, gid] = idResult.stdout.trim().split("\n");
|
|
1011
|
+
}
|
|
981
1012
|
const uidGidFlags = uid && gid ? `--uid=${uid} --gid=${gid}` : "";
|
|
982
1013
|
const onlyDirFlag = config.prefix ? ` --only-dir=${shellQuote(validatePrefix(config.prefix))}` : "";
|
|
983
1014
|
const hasCredentials = !!config.serviceAccountKey;
|
|
@@ -1220,7 +1251,10 @@ Error details: ${verifyResult.stderr || verifyResult.stdout || installResult?.st
|
|
|
1220
1251
|
*/
|
|
1221
1252
|
var E2BProcessManager = class extends CommandsApiProcessManager {
|
|
1222
1253
|
constructor(opts = {}) {
|
|
1223
|
-
super({
|
|
1254
|
+
super({
|
|
1255
|
+
defaultTimeout: opts.defaultTimeout,
|
|
1256
|
+
user: opts.user
|
|
1257
|
+
});
|
|
1224
1258
|
}
|
|
1225
1259
|
runCommands(operation, fn) {
|
|
1226
1260
|
if (operation === "spawn") return this.sandbox.retryOnDead(() => fn(this.sandbox.e2b.commands));
|
|
@@ -1338,7 +1372,10 @@ var E2BSandbox = class E2BSandbox extends MastraSandbox {
|
|
|
1338
1372
|
super({
|
|
1339
1373
|
...options,
|
|
1340
1374
|
name: "E2BSandbox",
|
|
1341
|
-
processes: new E2BProcessManager({
|
|
1375
|
+
processes: new E2BProcessManager({
|
|
1376
|
+
defaultTimeout: options.timeout ?? 3e5,
|
|
1377
|
+
user: options.user
|
|
1378
|
+
})
|
|
1342
1379
|
});
|
|
1343
1380
|
this.id = options.id ?? this.generateId();
|
|
1344
1381
|
this.timeout = options.timeout ?? 3e5;
|