@mastra/e2b 0.10.0-alpha.4 → 0.10.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/CHANGELOG.md +53 -0
- package/dist/index.cjs +39 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +39 -22
- package/dist/index.js.map +1 -1
- package/dist/sandbox/index.d.ts +28 -9
- package/dist/sandbox/index.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -776,17 +776,19 @@ var E2BSandbox = class E2BSandbox extends MastraSandbox {
|
|
|
776
776
|
resolvedTemplateId = await this.resolveTemplate();
|
|
777
777
|
}
|
|
778
778
|
this.logger.debug(`${LOG_PREFIX} Creating new sandbox for: ${this.id} with template: ${resolvedTemplateId}`);
|
|
779
|
+
const createOpts = {
|
|
780
|
+
...this.connectionOpts,
|
|
781
|
+
lifecycle: this.lifecycle,
|
|
782
|
+
metadata: {
|
|
783
|
+
...this.metadata,
|
|
784
|
+
"mastra-sandbox-id": this.id
|
|
785
|
+
},
|
|
786
|
+
...this.network && { network: this.network },
|
|
787
|
+
timeoutMs: this.timeout
|
|
788
|
+
};
|
|
789
|
+
let sdkSandbox;
|
|
779
790
|
try {
|
|
780
|
-
|
|
781
|
-
...this.connectionOpts,
|
|
782
|
-
lifecycle: this.lifecycle,
|
|
783
|
-
metadata: {
|
|
784
|
-
...this.metadata,
|
|
785
|
-
"mastra-sandbox-id": this.id
|
|
786
|
-
},
|
|
787
|
-
...this.network && { network: this.network },
|
|
788
|
-
timeoutMs: this.timeout
|
|
789
|
-
});
|
|
791
|
+
sdkSandbox = await this.createSdkSandbox(resolvedTemplateId, createOpts);
|
|
790
792
|
} catch (createError) {
|
|
791
793
|
const errorStr = String(createError);
|
|
792
794
|
if (errorStr.includes("404") && errorStr.includes("not found") && !this.templateSpec) {
|
|
@@ -794,19 +796,11 @@ var E2BSandbox = class E2BSandbox extends MastraSandbox {
|
|
|
794
796
|
this._resolvedTemplateId = void 0;
|
|
795
797
|
const rebuiltTemplateId = await this.buildDefaultTemplate();
|
|
796
798
|
this.logger.debug(`${LOG_PREFIX} Retrying sandbox creation with rebuilt template: ${rebuiltTemplateId}`);
|
|
797
|
-
|
|
798
|
-
...this.connectionOpts,
|
|
799
|
-
lifecycle: this.lifecycle,
|
|
800
|
-
metadata: {
|
|
801
|
-
...this.metadata,
|
|
802
|
-
"mastra-sandbox-id": this.id
|
|
803
|
-
},
|
|
804
|
-
...this.network && { network: this.network },
|
|
805
|
-
timeoutMs: this.timeout
|
|
806
|
-
});
|
|
799
|
+
sdkSandbox = await this.createSdkSandbox(rebuiltTemplateId, createOpts);
|
|
807
800
|
} else throw createError;
|
|
808
801
|
}
|
|
809
|
-
this.
|
|
802
|
+
this._sandbox = sdkSandbox;
|
|
803
|
+
this.logger.debug(`${LOG_PREFIX} Created sandbox ${sdkSandbox.sandboxId} for logical ID: ${this.id}`);
|
|
810
804
|
this._createdAt = /* @__PURE__ */ new Date();
|
|
811
805
|
}
|
|
812
806
|
/**
|
|
@@ -1206,19 +1200,39 @@ var E2BSandbox = class E2BSandbox extends MastraSandbox {
|
|
|
1206
1200
|
const info = await this.lookupExistingSandboxInfo();
|
|
1207
1201
|
if (!info) return null;
|
|
1208
1202
|
try {
|
|
1209
|
-
return await
|
|
1203
|
+
return await this.connectSdkSandbox(info.sandboxId, this.connectionOpts);
|
|
1210
1204
|
} catch (e) {
|
|
1211
1205
|
this.logger.debug(`${LOG_PREFIX} Error connecting to existing sandbox:`, e);
|
|
1212
1206
|
return null;
|
|
1213
1207
|
}
|
|
1214
1208
|
}
|
|
1215
1209
|
/**
|
|
1210
|
+
* Create a new SDK sandbox from a resolved template ID.
|
|
1211
|
+
*
|
|
1212
|
+
* Override point for providers layered on the E2B SDK whose `Sandbox`
|
|
1213
|
+
* class extends `e2b`'s (e.g. `@e2b/desktop`): override to call their
|
|
1214
|
+
* `Sandbox.create`. Connection options are already spread into `opts`.
|
|
1215
|
+
*/
|
|
1216
|
+
async createSdkSandbox(templateId, opts) {
|
|
1217
|
+
return Sandbox.create(templateId, opts);
|
|
1218
|
+
}
|
|
1219
|
+
/**
|
|
1220
|
+
* Connect to (and resume) an existing SDK sandbox by its E2B sandbox ID.
|
|
1221
|
+
* Override point — see {@link createSdkSandbox}.
|
|
1222
|
+
*/
|
|
1223
|
+
async connectSdkSandbox(sandboxId, opts) {
|
|
1224
|
+
return Sandbox.connect(sandboxId, opts);
|
|
1225
|
+
}
|
|
1226
|
+
/**
|
|
1216
1227
|
* Resolve the template specification to a template ID.
|
|
1217
1228
|
*
|
|
1218
1229
|
* - String: Use as-is (template ID)
|
|
1219
1230
|
* - TemplateBuilder: Build and return the template ID
|
|
1220
1231
|
* - Function: Apply to base mountable template, then build
|
|
1221
1232
|
* - undefined: Use default mountable template (cached)
|
|
1233
|
+
*
|
|
1234
|
+
* Override point: subclasses with a different default template (e.g.
|
|
1235
|
+
* desktop sandboxes) override this and {@link buildDefaultTemplate}.
|
|
1222
1236
|
*/
|
|
1223
1237
|
async resolveTemplate() {
|
|
1224
1238
|
if (this._resolvedTemplateId) return this._resolvedTemplateId;
|
|
@@ -1257,6 +1271,9 @@ var E2BSandbox = class E2BSandbox extends MastraSandbox {
|
|
|
1257
1271
|
}
|
|
1258
1272
|
/**
|
|
1259
1273
|
* Build the default mountable template (bypasses exists check).
|
|
1274
|
+
*
|
|
1275
|
+
* Override point: called from the template-not-found retry path in
|
|
1276
|
+
* `start()` when no explicit template was configured.
|
|
1260
1277
|
*/
|
|
1261
1278
|
async buildDefaultTemplate() {
|
|
1262
1279
|
const { template, id } = createDefaultMountableTemplate();
|