@meistrari/sandbox-sdk 1.2.2 → 1.3.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/README.md CHANGED
@@ -213,6 +213,20 @@ const result = await sandbox.runCode(`
213
213
  await sandbox.kill()
214
214
  ```
215
215
 
216
+ ### Selecting a Runtime
217
+
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.
221
+ const run = await client.createRunAndWait({
222
+ code: 'console.log("Hello")',
223
+ language: 'typescript',
224
+ runtime: 'lambda-microvm',
225
+ })
226
+
227
+ const sandbox = await client.createSandbox({ runtime: 'lambda-microvm' })
228
+ ```
229
+
216
230
  ### Streaming Output
217
231
 
218
232
  ```typescript
@@ -300,6 +314,8 @@ const client = sandbox({
300
314
  ```typescript
301
315
  type Status = 'pending' | 'running' | 'completed' | 'failed' | 'timeout' | 'cancelled'
302
316
 
317
+ type SandboxRuntime = 'lambda-microvm'
318
+
303
319
  interface CreateRunRequest {
304
320
  code: string
305
321
  language?: 'javascript' | 'typescript' | 'python' | 'bash'
@@ -311,6 +327,7 @@ interface CreateRunRequest {
311
327
  timeoutMs?: number // ms (default: 300000)
312
328
  sandboxId?: string // Use existing sandbox
313
329
  persistent?: boolean // Keep sandbox after execution
330
+ runtime?: SandboxRuntime // Sandbox backend (default: API's configured runtime)
314
331
  }
315
332
 
316
333
  interface RunCodeOptions {
package/dist/index.cjs CHANGED
@@ -3,6 +3,8 @@
3
3
  const node_buffer = require('node:buffer');
4
4
  const eventsourceParser = require('eventsource-parser');
5
5
 
6
+ const SANDBOX_RUNTIMES = ["lambda-microvm"];
7
+
6
8
  class FetchError extends Error {
7
9
  constructor(message, url, method, status, response) {
8
10
  super(message);
@@ -237,6 +239,11 @@ var __publicField = (obj, key, value) => {
237
239
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
238
240
  return value;
239
241
  };
242
+ function assertSupportedRuntime(runtime) {
243
+ if (runtime !== void 0 && !SANDBOX_RUNTIMES.includes(runtime)) {
244
+ throw new Error(`Unsupported runtime "${runtime}". Supported runtimes: ${SANDBOX_RUNTIMES.join(", ")}`);
245
+ }
246
+ }
240
247
  class SandboxClient {
241
248
  constructor(config) {
242
249
  __publicField(this, "apiUrl");
@@ -262,6 +269,7 @@ class SandboxClient {
262
269
  }
263
270
  // === Runs ===
264
271
  async createRun(request) {
272
+ assertSupportedRuntime(request.runtime);
265
273
  const response = await this.fetch("/api/runs", {
266
274
  method: "POST",
267
275
  body: JSON.stringify(request)
@@ -273,6 +281,7 @@ class SandboxClient {
273
281
  return await run.waitForCompletion();
274
282
  }
275
283
  async *streamRun(request) {
284
+ assertSupportedRuntime(request.runtime);
276
285
  const url = `${this.apiUrl}/api/runs/stream`;
277
286
  const headers = new Headers();
278
287
  const authHeaders = this.auth.getHeaders();
@@ -382,6 +391,7 @@ class SandboxClient {
382
391
  }
383
392
  // === Sandboxes ===
384
393
  async createSandbox(request = {}) {
394
+ assertSupportedRuntime(request.runtime);
385
395
  const response = await this.fetch("/api/sandboxes", {
386
396
  method: "POST",
387
397
  body: JSON.stringify(request)
@@ -486,6 +496,7 @@ function sandbox(config) {
486
496
 
487
497
  exports.DataTokenAuthStrategy = DataTokenAuthStrategy;
488
498
  exports.FetchError = FetchError;
499
+ exports.SANDBOX_RUNTIMES = SANDBOX_RUNTIMES;
489
500
  exports.Sandbox = Sandbox;
490
501
  exports.SandboxClient = SandboxClient;
491
502
  exports.SandboxRun = SandboxRun;
package/dist/index.d.cts CHANGED
@@ -6,6 +6,8 @@ interface SandboxConfig {
6
6
  interface AuthStrategy {
7
7
  getHeaders: () => Headers;
8
8
  }
9
+ declare const SANDBOX_RUNTIMES: readonly ["lambda-microvm"];
10
+ type SandboxRuntime = (typeof SANDBOX_RUNTIMES)[number];
9
11
  interface CreateRunRequest {
10
12
  code: string;
11
13
  language?: 'javascript' | 'typescript' | 'python' | 'bash' | 'ts' | 'js';
@@ -18,12 +20,14 @@ interface CreateRunRequest {
18
20
  sandboxId?: string;
19
21
  persistent?: boolean;
20
22
  sandboxTtlSeconds?: number;
23
+ runtime?: SandboxRuntime;
21
24
  }
22
25
  interface CreateSandboxRequest {
23
26
  cpuSize?: number;
24
27
  memSize?: number;
25
28
  sandboxTtlSeconds?: number;
26
29
  files?: FileInput[];
30
+ runtime?: SandboxRuntime;
27
31
  }
28
32
  type FileCategory = 'input' | 'skill' | 'settings' | 'context' | 'workspace' | 'output';
29
33
  interface FileInput {
@@ -132,6 +136,7 @@ declare class Sandbox {
132
136
  static create(client: SandboxClient, options?: {
133
137
  memSize?: number;
134
138
  cpuSize?: number;
139
+ runtime?: SandboxRuntime;
135
140
  files?: Array<{
136
141
  name: string;
137
142
  content: string;
@@ -209,5 +214,5 @@ declare class FetchError extends Error {
209
214
 
210
215
  declare function sandbox(config: SandboxConfig): SandboxClient;
211
216
 
212
- export { DataTokenAuthStrategy, FetchError, Sandbox, SandboxClient, SandboxRun, sandbox };
213
- export type { AuthStrategy, CreateRunRequest, CreateSandboxRequest, ExecutionResult, FileInput, RunCodeOptions, RunResponse, SandboxCommands, SandboxConfig, SandboxFiles, Status, StreamCallbacks, StreamEvent };
217
+ export { DataTokenAuthStrategy, FetchError, SANDBOX_RUNTIMES, Sandbox, SandboxClient, SandboxRun, sandbox };
218
+ export type { AuthStrategy, CreateRunRequest, CreateSandboxRequest, ExecutionResult, FileInput, RunCodeOptions, RunResponse, SandboxCommands, SandboxConfig, SandboxFiles, SandboxRuntime, Status, StreamCallbacks, StreamEvent };
package/dist/index.d.mts CHANGED
@@ -6,6 +6,8 @@ interface SandboxConfig {
6
6
  interface AuthStrategy {
7
7
  getHeaders: () => Headers;
8
8
  }
9
+ declare const SANDBOX_RUNTIMES: readonly ["lambda-microvm"];
10
+ type SandboxRuntime = (typeof SANDBOX_RUNTIMES)[number];
9
11
  interface CreateRunRequest {
10
12
  code: string;
11
13
  language?: 'javascript' | 'typescript' | 'python' | 'bash' | 'ts' | 'js';
@@ -18,12 +20,14 @@ interface CreateRunRequest {
18
20
  sandboxId?: string;
19
21
  persistent?: boolean;
20
22
  sandboxTtlSeconds?: number;
23
+ runtime?: SandboxRuntime;
21
24
  }
22
25
  interface CreateSandboxRequest {
23
26
  cpuSize?: number;
24
27
  memSize?: number;
25
28
  sandboxTtlSeconds?: number;
26
29
  files?: FileInput[];
30
+ runtime?: SandboxRuntime;
27
31
  }
28
32
  type FileCategory = 'input' | 'skill' | 'settings' | 'context' | 'workspace' | 'output';
29
33
  interface FileInput {
@@ -132,6 +136,7 @@ declare class Sandbox {
132
136
  static create(client: SandboxClient, options?: {
133
137
  memSize?: number;
134
138
  cpuSize?: number;
139
+ runtime?: SandboxRuntime;
135
140
  files?: Array<{
136
141
  name: string;
137
142
  content: string;
@@ -209,5 +214,5 @@ declare class FetchError extends Error {
209
214
 
210
215
  declare function sandbox(config: SandboxConfig): SandboxClient;
211
216
 
212
- export { DataTokenAuthStrategy, FetchError, Sandbox, SandboxClient, SandboxRun, sandbox };
213
- export type { AuthStrategy, CreateRunRequest, CreateSandboxRequest, ExecutionResult, FileInput, RunCodeOptions, RunResponse, SandboxCommands, SandboxConfig, SandboxFiles, Status, StreamCallbacks, StreamEvent };
217
+ export { DataTokenAuthStrategy, FetchError, SANDBOX_RUNTIMES, Sandbox, SandboxClient, SandboxRun, sandbox };
218
+ export type { AuthStrategy, CreateRunRequest, CreateSandboxRequest, ExecutionResult, FileInput, RunCodeOptions, RunResponse, SandboxCommands, SandboxConfig, SandboxFiles, SandboxRuntime, Status, StreamCallbacks, StreamEvent };
package/dist/index.d.ts CHANGED
@@ -6,6 +6,8 @@ interface SandboxConfig {
6
6
  interface AuthStrategy {
7
7
  getHeaders: () => Headers;
8
8
  }
9
+ declare const SANDBOX_RUNTIMES: readonly ["lambda-microvm"];
10
+ type SandboxRuntime = (typeof SANDBOX_RUNTIMES)[number];
9
11
  interface CreateRunRequest {
10
12
  code: string;
11
13
  language?: 'javascript' | 'typescript' | 'python' | 'bash' | 'ts' | 'js';
@@ -18,12 +20,14 @@ interface CreateRunRequest {
18
20
  sandboxId?: string;
19
21
  persistent?: boolean;
20
22
  sandboxTtlSeconds?: number;
23
+ runtime?: SandboxRuntime;
21
24
  }
22
25
  interface CreateSandboxRequest {
23
26
  cpuSize?: number;
24
27
  memSize?: number;
25
28
  sandboxTtlSeconds?: number;
26
29
  files?: FileInput[];
30
+ runtime?: SandboxRuntime;
27
31
  }
28
32
  type FileCategory = 'input' | 'skill' | 'settings' | 'context' | 'workspace' | 'output';
29
33
  interface FileInput {
@@ -132,6 +136,7 @@ declare class Sandbox {
132
136
  static create(client: SandboxClient, options?: {
133
137
  memSize?: number;
134
138
  cpuSize?: number;
139
+ runtime?: SandboxRuntime;
135
140
  files?: Array<{
136
141
  name: string;
137
142
  content: string;
@@ -209,5 +214,5 @@ declare class FetchError extends Error {
209
214
 
210
215
  declare function sandbox(config: SandboxConfig): SandboxClient;
211
216
 
212
- export { DataTokenAuthStrategy, FetchError, Sandbox, SandboxClient, SandboxRun, sandbox };
213
- export type { AuthStrategy, CreateRunRequest, CreateSandboxRequest, ExecutionResult, FileInput, RunCodeOptions, RunResponse, SandboxCommands, SandboxConfig, SandboxFiles, Status, StreamCallbacks, StreamEvent };
217
+ export { DataTokenAuthStrategy, FetchError, SANDBOX_RUNTIMES, Sandbox, SandboxClient, SandboxRun, sandbox };
218
+ export type { AuthStrategy, CreateRunRequest, CreateSandboxRequest, ExecutionResult, FileInput, RunCodeOptions, RunResponse, SandboxCommands, SandboxConfig, SandboxFiles, SandboxRuntime, Status, StreamCallbacks, StreamEvent };
package/dist/index.mjs CHANGED
@@ -1,6 +1,8 @@
1
1
  import { Buffer } from 'node:buffer';
2
2
  import { createParser } from 'eventsource-parser';
3
3
 
4
+ const SANDBOX_RUNTIMES = ["lambda-microvm"];
5
+
4
6
  class FetchError extends Error {
5
7
  constructor(message, url, method, status, response) {
6
8
  super(message);
@@ -235,6 +237,11 @@ var __publicField = (obj, key, value) => {
235
237
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
236
238
  return value;
237
239
  };
240
+ function assertSupportedRuntime(runtime) {
241
+ if (runtime !== void 0 && !SANDBOX_RUNTIMES.includes(runtime)) {
242
+ throw new Error(`Unsupported runtime "${runtime}". Supported runtimes: ${SANDBOX_RUNTIMES.join(", ")}`);
243
+ }
244
+ }
238
245
  class SandboxClient {
239
246
  constructor(config) {
240
247
  __publicField(this, "apiUrl");
@@ -260,6 +267,7 @@ class SandboxClient {
260
267
  }
261
268
  // === Runs ===
262
269
  async createRun(request) {
270
+ assertSupportedRuntime(request.runtime);
263
271
  const response = await this.fetch("/api/runs", {
264
272
  method: "POST",
265
273
  body: JSON.stringify(request)
@@ -271,6 +279,7 @@ class SandboxClient {
271
279
  return await run.waitForCompletion();
272
280
  }
273
281
  async *streamRun(request) {
282
+ assertSupportedRuntime(request.runtime);
274
283
  const url = `${this.apiUrl}/api/runs/stream`;
275
284
  const headers = new Headers();
276
285
  const authHeaders = this.auth.getHeaders();
@@ -380,6 +389,7 @@ class SandboxClient {
380
389
  }
381
390
  // === Sandboxes ===
382
391
  async createSandbox(request = {}) {
392
+ assertSupportedRuntime(request.runtime);
383
393
  const response = await this.fetch("/api/sandboxes", {
384
394
  method: "POST",
385
395
  body: JSON.stringify(request)
@@ -482,4 +492,4 @@ function sandbox(config) {
482
492
  return new SandboxClient(config);
483
493
  }
484
494
 
485
- export { DataTokenAuthStrategy, FetchError, Sandbox, SandboxClient, SandboxRun, sandbox };
495
+ export { DataTokenAuthStrategy, FetchError, SANDBOX_RUNTIMES, Sandbox, SandboxClient, SandboxRun, sandbox };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meistrari/sandbox-sdk",
3
- "version": "1.2.2",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {