@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
|
@@ -22,6 +22,8 @@ export interface CommandsApi {
|
|
|
22
22
|
stdin?: boolean;
|
|
23
23
|
cwd?: string;
|
|
24
24
|
envs?: Record<string, string>;
|
|
25
|
+
/** OS user to run the command as. Omitted when the provider has no user configured. */
|
|
26
|
+
user?: string;
|
|
25
27
|
}): Promise<CommandsApiHandle>;
|
|
26
28
|
connect(pid: number, opts?: CommandsApiStreamOptions): Promise<CommandsApiHandle>;
|
|
27
29
|
/** Running commands only. */
|
|
@@ -68,6 +70,12 @@ export interface CommandsApiProcessManagerOptions {
|
|
|
68
70
|
env?: Record<string, string | undefined>;
|
|
69
71
|
/** Default timeout in milliseconds for commands that don't specify one. */
|
|
70
72
|
defaultTimeout?: number;
|
|
73
|
+
/**
|
|
74
|
+
* OS user every command this manager starts runs as. Providers pass the user
|
|
75
|
+
* their sandbox is configured with; leaving it unset keeps the provider's own
|
|
76
|
+
* default user.
|
|
77
|
+
*/
|
|
78
|
+
user?: string;
|
|
71
79
|
}
|
|
72
80
|
/**
|
|
73
81
|
* A process manager over E2B's envd commands API. Providers supply the
|
|
@@ -75,7 +83,9 @@ export interface CommandsApiProcessManagerOptions {
|
|
|
75
83
|
*/
|
|
76
84
|
export declare abstract class CommandsApiProcessManager<TSandbox extends MastraSandbox = MastraSandbox> extends SandboxProcessManager<TSandbox> {
|
|
77
85
|
protected readonly defaultTimeout?: number;
|
|
78
|
-
|
|
86
|
+
/** Read by {@link CommandsApiProcessHandle.kill}, which must run as the same user. */
|
|
87
|
+
readonly defaultUser?: string;
|
|
88
|
+
constructor({ defaultTimeout, user, ...options }?: CommandsApiProcessManagerOptions);
|
|
79
89
|
/** Run `fn` against the provider's current commands handle. */
|
|
80
90
|
abstract runCommands<T>(operation: CommandsApiOperation, fn: (commands: CommandsApi) => Promise<T>): Promise<T>;
|
|
81
91
|
/** Wrap a started or attached command. Providers override this to supply their own handle. */
|
package/dist/index.cjs
CHANGED
|
@@ -649,7 +649,8 @@ var CommandsApiProcessHandle = class extends _mastra_core_workspace.ProcessHandl
|
|
|
649
649
|
await (await commands.run(killDescendants(this.inner.pid), {
|
|
650
650
|
background: true,
|
|
651
651
|
stdin: false,
|
|
652
|
-
timeoutMs: KILL_DESCENDANTS_TIMEOUT_MS
|
|
652
|
+
timeoutMs: KILL_DESCENDANTS_TIMEOUT_MS,
|
|
653
|
+
...this.manager.defaultUser !== void 0 && { user: this.manager.defaultUser }
|
|
653
654
|
})).wait();
|
|
654
655
|
} catch {}
|
|
655
656
|
return commands.kill(this.inner.pid);
|
|
@@ -670,9 +671,12 @@ var CommandsApiProcessHandle = class extends _mastra_core_workspace.ProcessHandl
|
|
|
670
671
|
*/
|
|
671
672
|
var CommandsApiProcessManager = class extends _mastra_core_workspace.SandboxProcessManager {
|
|
672
673
|
defaultTimeout;
|
|
673
|
-
|
|
674
|
+
/** Read by {@link CommandsApiProcessHandle.kill}, which must run as the same user. */
|
|
675
|
+
defaultUser;
|
|
676
|
+
constructor({ defaultTimeout, user, ...options } = {}) {
|
|
674
677
|
super(options);
|
|
675
678
|
this.defaultTimeout = defaultTimeout;
|
|
679
|
+
this.defaultUser = user;
|
|
676
680
|
}
|
|
677
681
|
/** Wrap a started or attached command. Providers override this to supply their own handle. */
|
|
678
682
|
createHandle(inner, stdinMode, options) {
|
|
@@ -692,6 +696,7 @@ var CommandsApiProcessManager = class extends _mastra_core_workspace.SandboxProc
|
|
|
692
696
|
cwd: options.cwd ?? this.defaultCwd(),
|
|
693
697
|
envs,
|
|
694
698
|
timeoutMs: options.timeout ?? this.defaultTimeout,
|
|
699
|
+
...this.defaultUser !== void 0 && { user: this.defaultUser },
|
|
695
700
|
onStdout: output.onStdout,
|
|
696
701
|
onStderr: output.onStderr
|
|
697
702
|
});
|
|
@@ -830,6 +835,14 @@ function validateRegion(region) {
|
|
|
830
835
|
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").`);
|
|
831
836
|
}
|
|
832
837
|
/**
|
|
838
|
+
* Validate a mount owner before interpolating uid/gid into shell commands.
|
|
839
|
+
*/
|
|
840
|
+
function validateOwner(owner) {
|
|
841
|
+
if (owner === void 0) throw new Error("Invalid mount owner: expected an object with numeric \"uid\" and \"gid\".");
|
|
842
|
+
const { uid, gid } = owner;
|
|
843
|
+
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.`);
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
833
846
|
* Validate and normalize a mount prefix before interpolating into shell commands.
|
|
834
847
|
* Returns the normalized prefix (no leading/trailing slashes).
|
|
835
848
|
*
|
|
@@ -865,6 +878,7 @@ async function mountS3(mountPath, config, ctx) {
|
|
|
865
878
|
validateS3BucketName(config.bucket);
|
|
866
879
|
validateRegion(config.region);
|
|
867
880
|
if (config.endpoint) validateEndpoint(config.endpoint);
|
|
881
|
+
if (config.owner) validateOwner(config.owner);
|
|
868
882
|
if ((await sandbox.commands.run("which s3fs || echo \"not found\"")).stdout.includes("not found")) {
|
|
869
883
|
logger.warn(`${LOG_PREFIX} s3fs not found, attempting runtime installation...`);
|
|
870
884
|
logger.info(`${LOG_PREFIX} Tip: For faster startup, use createMountableTemplate() to pre-install s3fs in your sandbox template`);
|
|
@@ -881,7 +895,15 @@ Option 2: Customize the base template:
|
|
|
881
895
|
|
|
882
896
|
Error details: ${installResult.stderr || installResult.stdout}`);
|
|
883
897
|
}
|
|
884
|
-
|
|
898
|
+
let uid;
|
|
899
|
+
let gid;
|
|
900
|
+
if (config.owner) {
|
|
901
|
+
uid = String(config.owner.uid);
|
|
902
|
+
gid = String(config.owner.gid);
|
|
903
|
+
} else {
|
|
904
|
+
const idResult = await sandbox.commands.run("id -u && id -g");
|
|
905
|
+
[uid, gid] = idResult.stdout.trim().split("\n");
|
|
906
|
+
}
|
|
885
907
|
const hasAccessKey = !!config.accessKeyId;
|
|
886
908
|
const hasSecretKey = !!config.secretAccessKey;
|
|
887
909
|
if (hasAccessKey !== hasSecretKey) throw new Error("Both accessKeyId and secretAccessKey must be provided together.");
|
|
@@ -974,11 +996,20 @@ Error details: ${installResult.stderr || installResult.stdout}`);
|
|
|
974
996
|
async function mountGCS(mountPath, config, ctx) {
|
|
975
997
|
const { sandbox, logger } = ctx;
|
|
976
998
|
validateGCSBucketName(config.bucket);
|
|
999
|
+
if (config.owner) validateOwner(config.owner);
|
|
977
1000
|
if ((await sandbox.commands.run("which gcsfuse || echo \"not found\"")).stdout.includes("not found")) {
|
|
978
1001
|
const codename = (await sandbox.commands.run("lsb_release -cs 2>/dev/null || echo jammy")).stdout.trim() || "jammy";
|
|
979
1002
|
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 });
|
|
980
1003
|
}
|
|
981
|
-
|
|
1004
|
+
let uid;
|
|
1005
|
+
let gid;
|
|
1006
|
+
if (config.owner) {
|
|
1007
|
+
uid = String(config.owner.uid);
|
|
1008
|
+
gid = String(config.owner.gid);
|
|
1009
|
+
} else {
|
|
1010
|
+
const idResult = await sandbox.commands.run("id -u && id -g");
|
|
1011
|
+
[uid, gid] = idResult.stdout.trim().split("\n");
|
|
1012
|
+
}
|
|
982
1013
|
const uidGidFlags = uid && gid ? `--uid=${uid} --gid=${gid}` : "";
|
|
983
1014
|
const onlyDirFlag = config.prefix ? ` --only-dir=${shellQuote(validatePrefix(config.prefix))}` : "";
|
|
984
1015
|
const hasCredentials = !!config.serviceAccountKey;
|
|
@@ -1221,7 +1252,10 @@ Error details: ${verifyResult.stderr || verifyResult.stdout || installResult?.st
|
|
|
1221
1252
|
*/
|
|
1222
1253
|
var E2BProcessManager = class extends CommandsApiProcessManager {
|
|
1223
1254
|
constructor(opts = {}) {
|
|
1224
|
-
super({
|
|
1255
|
+
super({
|
|
1256
|
+
defaultTimeout: opts.defaultTimeout,
|
|
1257
|
+
user: opts.user
|
|
1258
|
+
});
|
|
1225
1259
|
}
|
|
1226
1260
|
runCommands(operation, fn) {
|
|
1227
1261
|
if (operation === "spawn") return this.sandbox.retryOnDead(() => fn(this.sandbox.e2b.commands));
|
|
@@ -1339,7 +1373,10 @@ var E2BSandbox = class E2BSandbox extends _mastra_core_workspace.MastraSandbox {
|
|
|
1339
1373
|
super({
|
|
1340
1374
|
...options,
|
|
1341
1375
|
name: "E2BSandbox",
|
|
1342
|
-
processes: new E2BProcessManager({
|
|
1376
|
+
processes: new E2BProcessManager({
|
|
1377
|
+
defaultTimeout: options.timeout ?? 3e5,
|
|
1378
|
+
user: options.user
|
|
1379
|
+
})
|
|
1343
1380
|
});
|
|
1344
1381
|
this.id = options.id ?? this.generateId();
|
|
1345
1382
|
this.timeout = options.timeout ?? 3e5;
|