@sandboxrouter/sdk 0.12.0 → 0.14.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.
Files changed (53) hide show
  1. package/README.md +13 -8
  2. package/dist/agent-bench.d.ts +12 -1
  3. package/dist/agent-bench.js +46 -7
  4. package/dist/bench.d.ts +13 -1
  5. package/dist/bench.js +39 -17
  6. package/dist/billing.js +0 -1
  7. package/dist/burst.d.ts +10 -0
  8. package/dist/burst.js +21 -10
  9. package/dist/catalog.d.ts +13 -0
  10. package/dist/catalog.js +34 -16
  11. package/dist/cli.js +47 -37
  12. package/dist/client.d.ts +6 -1
  13. package/dist/client.js +19 -0
  14. package/dist/computers.d.ts +2 -2
  15. package/dist/cost.d.ts +44 -5
  16. package/dist/cost.js +54 -24
  17. package/dist/leaderboard.d.ts +30 -8
  18. package/dist/leaderboard.js +89 -50
  19. package/dist/price-index.d.ts +3 -3
  20. package/dist/price-index.js +3 -3
  21. package/dist/providers/blaxel.d.ts +1 -0
  22. package/dist/providers/blaxel.js +56 -1
  23. package/dist/providers/daytona.js +33 -1
  24. package/dist/providers/deno.d.ts +3 -0
  25. package/dist/providers/deno.js +14 -0
  26. package/dist/providers/docker.d.ts +1 -0
  27. package/dist/providers/docker.js +30 -3
  28. package/dist/providers/e2b.d.ts +22 -1
  29. package/dist/providers/e2b.js +50 -3
  30. package/dist/providers/hopx.js +12 -0
  31. package/dist/providers/limrun.d.ts +1 -8
  32. package/dist/providers/limrun.js +0 -1
  33. package/dist/providers/mobilerun.d.ts +1 -5
  34. package/dist/providers/mobilerun.js +18 -26
  35. package/dist/providers/modal.js +7 -0
  36. package/dist/providers/novita.js +5 -5
  37. package/dist/providers/sail.js +4 -4
  38. package/dist/providers/vercel.js +41 -3
  39. package/dist/published.js +639 -1283
  40. package/dist/recommend.d.ts +17 -0
  41. package/dist/recommend.js +17 -11
  42. package/dist/results.d.ts +2 -2
  43. package/dist/results.js +104 -3
  44. package/dist/router.d.ts +22 -8
  45. package/dist/router.js +58 -11
  46. package/dist/server.d.ts +4 -1
  47. package/dist/server.js +101 -7
  48. package/dist/task.d.ts +2 -1
  49. package/dist/task.js +38 -19
  50. package/dist/types.d.ts +20 -4
  51. package/dist/validate.d.ts +4 -2
  52. package/dist/validate.js +18 -1
  53. package/package.json +18 -3
@@ -57,21 +57,14 @@ export declare class LimrunProvider implements ComputerProvider {
57
57
  baseURL?: string;
58
58
  });
59
59
  configured(): boolean;
60
- /** @internal */
61
- client(): Promise<{
62
- mod: LimrunModule;
63
- lim: LimrunClient;
64
- }>;
60
+ private client;
65
61
  createComputer(spec: ComputerSpec): Promise<ProviderComputer>;
66
62
  /** Limrun ids don't say which platform they belong to, so try Android, then iOS. */
67
63
  connectComputer(nativeId: string): Promise<ProviderComputer>;
68
64
  }
69
- type LimrunModule = typeof import("@limrun/api");
70
- type LimrunClient = InstanceType<LimrunModule["Limrun"]>;
71
65
  /** @internal "ctrl+Return" on android -> { key: "ENTER", modifiers: ["ctrl"] }. Throws if unavailable. */
72
66
  export declare function limrunKey(chord: string, os: "android" | "ios"): {
73
67
  key: string;
74
68
  modifiers: string[];
75
69
  button?: string;
76
70
  };
77
- export {};
@@ -60,7 +60,6 @@ export class LimrunProvider {
60
60
  configured() {
61
61
  return !!this.apiKey;
62
62
  }
63
- /** @internal */
64
63
  client() {
65
64
  if (!this.apiKey)
66
65
  return Promise.reject(err("LIM_API_KEY is not set"));
@@ -1,6 +1,4 @@
1
1
  import type { ComputerOs, ComputerProvider, ComputerSpec, ProviderComputer } from "../computers.js";
2
- type MobilerunModule = typeof import("@mobilerun/sdk");
3
- type MobilerunClient = InstanceType<MobilerunModule["Mobilerun"]>;
4
2
  /**
5
3
  * Mobilerun (droidrun) cloud Android phones via `@mobilerun/sdk`. Desktop-only: no sandboxes.
6
4
  *
@@ -25,8 +23,7 @@ export declare class MobilerunProvider implements ComputerProvider {
25
23
  /** The SDK reads MOBILERUN_CLOUD_API_KEY itself; we read it too so configured() is honest. */
26
24
  constructor(apiKey?: string | undefined, baseURL?: string | undefined);
27
25
  configured(): boolean;
28
- /** @internal */
29
- sdk(): Promise<MobilerunClient>;
26
+ private sdk;
30
27
  createComputer(spec: ComputerSpec): Promise<ProviderComputer>;
31
28
  /** Re-attach by device id. A parked (stopped) phone is resumed and waited on. */
32
29
  connectComputer(nativeId: string): Promise<ProviderComputer>;
@@ -41,4 +38,3 @@ export declare class MobilerunProvider implements ComputerProvider {
41
38
  export declare const MOBILERUN_KEYS: Record<string, number>;
42
39
  /** One xdotool key name (no modifiers) to an Android key code. */
43
40
  export declare function mobilerunKey(name: string): number;
44
- export {};
@@ -35,7 +35,6 @@ export class MobilerunProvider {
35
35
  configured() {
36
36
  return !!this.apiKey;
37
37
  }
38
- /** @internal */
39
38
  async sdk() {
40
39
  if (!this.apiKey)
41
40
  throw new ProviderError(ID, "MOBILERUN_CLOUD_API_KEY is not set");
@@ -58,12 +57,12 @@ export class MobilerunProvider {
58
57
  if (mine) {
59
58
  if (mine.state === "stopped")
60
59
  await guard(client.devices.resume(mine.id));
61
- return new MobilerunComputer(this, await waitReady(client, mine.id));
60
+ return new MobilerunComputer(client, await waitReady(client, mine.id));
62
61
  }
63
62
  }
64
63
  const created = await guard(client.devices.create({ deviceType: "android_cloud_phone", billing: "auto", ...(name ? { name } : {}) }));
65
64
  const ready = created.state === "ready" ? created : await waitReady(client, created.id);
66
- return new MobilerunComputer(this, ready);
65
+ return new MobilerunComputer(client, ready);
67
66
  }
68
67
  /** Re-attach by device id. A parked (stopped) phone is resumed and waited on. */
69
68
  async connectComputer(nativeId) {
@@ -73,7 +72,7 @@ export class MobilerunProvider {
73
72
  throw new ProviderError(ID, `device ${nativeId} is terminated`, 404);
74
73
  if (d.state === "stopped")
75
74
  await guard(client.devices.resume(nativeId));
76
- return new MobilerunComputer(this, d.state === "ready" ? d : await waitReady(client, nativeId));
75
+ return new MobilerunComputer(client, d.state === "ready" ? d : await waitReady(client, nativeId));
77
76
  }
78
77
  }
79
78
  /**
@@ -203,19 +202,16 @@ async function bytesOf(p) {
203
202
  }
204
203
  /** Gestures take the canonical frame (the last screenshot), which is the phone's native pixels. */
205
204
  class MobilerunComputer {
206
- p;
205
+ client;
207
206
  nativeId;
208
207
  frame = 0;
209
208
  size;
210
- constructor(p, device) {
211
- this.p = p;
209
+ constructor(client, device) {
210
+ this.client = client;
212
211
  this.nativeId = device.id;
213
212
  }
214
- sdk() {
215
- return this.p.sdk();
216
- }
217
213
  async info() {
218
- const d = await guard((await this.sdk()).devices.retrieve(this.nativeId));
214
+ const d = await guard(this.client.devices.retrieve(this.nativeId));
219
215
  const status = d.state === "ready" ? "ready" : d.state === "stopped" ? "sleeping" : d.state === "terminated" ? "deleted" : d.state;
220
216
  const info = {
221
217
  id: d.id,
@@ -250,8 +246,7 @@ class MobilerunComputer {
250
246
  return out;
251
247
  }
252
248
  async capture() {
253
- const client = await this.sdk();
254
- const png = await bytesOf(client.devices.screenshots.capture(this.nativeId, {}, { headers: { "Accept-Encoding": "identity" } }));
249
+ const png = await bytesOf(this.client.devices.screenshots.capture(this.nativeId, {}, { headers: { "Accept-Encoding": "identity" } }));
255
250
  if (!png.length)
256
251
  throw new Error("screenshot came back empty");
257
252
  const s = pngSize(png);
@@ -271,7 +266,6 @@ class MobilerunComputer {
271
266
  return this.size;
272
267
  }
273
268
  async perform(a) {
274
- const client = await this.sdk();
275
269
  const id = this.nativeId;
276
270
  switch (a.action) {
277
271
  case "screenshot":
@@ -282,7 +276,7 @@ class MobilerunComputer {
282
276
  if (a.modifier)
283
277
  throw new Error("mobilerun taps can't hold modifier keys");
284
278
  const [x, y] = a.coordinate;
285
- await client.devices.actions.tap(id, { x: Math.round(x), y: Math.round(y) });
279
+ await this.client.devices.actions.tap(id, { x: Math.round(x), y: Math.round(y) });
286
280
  return {};
287
281
  }
288
282
  case "left_click_drag": {
@@ -290,7 +284,7 @@ class MobilerunComputer {
290
284
  throw new Error("left_click_drag needs startCoordinate and coordinate (a phone has no cursor)");
291
285
  const [sx, sy] = a.startCoordinate;
292
286
  const [ex, ey] = a.coordinate;
293
- await client.devices.actions.swipe(id, { startX: Math.round(sx), startY: Math.round(sy), endX: Math.round(ex), endY: Math.round(ey), duration: 600 });
287
+ await this.client.devices.actions.swipe(id, { startX: Math.round(sx), startY: Math.round(sy), endX: Math.round(ex), endY: Math.round(ey), duration: 600 });
294
288
  return {};
295
289
  }
296
290
  case "scroll": {
@@ -308,13 +302,13 @@ class MobilerunComputer {
308
302
  const [sx, sy, ex, ey] = vertical
309
303
  ? [cx, cy + (sign * span) / 2, cx, cy - (sign * span) / 2]
310
304
  : [cx + (sign * span) / 2, cy, cx - (sign * span) / 2, cy];
311
- await client.devices.actions.swipe(id, { startX: clampX(sx), startY: clampY(sy), endX: clampX(ex), endY: clampY(ey), duration: 400 });
305
+ await this.client.devices.actions.swipe(id, { startX: clampX(sx), startY: clampY(sy), endX: clampX(ex), endY: clampY(ey), duration: 400 });
312
306
  return {};
313
307
  }
314
308
  case "type":
315
309
  if (!a.text)
316
310
  throw new Error("type needs text");
317
- await client.devices.keyboard.write(id, { text: a.text });
311
+ await this.client.devices.keyboard.write(id, { text: a.text });
318
312
  return {};
319
313
  case "key": {
320
314
  if (!a.text)
@@ -323,7 +317,7 @@ class MobilerunComputer {
323
317
  const codes = a.text.trim().split(/\s+/).map(mobilerunKey);
324
318
  for (let n = 0; n < Math.max(1, a.repeat ?? 1); n++) {
325
319
  for (const key of codes)
326
- await client.devices.keyboard.key(id, { key });
320
+ await this.client.devices.keyboard.key(id, { key });
327
321
  }
328
322
  return {};
329
323
  }
@@ -362,9 +356,8 @@ class MobilerunComputer {
362
356
  }
363
357
  /** Pulls a file from a device path, e.g. /sdcard/Download/report.pdf. */
364
358
  async readFile(path) {
365
- const client = await this.sdk();
366
359
  try {
367
- return await bytesOf(client.devices.files.download(this.nativeId, { path }, { headers: { "Accept-Encoding": "identity" } }));
360
+ return await bytesOf(this.client.devices.files.download(this.nativeId, { path }, { headers: { "Accept-Encoding": "identity" } }));
368
361
  }
369
362
  catch (err) {
370
363
  throw toProviderError(err);
@@ -375,10 +368,9 @@ class MobilerunComputer {
375
368
  const name = path.slice(path.lastIndexOf("/") + 1);
376
369
  if (!name)
377
370
  throw new ProviderError(ID, `writeFile needs a file path, got directory "${path}"`);
378
- const client = await this.sdk();
379
371
  const { toFile } = await optionalImport("@mobilerun/sdk", "mobilerun");
380
372
  const file = await toFile(Buffer.from(toBytes(content)), name);
381
- await guard(client.devices.files.upload(this.nativeId, { path: dirname(path), file }));
373
+ await guard(this.client.devices.files.upload(this.nativeId, { path: dirname(path), file }));
382
374
  }
383
375
  /**
384
376
  * The device's WebRTC stream: `url` is the device's streamUrl and `token` its device-scoped
@@ -387,7 +379,7 @@ class MobilerunComputer {
387
379
  * (DeviceStream hasControl={false}). Mobilerun does not publish an expiry, so expiresAt is null.
388
380
  */
389
381
  async viewer(mode = "watch", _opts = {}) {
390
- const d = await guard((await this.sdk()).devices.retrieve(this.nativeId));
382
+ const d = await guard(this.client.devices.retrieve(this.nativeId));
391
383
  if (!d.streamUrl || !d.streamToken)
392
384
  throw new ProviderError(ID, `no live stream for device ${this.nativeId} (state: ${d.state})`);
393
385
  return {
@@ -400,11 +392,11 @@ class MobilerunComputer {
400
392
  }
401
393
  /** Park: apps, data and identity kept, no minutes billed. connectComputer resumes it. 404 where capabilities.stop is false. */
402
394
  async sleep() {
403
- await guard((await this.sdk()).devices.stop(this.nativeId));
395
+ await guard(this.client.devices.stop(this.nativeId));
404
396
  }
405
397
  /** Terminate and release. Subscription-billed (dedicated) phones refuse this with 401. */
406
398
  async delete() {
407
- await guard((await this.sdk()).devices.terminate(this.nativeId));
399
+ await guard(this.client.devices.terminate(this.nativeId));
408
400
  }
409
401
  }
410
402
  function seconds(n) {
@@ -35,6 +35,7 @@ export class ModalProvider {
35
35
  gpu: spec.gpu,
36
36
  timeoutMs: (spec.timeoutMinutes ?? 30) * 60_000,
37
37
  env: spec.env,
38
+ ...(spec.ports?.length ? { encryptedPorts: spec.ports } : {}),
38
39
  });
39
40
  return new ModalBox(sb);
40
41
  }
@@ -91,6 +92,12 @@ class ModalBox {
91
92
  throw new ProviderError("modal", message);
92
93
  }
93
94
  }
95
+ async url(port) {
96
+ const tunnel = (await this.sb.tunnels())[port];
97
+ if (!tunnel)
98
+ throw new ProviderError("modal", `port ${port} was not requested when this sandbox was created`, 400);
99
+ return tunnel.url;
100
+ }
94
101
  async writeFile(path, content) {
95
102
  await this.sb.filesystem.writeBytes(toBytes(content), path);
96
103
  }
@@ -1,10 +1,10 @@
1
1
  import { ProviderError } from "../types.js";
2
2
  import { optionalImport } from "../util.js";
3
- import { E2BBox } from "./e2b.js";
3
+ import { E2BNativeBox } from "./e2b.js";
4
4
  /**
5
5
  * Novita AI Agent Sandbox via the official `novita-sandbox` SDK (2.x), a fork of E2B's SDK with
6
- * the same surface (Sandbox.create/connect, commands.run with onStdout/onStderr, files.read/write,
7
- * pause, kill), so the E2B box wrapper is reused as-is.
6
+ * the same surface for creating, running and pausing sandboxes, including getHost and background
7
+ * command handles, so the E2B box wrapper is reused.
8
8
  *
9
9
  * Why not the `e2b` SDK with Novita's domain: that was Novita's documented route for its v1
10
10
  * cluster (sandbox.novita.ai), but since the 2026-06-08 SDK 2.0 release the E2B-compatible page
@@ -56,7 +56,7 @@ export class NovitaProvider {
56
56
  const template = spec.image?.novita;
57
57
  try {
58
58
  const sbx = template ? await Sandbox.create(template, opts) : await Sandbox.create(opts);
59
- return new E2BBox(sbx, ID);
59
+ return new E2BNativeBox(sbx, ID);
60
60
  }
61
61
  catch (err) {
62
62
  throw wrap(err);
@@ -66,7 +66,7 @@ export class NovitaProvider {
66
66
  async connect(nativeId) {
67
67
  const { Sandbox } = await optionalImport("novita-sandbox", "novita");
68
68
  try {
69
- return new E2BBox(await Sandbox.connect(nativeId, this.conn()), ID);
69
+ return new E2BNativeBox(await Sandbox.connect(nativeId, this.conn()), ID);
70
70
  }
71
71
  catch (err) {
72
72
  throw wrap(err);
@@ -176,7 +176,7 @@ class SailBox {
176
176
  get path() {
177
177
  return `/sailboxes/${encodeURIComponent(this.nativeId)}`;
178
178
  }
179
- url(sub) {
179
+ sandboxUrl(sub) {
180
180
  return `${this.p.sailboxApi}${this.path}${sub}`;
181
181
  }
182
182
  async resume() {
@@ -225,7 +225,7 @@ class SailBox {
225
225
  }
226
226
  };
227
227
  try {
228
- const res = await this.live(() => this.p.request("POST", this.url("/exec"), {
228
+ const res = await this.live(() => this.p.request("POST", this.sandboxUrl("/exec"), {
229
229
  signal: ctl.signal,
230
230
  json: {
231
231
  command: guardTimeout(wrapCommand(cmd, { cwd: opts.cwd }), secs),
@@ -297,12 +297,12 @@ class SailBox {
297
297
  }
298
298
  async writeFile(path, content) {
299
299
  const q = new URLSearchParams({ path, mode: "420" });
300
- const res = await this.live(() => this.p.request("PUT", this.url(`/files?${q}`), { body: toBytes(content) }));
300
+ const res = await this.live(() => this.p.request("PUT", this.sandboxUrl(`/files?${q}`), { body: toBytes(content) }));
301
301
  await res.arrayBuffer().catch(() => { });
302
302
  }
303
303
  async readFile(path) {
304
304
  const q = new URLSearchParams({ path });
305
- const res = await this.live(() => this.p.request("GET", this.url(`/files?${q}`)));
305
+ const res = await this.live(() => this.p.request("GET", this.sandboxUrl(`/files?${q}`)));
306
306
  return new Uint8Array(await res.arrayBuffer());
307
307
  }
308
308
  /** Pause in memory (no compute billed) and wait until it lands, so connect() can resume it. */
@@ -1,6 +1,6 @@
1
- import { DEFAULT_MEMORY_GB, DEFAULT_VCPU } from "../catalog.js";
1
+ import { vercelSandboxSize } from "../catalog.js";
2
2
  import { ProviderError } from "../types.js";
3
- import { DEFAULT_EXEC_TIMEOUT_S, killedByTimeout, optionalImport, timeoutError, toBytes, wrapCommand } from "../util.js";
3
+ import { DEFAULT_EXEC_TIMEOUT_S, errorStatus, killedByTimeout, optionalImport, timeoutError, toBytes, wrapCommand } from "../util.js";
4
4
  /**
5
5
  * Vercel Sandbox via `@vercel/sandbox`. Auth: VERCEL_OIDC_TOKEN (from `vercel env pull`), or
6
6
  * VERCEL_TOKEN + VERCEL_TEAM_ID + VERCEL_PROJECT_ID. Memory is fixed at 2 GB per vCPU.
@@ -19,7 +19,7 @@ export class VercelProvider {
19
19
  }
20
20
  async create(spec) {
21
21
  const { Sandbox } = await optionalImport("@vercel/sandbox", "vercel");
22
- const vcpus = Math.min(8, Math.max(spec.vcpu ?? DEFAULT_VCPU, Math.ceil((spec.memoryGb ?? DEFAULT_MEMORY_GB) / 2)));
22
+ const { vcpu: vcpus } = vercelSandboxSize(spec);
23
23
  const sbx = await Sandbox.create({
24
24
  ...this.creds(),
25
25
  runtime: spec.image?.vercel ?? "node22",
@@ -27,6 +27,7 @@ export class VercelProvider {
27
27
  resources: { vcpus },
28
28
  env: spec.env,
29
29
  tags: spec.metadata,
30
+ ...(spec.ports?.length ? { ports: spec.ports } : {}),
30
31
  // v3 keeps sandboxes by default and restarts a stopped one on the next command; a router
31
32
  // sandbox is single-use, so nothing should outlive kill().
32
33
  persistent: false,
@@ -90,6 +91,43 @@ class VercelBox {
90
91
  throw new ProviderError("vercel", err?.message ?? String(err));
91
92
  }
92
93
  }
94
+ url(port) {
95
+ try {
96
+ return this.sbx.domain(port);
97
+ }
98
+ catch (err) {
99
+ if (err instanceof Error && err.message === `No route for port ${port}`) {
100
+ throw new ProviderError("vercel", `port ${port} was not requested when this sandbox was created`, 400);
101
+ }
102
+ throw err;
103
+ }
104
+ }
105
+ async start(cmd, opts = {}) {
106
+ try {
107
+ const command = await this.sbx.runCommand({
108
+ cmd: "sh",
109
+ args: ["-c", cmd],
110
+ cwd: opts.cwd,
111
+ env: opts.env,
112
+ detached: true,
113
+ });
114
+ return {
115
+ async kill() {
116
+ try {
117
+ await command.kill("SIGKILL");
118
+ }
119
+ catch (err) {
120
+ const status = errorStatus(err);
121
+ if (status !== 404)
122
+ throw new ProviderError("vercel", err instanceof Error ? err.message : String(err), status);
123
+ }
124
+ },
125
+ };
126
+ }
127
+ catch (err) {
128
+ throw new ProviderError("vercel", err instanceof Error ? err.message : String(err), errorStatus(err));
129
+ }
130
+ }
93
131
  async writeFile(path, content) {
94
132
  await this.sbx.writeFiles([{ path, content: Buffer.from(toBytes(content)) }]);
95
133
  }