@meistrari/sandbox-sdk 1.5.0 → 1.5.2

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/README.md CHANGED
@@ -213,20 +213,26 @@ const result = await sandbox.runCode(`
213
213
  await sandbox.kill()
214
214
  ```
215
215
 
216
- ### Selecting a Runtime
216
+ ### Selecting a Backend
217
217
 
218
218
  ```typescript
219
- // Pick the backend that runs the sandbox. Only 'lambda-microvm' is supported
220
- // today; omitting it uses the API's default runtime.
219
+ // `agent-sandbox`, `lambda-microvm` or `e2b`; omitting it uses the
220
+ // deployment's default. Naming one is a promise: the request is served by
221
+ // that backend or it fails.
221
222
  const run = await client.createRunAndWait({
222
223
  code: 'console.log("Hello")',
223
224
  language: 'typescript',
224
- runtime: 'lambda-microvm',
225
+ provider: 'lambda-microvm',
225
226
  })
226
227
 
227
- const sandbox = await client.createSandbox({ runtime: 'lambda-microvm' })
228
+ const sandbox = await client.createSandbox({ provider: 'lambda-microvm' })
228
229
  ```
229
230
 
231
+ `runtime` is the older name for the same setting and still works — it is
232
+ resolved to `provider` before the request goes out. Naming both to different
233
+ backends is refused rather than guessed. Prefer `provider`: it is what the API
234
+ reads, what a run reports back, and what `/health` lists.
235
+
230
236
  ### Streaming Output
231
237
 
232
238
  ```typescript
@@ -327,7 +333,8 @@ interface CreateRunRequest {
327
333
  timeoutMs?: number // ms (default: 300000)
328
334
  sandboxId?: string // Use existing sandbox
329
335
  persistent?: boolean // Keep sandbox after execution
330
- runtime?: SandboxRuntime // Sandbox backend (default: API's configured runtime)
336
+ provider?: string // Sandbox backend (default: the deployment's)
337
+ runtime?: SandboxRuntime // Older name for `provider`; resolved to it
331
338
  }
332
339
 
333
340
  interface RunCodeOptions {
package/dist/index.cjs CHANGED
@@ -259,6 +259,19 @@ function assertSupportedRuntime(runtime) {
259
259
  throw new Error(`Unsupported runtime "${runtime}". Supported runtimes: ${SANDBOX_RUNTIMES.join(", ")}`);
260
260
  }
261
261
  }
262
+ function withProvider(request) {
263
+ assertSupportedRuntime(request.runtime);
264
+ if (request.runtime === void 0) {
265
+ return request;
266
+ }
267
+ if (request.provider !== void 0 && request.provider !== request.runtime) {
268
+ throw new Error(
269
+ `Conflicting backends: runtime "${request.runtime}" and provider "${request.provider}". They are the same setting; name only one.`
270
+ );
271
+ }
272
+ const { runtime, ...rest } = request;
273
+ return { ...rest, provider: runtime };
274
+ }
262
275
  class SandboxClient {
263
276
  constructor(config) {
264
277
  __publicField(this, "apiUrl");
@@ -284,10 +297,9 @@ class SandboxClient {
284
297
  }
285
298
  // === Runs ===
286
299
  async createRun(request) {
287
- assertSupportedRuntime(request.runtime);
288
300
  const response = await this.fetch("/api/runs", {
289
301
  method: "POST",
290
- body: JSON.stringify(request)
302
+ body: JSON.stringify(withProvider(request))
291
303
  });
292
304
  return new SandboxRun(this, response.data);
293
305
  }
@@ -296,7 +308,7 @@ class SandboxClient {
296
308
  return await run.waitForCompletion();
297
309
  }
298
310
  async *streamRun(request) {
299
- assertSupportedRuntime(request.runtime);
311
+ const resolved = withProvider(request);
300
312
  const url = `${this.apiUrl}/api/runs/stream`;
301
313
  const headers = new Headers();
302
314
  const authHeaders = this.auth.getHeaders();
@@ -307,7 +319,7 @@ class SandboxClient {
307
319
  const res = await fetch(url, {
308
320
  method: "POST",
309
321
  headers,
310
- body: JSON.stringify(request)
322
+ body: JSON.stringify(resolved)
311
323
  });
312
324
  if (!res.ok) {
313
325
  throw await FetchError.from(url, "POST", res);
@@ -406,10 +418,9 @@ class SandboxClient {
406
418
  }
407
419
  // === Sandboxes ===
408
420
  async createSandbox(request = {}) {
409
- assertSupportedRuntime(request.runtime);
410
421
  const response = await this.fetch("/api/sandboxes", {
411
422
  method: "POST",
412
- body: JSON.stringify(request)
423
+ body: JSON.stringify(withProvider(request))
413
424
  });
414
425
  return new Sandbox(this, response.data.sandboxId, this.auth, response.data);
415
426
  }
package/dist/index.d.cts CHANGED
@@ -58,6 +58,29 @@ interface CreateRunRequest {
58
58
  runtime?: SandboxRuntime;
59
59
  /** Backend to run on (`agent-sandbox`, `lambda-microvm`, `e2b`); the deployment's default when omitted. */
60
60
  provider?: string;
61
+ /**
62
+ * Backend to try when `provider` does not deliver. Naming it is asking for
63
+ * the swap, so it applies even when `provider` is named. Rejected on a run
64
+ * that targets an existing `sandboxId`.
65
+ */
66
+ fallback?: string;
67
+ /**
68
+ * How long getting a sandbox ready may take. `timeoutMs` is the other
69
+ * half: how long the code may then run. Either omitted leaves the
70
+ * deployment's own limit in place; exceeding either ends the run as
71
+ * `timeout`.
72
+ */
73
+ startTimeoutMs?: number;
74
+ /**
75
+ * What a blown budget does. `start` retries on the fallback and defaults
76
+ * to true — no code has executed yet, so it duplicates nothing. `session`
77
+ * runs the code a second time and defaults to false: the first attempt may
78
+ * have sent requests or written data before it hung.
79
+ */
80
+ retry?: {
81
+ start?: boolean;
82
+ session?: boolean;
83
+ };
61
84
  }
62
85
  interface CreateSandboxRequest {
63
86
  cpuSize?: number;
package/dist/index.d.mts CHANGED
@@ -58,6 +58,29 @@ interface CreateRunRequest {
58
58
  runtime?: SandboxRuntime;
59
59
  /** Backend to run on (`agent-sandbox`, `lambda-microvm`, `e2b`); the deployment's default when omitted. */
60
60
  provider?: string;
61
+ /**
62
+ * Backend to try when `provider` does not deliver. Naming it is asking for
63
+ * the swap, so it applies even when `provider` is named. Rejected on a run
64
+ * that targets an existing `sandboxId`.
65
+ */
66
+ fallback?: string;
67
+ /**
68
+ * How long getting a sandbox ready may take. `timeoutMs` is the other
69
+ * half: how long the code may then run. Either omitted leaves the
70
+ * deployment's own limit in place; exceeding either ends the run as
71
+ * `timeout`.
72
+ */
73
+ startTimeoutMs?: number;
74
+ /**
75
+ * What a blown budget does. `start` retries on the fallback and defaults
76
+ * to true — no code has executed yet, so it duplicates nothing. `session`
77
+ * runs the code a second time and defaults to false: the first attempt may
78
+ * have sent requests or written data before it hung.
79
+ */
80
+ retry?: {
81
+ start?: boolean;
82
+ session?: boolean;
83
+ };
61
84
  }
62
85
  interface CreateSandboxRequest {
63
86
  cpuSize?: number;
package/dist/index.d.ts CHANGED
@@ -58,6 +58,29 @@ interface CreateRunRequest {
58
58
  runtime?: SandboxRuntime;
59
59
  /** Backend to run on (`agent-sandbox`, `lambda-microvm`, `e2b`); the deployment's default when omitted. */
60
60
  provider?: string;
61
+ /**
62
+ * Backend to try when `provider` does not deliver. Naming it is asking for
63
+ * the swap, so it applies even when `provider` is named. Rejected on a run
64
+ * that targets an existing `sandboxId`.
65
+ */
66
+ fallback?: string;
67
+ /**
68
+ * How long getting a sandbox ready may take. `timeoutMs` is the other
69
+ * half: how long the code may then run. Either omitted leaves the
70
+ * deployment's own limit in place; exceeding either ends the run as
71
+ * `timeout`.
72
+ */
73
+ startTimeoutMs?: number;
74
+ /**
75
+ * What a blown budget does. `start` retries on the fallback and defaults
76
+ * to true — no code has executed yet, so it duplicates nothing. `session`
77
+ * runs the code a second time and defaults to false: the first attempt may
78
+ * have sent requests or written data before it hung.
79
+ */
80
+ retry?: {
81
+ start?: boolean;
82
+ session?: boolean;
83
+ };
61
84
  }
62
85
  interface CreateSandboxRequest {
63
86
  cpuSize?: number;
package/dist/index.mjs CHANGED
@@ -257,6 +257,19 @@ function assertSupportedRuntime(runtime) {
257
257
  throw new Error(`Unsupported runtime "${runtime}". Supported runtimes: ${SANDBOX_RUNTIMES.join(", ")}`);
258
258
  }
259
259
  }
260
+ function withProvider(request) {
261
+ assertSupportedRuntime(request.runtime);
262
+ if (request.runtime === void 0) {
263
+ return request;
264
+ }
265
+ if (request.provider !== void 0 && request.provider !== request.runtime) {
266
+ throw new Error(
267
+ `Conflicting backends: runtime "${request.runtime}" and provider "${request.provider}". They are the same setting; name only one.`
268
+ );
269
+ }
270
+ const { runtime, ...rest } = request;
271
+ return { ...rest, provider: runtime };
272
+ }
260
273
  class SandboxClient {
261
274
  constructor(config) {
262
275
  __publicField(this, "apiUrl");
@@ -282,10 +295,9 @@ class SandboxClient {
282
295
  }
283
296
  // === Runs ===
284
297
  async createRun(request) {
285
- assertSupportedRuntime(request.runtime);
286
298
  const response = await this.fetch("/api/runs", {
287
299
  method: "POST",
288
- body: JSON.stringify(request)
300
+ body: JSON.stringify(withProvider(request))
289
301
  });
290
302
  return new SandboxRun(this, response.data);
291
303
  }
@@ -294,7 +306,7 @@ class SandboxClient {
294
306
  return await run.waitForCompletion();
295
307
  }
296
308
  async *streamRun(request) {
297
- assertSupportedRuntime(request.runtime);
309
+ const resolved = withProvider(request);
298
310
  const url = `${this.apiUrl}/api/runs/stream`;
299
311
  const headers = new Headers();
300
312
  const authHeaders = this.auth.getHeaders();
@@ -305,7 +317,7 @@ class SandboxClient {
305
317
  const res = await fetch(url, {
306
318
  method: "POST",
307
319
  headers,
308
- body: JSON.stringify(request)
320
+ body: JSON.stringify(resolved)
309
321
  });
310
322
  if (!res.ok) {
311
323
  throw await FetchError.from(url, "POST", res);
@@ -404,10 +416,9 @@ class SandboxClient {
404
416
  }
405
417
  // === Sandboxes ===
406
418
  async createSandbox(request = {}) {
407
- assertSupportedRuntime(request.runtime);
408
419
  const response = await this.fetch("/api/sandboxes", {
409
420
  method: "POST",
410
- body: JSON.stringify(request)
421
+ body: JSON.stringify(withProvider(request))
411
422
  });
412
423
  return new Sandbox(this, response.data.sandboxId, this.auth, response.data);
413
424
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meistrari/sandbox-sdk",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -16,7 +16,8 @@
16
16
  ],
17
17
  "scripts": {
18
18
  "build": "unbuild",
19
- "test": "vitest"
19
+ "test": "bun test test",
20
+ "test:manual": "bun run test/manual/integration.ts"
20
21
  },
21
22
  "dependencies": {
22
23
  "eventsource-parser": "^3.0.0"