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