@mastra/e2b 0.10.0-alpha.3 → 0.10.0-alpha.4

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.
@@ -26,6 +26,17 @@ import { E2BProcessManager } from './process-manager.js';
26
26
  export interface E2BSandboxOptions extends Omit<MastraSandboxOptions, 'processes'> {
27
27
  /** Unique identifier for this sandbox instance */
28
28
  id?: string;
29
+ /**
30
+ * Persisted E2B provider sandbox ID to reattach to deterministically.
31
+ *
32
+ * When set, `start()` first queries this exact sandbox and connects to it
33
+ * (resuming it if paused) instead of discovering by logical `id` metadata.
34
+ * Only a typed "sandbox gone" error (not found / killed / not running)
35
+ * falls through to the usual logical-id lookup and create ladder;
36
+ * auth, quota, rate-limit, timeout, and network errors propagate without
37
+ * creating a new sandbox.
38
+ */
39
+ sandboxId?: string;
29
40
  /**
30
41
  * Sandbox template specification.
31
42
  *
@@ -120,7 +131,7 @@ export interface E2BSandboxOptions extends Omit<MastraSandboxOptions, 'processes
120
131
  *
121
132
  * ```
122
133
  */
123
- export declare class E2BSandbox extends MastraSandbox {
134
+ export declare class E2BSandbox extends MastraSandbox<Sandbox> {
124
135
  readonly id: string;
125
136
  readonly name = "E2BSandbox";
126
137
  readonly provider = "e2b";
@@ -146,6 +157,7 @@ export declare class E2BSandbox extends MastraSandbox {
146
157
  private readonly network?;
147
158
  private readonly lifecycle;
148
159
  private readonly connectionOpts;
160
+ private readonly _preferredSandboxId?;
149
161
  private readonly _instructionsOverride?;
150
162
  private readonly _constructorOptions;
151
163
  /** Resolved template ID after building (if needed) */
@@ -164,7 +176,9 @@ export declare class E2BSandbox extends MastraSandbox {
164
176
  * independent sandboxes (e.g. one per project).
165
177
  *
166
178
  * `options.idleTimeoutMinutes` maps to the E2B sandbox `timeout` (ms);
167
- * `options.sandboxId` is ignored because E2B reconnects by logical `id`.
179
+ * `options.sandboxId` reattaches the clone to that exact E2B sandbox on
180
+ * `start()`. The parent's own preferred provider sandbox ID is never
181
+ * inherited — physical identity is per-instance.
168
182
  */
169
183
  clone(options?: SandboxCloneOptions): E2BSandbox;
170
184
  /**
@@ -191,12 +205,28 @@ export declare class E2BSandbox extends MastraSandbox {
191
205
  */
192
206
  get e2b(): Sandbox;
193
207
  /**
194
- * Start the E2B sandbox.
195
- * Handles template preparation, existing sandbox reconnection, and new sandbox creation.
208
+ * The E2B provider sandbox ID resolved after connect or create.
209
+ *
210
+ * Persist this to reattach deterministically later via the `sandboxId`
211
+ * option (or `clone({ sandboxId })`). Undefined until the sandbox has been
212
+ * started (attached) in this process.
213
+ */
214
+ get sandboxId(): string | undefined;
215
+ /**
216
+ * Acquisition primitives (base-orchestrated start): the base derives
217
+ * `outcome: 'created'` only when a brand-new sandbox VM was created;
218
+ * reconnecting (including resuming a paused sandbox) is `outcome: 'connected'`.
196
219
  *
197
- * Status management and mount processing are handled by the base class.
220
+ * `find` returns an already-connected E2B handle: `Sandbox.connect`
221
+ * resumes paused sandboxes, and its failures are deliberately swallowed
222
+ * (unusable handle → create fresh) — that forgiveness is this provider's
223
+ * policy, so it lives here rather than in `connect`. The exception is the
224
+ * `sandboxId` reattach inside {@link acquireExistingSandbox}, which is
225
+ * fail-closed: only a "sandbox gone" error falls through to discovery.
198
226
  */
199
- start(): Promise<void>;
227
+ protected find(): Promise<Sandbox | undefined>;
228
+ protected connect(existingSandbox: Sandbox): Promise<void>;
229
+ protected create(): Promise<void>;
200
230
  /**
201
231
  * Stop the E2B sandbox by pausing it (snapshot-stop).
202
232
  *
@@ -254,6 +284,24 @@ export declare class E2BSandbox extends MastraSandbox {
254
284
  * WITHOUT connecting or resuming it. Returns its list info or null.
255
285
  */
256
286
  private lookupExistingSandboxInfo;
287
+ /**
288
+ * Acquire an existing sandbox: try the preferred provider sandbox ID first
289
+ * (deterministic reattach), then fall back to logical-id metadata discovery.
290
+ */
291
+ private acquireExistingSandbox;
292
+ /**
293
+ * Deterministically reattach to a sandbox by its E2B provider ID.
294
+ *
295
+ * Fail-closed: only a typed "sandbox gone" error (not found / killed /
296
+ * not running) returns null so the caller can fall through to logical-id
297
+ * discovery or creation. Any other error (auth, quota, rate limit,
298
+ * timeout, network) propagates so a duplicate sandbox is never created.
299
+ *
300
+ * Ownership is validated before connecting: a sandbox tagged with a
301
+ * different `mastra-sandbox-id` is refused (without resuming it).
302
+ * Sandboxes without the tag (created outside Mastra) are attachable.
303
+ */
304
+ private connectToPreferredSandbox;
257
305
  /**
258
306
  * Find an existing sandbox with matching mastra-sandbox-id metadata.
259
307
  * Returns the connected sandbox if found, null otherwise.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sandbox/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EACV,WAAW,EACX,mBAAmB,EACnB,WAAW,EAEX,cAAc,EACd,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAEhC;;GAEG;AACH,KAAK,kBAAkB,GAAG,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE;IAAE,mBAAmB,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,cAAc,CAAA;CAAE,KAAK,MAAM,CAAC,CAAC;AACxH,OAAO,EAAE,aAAa,EAAwB,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAY,MAAM,KAAK,CAAC;AACxC,OAAO,KAAK,EAEV,gBAAgB,EAChB,kBAAkB,EAGnB,MAAM,KAAK,CAAC;AAEb,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAStD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAoBtD;;GAEG;AACH,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,oBAAoB,EAAE,WAAW,CAAC;IAChF,kDAAkD;IA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B;IAe5B;;;;;;;OAOG;IACG,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAiBvD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/e2b",
3
- "version": "0.10.0-alpha.3",
3
+ "version": "0.10.0-alpha.4",
4
4
  "description": "E2B cloud sandbox provider for Mastra workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -36,8 +36,8 @@
36
36
  "@internal/types-builder": "0.0.100",
37
37
  "@internal/workspace-test-utils": "0.0.69",
38
38
  "@mastra/gcs": "0.3.2",
39
- "@mastra/core": "1.62.0-alpha.8",
40
- "@mastra/s3": "0.6.1"
39
+ "@mastra/s3": "0.6.1",
40
+ "@mastra/core": "1.62.0-alpha.11"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "@mastra/core": ">=1.55.0-0 <2.0.0-0"