@sandboxrouter/sdk 0.15.2 → 0.16.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/dist/cli.js +5 -0
- package/dist/client.d.ts +10 -0
- package/dist/client.js +12 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/move.d.ts +69 -0
- package/dist/move.js +123 -0
- package/dist/router.d.ts +18 -0
- package/dist/router.js +20 -0
- package/package.json +3 -3
package/dist/cli.js
CHANGED
|
@@ -214,6 +214,11 @@ async function main() {
|
|
|
214
214
|
if (!command)
|
|
215
215
|
throw new RouterError('usage: sandboxrouter compare "<cmd>" [--setup "<cmd>"] [--runs 3] [--provider a,b]');
|
|
216
216
|
const ids = providers ?? router.registered().filter((id) => router.isConfigured(id));
|
|
217
|
+
// With no keys there is nothing to compare: say so instead of printing an empty table.
|
|
218
|
+
if (!ids.length) {
|
|
219
|
+
throw new RouterError("no provider keys found: set the API key for at least one provider (the README's Env table lists each provider's variables); " +
|
|
220
|
+
"`npx @sandboxrouter/sdk providers` shows which are set");
|
|
221
|
+
}
|
|
217
222
|
const rows = await compare({ router, providers: ids, command, setup: values.setup, runs: num(values.runs), timeoutSeconds: num(values.seconds), parallel: num(values.parallel), onProgress: (m) => console.error(m) });
|
|
218
223
|
if (values.json)
|
|
219
224
|
return console.log(JSON.stringify(rows, null, 2));
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Candidate, Quote, Size } from "./router.js";
|
|
2
|
+
import { type CopyOptions, type CopyResult, type FileBox, type MoveOptions } from "./move.js";
|
|
2
3
|
import type { Attempt, Capability, ExecOptions, ExecResult, RouteOptions, RouterErrorCode, SandboxProcess, SandboxSpec, StartOptions } from "./types.js";
|
|
3
4
|
/**
|
|
4
5
|
* Client for the sandboxrouter HTTP API: the hosted service (one key, prepaid credits) or your own
|
|
@@ -42,6 +43,15 @@ export declare class Client {
|
|
|
42
43
|
create(spec?: SandboxSpec, route?: RouteOptions, opts?: {
|
|
43
44
|
idempotencyKey?: string;
|
|
44
45
|
}): Promise<RemoteSandbox>;
|
|
46
|
+
/** Copy a folder from one sandbox to another, on any two providers. The files pass through this machine. */
|
|
47
|
+
copy(from: FileBox, to: FileBox, opts?: CopyOptions): Promise<CopyResult>;
|
|
48
|
+
/**
|
|
49
|
+
* Move a sandbox's folder to a new sandbox and kill the old one: on another provider by default,
|
|
50
|
+
* or on the ones `provider` names. If the new one can't start or the copy fails, the old sandbox is left running.
|
|
51
|
+
*/
|
|
52
|
+
move(from: FileBox, opts?: MoveOptions): Promise<RemoteSandbox & {
|
|
53
|
+
moved: CopyResult;
|
|
54
|
+
}>;
|
|
45
55
|
/** A handle on a sandbox you created earlier. */
|
|
46
56
|
sandbox(id: string): RemoteSandbox;
|
|
47
57
|
}
|
package/dist/client.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { copyFiles, moveSandbox } from "./move.js";
|
|
1
2
|
/**
|
|
2
3
|
* Client for the sandboxrouter HTTP API: the hosted service (one key, prepaid credits) or your own
|
|
3
4
|
* `sandboxrouter serve`. Provider keys live on the server; this side only needs the one key.
|
|
@@ -66,6 +67,17 @@ export class Client {
|
|
|
66
67
|
const r = (await res.json());
|
|
67
68
|
return new RemoteSandbox(this, r.id, r.provider, { ...r, replayed: res.headers.get("idempotent-replayed") === "true" });
|
|
68
69
|
}
|
|
70
|
+
/** Copy a folder from one sandbox to another, on any two providers. The files pass through this machine. */
|
|
71
|
+
copy(from, to, opts = {}) {
|
|
72
|
+
return copyFiles(from, to, opts);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Move a sandbox's folder to a new sandbox and kill the old one: on another provider by default,
|
|
76
|
+
* or on the ones `provider` names. If the new one can't start or the copy fails, the old sandbox is left running.
|
|
77
|
+
*/
|
|
78
|
+
move(from, opts = {}) {
|
|
79
|
+
return moveSandbox({ candidates: (spec, route) => this.route(spec, route), create: (spec, route) => this.create(spec, route) }, from, opts);
|
|
80
|
+
}
|
|
69
81
|
/** A handle on a sandbox you created earlier. */
|
|
70
82
|
sandbox(id) {
|
|
71
83
|
return new RemoteSandbox(this, id, id.split(":")[0]);
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export { validate, splitRequest, SPEC_KEYS, ROUTE_KEYS, STRATEGIES } from "./val
|
|
|
13
13
|
export { CATALOG, hourlyCost, unfit, info, billingRules, billedUsd, type ProviderInfo } from "./catalog.js";
|
|
14
14
|
export { createApp, HttpError, ERROR_STATUS, ORPHAN_GRACE_MS, type ServerHooks } from "./server.js";
|
|
15
15
|
export { Client, ClientError, RemoteSandbox, type CreateResponse } from "./client.js";
|
|
16
|
+
export { copyFiles, moveSandbox, DEFAULT_COPY_MAX_BYTES, type CopyOptions, type CopyResult, type FileBox, type MoveOptions, type Mover } from "./move.js";
|
|
16
17
|
export { RoutedComputer, createComputer, splitComputerRequest, DEFAULT_COMPUTER_TIMEOUT_S, DEFAULT_COMPUTER_DEADLINE_S, type ComputerRoute, planComputer, computerCatalog, computerHourly, COMPUTER_ENTRIES, type ComputerCatalogEntry, type ComputerCandidate, type ComputerProviderId, type ActionResult, type ComputerAction, type ComputerActionName, type ComputerInfo, type ComputerOs, type ComputerProvider, type ComputerSpec, type ProviderComputer, } from "./computers.js";
|
|
17
18
|
export { bench, benchMarkdown, type BenchRow } from "./bench.js";
|
|
18
19
|
export { aggregate, loadReports, makeReport, renderLeaderboard, type BenchReport, type LeaderRow } from "./leaderboard.js";
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,7 @@ export { validate, splitRequest, SPEC_KEYS, ROUTE_KEYS, STRATEGIES } from "./val
|
|
|
13
13
|
export { CATALOG, hourlyCost, unfit, info, billingRules, billedUsd } from "./catalog.js";
|
|
14
14
|
export { createApp, HttpError, ERROR_STATUS, ORPHAN_GRACE_MS } from "./server.js";
|
|
15
15
|
export { Client, ClientError, RemoteSandbox } from "./client.js";
|
|
16
|
+
export { copyFiles, moveSandbox, DEFAULT_COPY_MAX_BYTES } from "./move.js";
|
|
16
17
|
export { RoutedComputer, createComputer, splitComputerRequest, DEFAULT_COMPUTER_TIMEOUT_S, DEFAULT_COMPUTER_DEADLINE_S, planComputer, computerCatalog, computerHourly, COMPUTER_ENTRIES, } from "./computers.js";
|
|
17
18
|
export { bench, benchMarkdown } from "./bench.js";
|
|
18
19
|
export { aggregate, loadReports, makeReport, renderLeaderboard } from "./leaderboard.js";
|
package/dist/move.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type ExecOptions, type ExecResult, type ProviderId, type RouteOptions, type SandboxSpec } from "./types.js";
|
|
2
|
+
/** What copy and move need from a sandbox: a `RoutedSandbox` and a `RemoteSandbox` both fit. */
|
|
3
|
+
export interface FileBox {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly provider: string;
|
|
6
|
+
readonly size?: {
|
|
7
|
+
vcpu: number;
|
|
8
|
+
memoryGb: number;
|
|
9
|
+
};
|
|
10
|
+
exec(cmd: string, opts?: ExecOptions): Promise<ExecResult>;
|
|
11
|
+
readFile(path: string): Promise<Uint8Array>;
|
|
12
|
+
writeFile(path: string, content: string | Uint8Array): Promise<void>;
|
|
13
|
+
kill(): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export interface CopyOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Folder to copy from the source. Default: the folder its commands run in. Copied whole like that,
|
|
18
|
+
* the destination keeps its own shell startup files (`.bashrc`, `.profile`, ...), since those belong to its image.
|
|
19
|
+
*/
|
|
20
|
+
path?: string;
|
|
21
|
+
/** Folder to copy into. Default: the same path, or the destination's own working folder when `path` isn't given. */
|
|
22
|
+
to?: string;
|
|
23
|
+
/** Names or patterns to leave behind, as `tar --exclude` reads them, e.g. `["node_modules", ".venv", "*.log"]`. */
|
|
24
|
+
exclude?: string[];
|
|
25
|
+
/** Refuse when the packed folder is bigger than this (default 1 GB), before anything is sent. */
|
|
26
|
+
maxBytes?: number;
|
|
27
|
+
/** Seconds each pack and unpack command may take (default 600). */
|
|
28
|
+
timeoutSeconds?: number;
|
|
29
|
+
/** Bytes sent per file transfer (default 4 MB). Providers cap how much one file call carries. */
|
|
30
|
+
chunkBytes?: number;
|
|
31
|
+
}
|
|
32
|
+
export interface CopyResult {
|
|
33
|
+
/** The folder read on the source. */
|
|
34
|
+
from: string;
|
|
35
|
+
/** The folder written on the destination. */
|
|
36
|
+
to: string;
|
|
37
|
+
/** Size of the packed (gzip) folder that was sent. */
|
|
38
|
+
bytes: number;
|
|
39
|
+
ms: number;
|
|
40
|
+
}
|
|
41
|
+
export interface MoveOptions extends CopyOptions, RouteOptions {
|
|
42
|
+
/** The new sandbox's spec. Its size defaults to the old sandbox's. */
|
|
43
|
+
spec?: SandboxSpec;
|
|
44
|
+
/** Leave the old sandbox running (default: kill it once the files are across). */
|
|
45
|
+
keep?: boolean;
|
|
46
|
+
}
|
|
47
|
+
export declare const DEFAULT_COPY_MAX_BYTES: number;
|
|
48
|
+
/**
|
|
49
|
+
* Copy a folder from one sandbox to another, on any two providers: packed with tar on the source,
|
|
50
|
+
* carried through this process in pieces, unpacked on the destination. Files, their modes and
|
|
51
|
+
* symlinks come across; running processes, memory and env vars don't. The source isn't changed.
|
|
52
|
+
* Both sandboxes need `tar` and `split` (every stock image has them).
|
|
53
|
+
*/
|
|
54
|
+
export declare function copyFiles(from: FileBox, to: FileBox, opts?: CopyOptions): Promise<CopyResult>;
|
|
55
|
+
/** What a move needs from a router: a `Router` and a hosted `Client` both fit. */
|
|
56
|
+
export interface Mover<B extends FileBox> {
|
|
57
|
+
candidates(spec: SandboxSpec, route: RouteOptions): Promise<{
|
|
58
|
+
provider: ProviderId;
|
|
59
|
+
skip?: string;
|
|
60
|
+
}[]>;
|
|
61
|
+
create(spec: SandboxSpec, route: RouteOptions): Promise<B>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Start a sandbox on another provider, copy the folder across, then kill the old one. If anything
|
|
65
|
+
* fails the new sandbox is killed and the old one is left as it was.
|
|
66
|
+
*/
|
|
67
|
+
export declare function moveSandbox<B extends FileBox>(mover: Mover<B>, from: FileBox, opts?: MoveOptions): Promise<B & {
|
|
68
|
+
moved: CopyResult;
|
|
69
|
+
}>;
|
package/dist/move.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { RouterError } from "./types.js";
|
|
3
|
+
import { shq } from "./util.js";
|
|
4
|
+
export const DEFAULT_COPY_MAX_BYTES = 1024 ** 3;
|
|
5
|
+
/** Shell startup files the destination keeps as its image made them when a working folder is copied whole (no `path`). */
|
|
6
|
+
const IMAGE_FILES = [".bashrc", ".bash_profile", ".bash_logout", ".profile", ".zshrc"];
|
|
7
|
+
const DEFAULT_CHUNK_BYTES = 4 * 1024 * 1024;
|
|
8
|
+
const DEFAULT_COPY_TIMEOUT_S = 600;
|
|
9
|
+
/**
|
|
10
|
+
* Copy a folder from one sandbox to another, on any two providers: packed with tar on the source,
|
|
11
|
+
* carried through this process in pieces, unpacked on the destination. Files, their modes and
|
|
12
|
+
* symlinks come across; running processes, memory and env vars don't. The source isn't changed.
|
|
13
|
+
* Both sandboxes need `tar` and `split` (every stock image has them).
|
|
14
|
+
*/
|
|
15
|
+
export async function copyFiles(from, to, opts = {}) {
|
|
16
|
+
const started = Date.now();
|
|
17
|
+
const timeoutSeconds = opts.timeoutSeconds ?? DEFAULT_COPY_TIMEOUT_S;
|
|
18
|
+
const chunk = Math.max(64 * 1024, Math.floor(opts.chunkBytes ?? DEFAULT_CHUNK_BYTES));
|
|
19
|
+
const maxBytes = opts.maxBytes ?? DEFAULT_COPY_MAX_BYTES;
|
|
20
|
+
const src = opts.path ?? (await workdir(from));
|
|
21
|
+
const dst = opts.to ?? opts.path ?? (await workdir(to));
|
|
22
|
+
for (const p of [src, dst]) {
|
|
23
|
+
if (!p.startsWith("/"))
|
|
24
|
+
throw new RouterError(`copy needs an absolute path, got "${p}"`, [], "bad_request");
|
|
25
|
+
if (p.replace(/\/+$/, "") === "")
|
|
26
|
+
throw new RouterError("copy won't take the whole filesystem (/): name a folder", [], "bad_request");
|
|
27
|
+
}
|
|
28
|
+
const tmp = `/tmp/sr-move-${randomUUID().slice(0, 8)}`;
|
|
29
|
+
const run = async (box, what, cmd) => {
|
|
30
|
+
const r = await box.exec(cmd, { timeoutSeconds });
|
|
31
|
+
if (r.exitCode !== 0) {
|
|
32
|
+
const detail = (r.stderr || r.stdout).trim().split("\n").slice(-3).join(" ");
|
|
33
|
+
throw new RouterError(`${what} failed on ${box.provider} (exit ${r.exitCode})${detail ? `: ${detail}` : ""}`, [], "all_failed");
|
|
34
|
+
}
|
|
35
|
+
return r.stdout;
|
|
36
|
+
};
|
|
37
|
+
const clean = (box) => box.exec(`rm -rf ${shq(tmp)}`, { timeoutSeconds: 60 }).catch(() => { });
|
|
38
|
+
try {
|
|
39
|
+
// The archive is written outside the folder where it can be, and excluded by name in case /tmp is inside it.
|
|
40
|
+
const excludes = ["sr-move-*", ...(opts.exclude ?? [])].map((e) => `--exclude=${shq(e)}`).join(" ");
|
|
41
|
+
const packed = await run(from, "packing the folder", [
|
|
42
|
+
`mkdir -p ${shq(tmp)}`,
|
|
43
|
+
`tar -czf ${shq(`${tmp}/a.tgz`)} ${excludes} -C ${shq(src)} .`,
|
|
44
|
+
`echo "size=$(wc -c < ${shq(`${tmp}/a.tgz`)} | tr -d ' ')"`,
|
|
45
|
+
].join(" && "));
|
|
46
|
+
const bytes = Number(/size=(\d+)/.exec(packed)?.[1] ?? NaN);
|
|
47
|
+
if (!Number.isFinite(bytes))
|
|
48
|
+
throw new RouterError(`couldn't read the packed size on ${from.provider}`, [], "all_failed");
|
|
49
|
+
if (bytes > maxBytes) {
|
|
50
|
+
throw new RouterError(`the folder packs to ${mb(bytes)}, over the ${mb(maxBytes)} limit: pass exclude (e.g. node_modules) or a higher maxBytes`, [], "bad_request");
|
|
51
|
+
}
|
|
52
|
+
const listed = await run(from, "splitting the archive", `cd ${shq(tmp)} && split -b ${chunk} -a 4 a.tgz p. && rm a.tgz && ls p.*`);
|
|
53
|
+
const parts = listed.split("\n").map((l) => l.trim()).filter((l) => /^p\.[a-z]{4}$/.test(l)).sort();
|
|
54
|
+
if (parts.length === 0)
|
|
55
|
+
throw new RouterError(`no archive pieces found on ${from.provider}`, [], "all_failed");
|
|
56
|
+
await run(to, "preparing the destination", `mkdir -p ${shq(tmp)} ${shq(dst)}`);
|
|
57
|
+
for (const part of parts)
|
|
58
|
+
await to.writeFile(`${tmp}/${part}`, await from.readFile(`${tmp}/${part}`));
|
|
59
|
+
// The size check catches a piece a provider cut short before tar unpacks half a folder.
|
|
60
|
+
const got = await run(to, "checking the archive", `cat ${shq(tmp)}/p.* | wc -c | tr -d ' '`);
|
|
61
|
+
if (Number(got.trim().split("\n").pop()) !== bytes) {
|
|
62
|
+
throw new RouterError(`the archive arrived as ${got.trim()} bytes on ${to.provider}, expected ${bytes}`, [], "all_failed");
|
|
63
|
+
}
|
|
64
|
+
// -o: the files belong to whoever runs the destination sandbox, not the source's user id.
|
|
65
|
+
// Copying a whole working folder would replace the destination image's shell startup files with
|
|
66
|
+
// the source image's (a different PATH, a different user): the destination's are put back after.
|
|
67
|
+
const keep = opts.path === undefined ? IMAGE_FILES.map(shq).join(" ") : "";
|
|
68
|
+
const save = keep ? `mkdir -p ${shq(`${tmp}/keep`)} && for f in ${keep}; do if [ -f ${shq(dst)}/"$f" ]; then cp -p ${shq(dst)}/"$f" ${shq(`${tmp}/keep`)}/; fi; done && ` : "";
|
|
69
|
+
const restore = keep ? ` && for f in ${keep}; do if [ -f ${shq(`${tmp}/keep`)}/"$f" ]; then cp -p ${shq(`${tmp}/keep`)}/"$f" ${shq(dst)}/; fi; done` : "";
|
|
70
|
+
await run(to, "unpacking the folder", `${save}cat ${shq(tmp)}/p.* | tar -xzo -f - -C ${shq(dst)}${restore}`);
|
|
71
|
+
return { from: src, to: dst, bytes, ms: Date.now() - started };
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
await Promise.all([clean(from), clean(to)]);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Start a sandbox on another provider, copy the folder across, then kill the old one. If anything
|
|
79
|
+
* fails the new sandbox is killed and the old one is left as it was.
|
|
80
|
+
*/
|
|
81
|
+
export async function moveSandbox(mover, from, opts = {}) {
|
|
82
|
+
const { spec: given = {}, keep, path, to, exclude, maxBytes, timeoutSeconds, chunkBytes, ...route } = opts;
|
|
83
|
+
let spec = { ...given };
|
|
84
|
+
const elsewhere = async (s) => (await mover.candidates(s, route)).filter((c) => !c.skip && c.provider !== from.provider).map((c) => c.provider);
|
|
85
|
+
// The new sandbox keeps the old one's size. A provider's fixed default size (E2B's 2 vCPU / 0.5 GB)
|
|
86
|
+
// may be one nobody else sells, so when nothing else takes it the move goes ahead at the default size.
|
|
87
|
+
const sized = given.vcpu === undefined && given.memoryGb === undefined && from.size ? { ...given, vcpu: from.size.vcpu, memoryGb: from.size.memoryGb } : undefined;
|
|
88
|
+
if (route.provider !== undefined) {
|
|
89
|
+
if (sized && (await mover.candidates(sized, route)).some((c) => !c.skip))
|
|
90
|
+
spec = sized;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// Without a named provider, "move" means somewhere else: the usual order, minus where it is now.
|
|
94
|
+
let list = sized ? await elsewhere(sized) : [];
|
|
95
|
+
if (list.length > 0)
|
|
96
|
+
spec = sized;
|
|
97
|
+
else
|
|
98
|
+
list = await elsewhere(spec);
|
|
99
|
+
if (list.length === 0)
|
|
100
|
+
throw new RouterError(`no other provider can take this sandbox (it is on ${from.provider})`, [], "no_provider");
|
|
101
|
+
route.provider = list;
|
|
102
|
+
}
|
|
103
|
+
const next = await mover.create(spec, route);
|
|
104
|
+
let moved;
|
|
105
|
+
try {
|
|
106
|
+
moved = await copyFiles(from, next, { path, to, exclude, maxBytes, timeoutSeconds, chunkBytes });
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
await next.kill().catch(() => { });
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
if (!keep)
|
|
113
|
+
await from.kill();
|
|
114
|
+
return Object.assign(next, { moved });
|
|
115
|
+
}
|
|
116
|
+
async function workdir(box) {
|
|
117
|
+
const r = await box.exec("pwd", { timeoutSeconds: 60 });
|
|
118
|
+
const dir = r.stdout.trim().split("\n").pop()?.trim() ?? "";
|
|
119
|
+
if (r.exitCode !== 0 || !dir.startsWith("/"))
|
|
120
|
+
throw new RouterError(`couldn't find the working folder on ${box.provider}: pass path`, [], "all_failed");
|
|
121
|
+
return dir;
|
|
122
|
+
}
|
|
123
|
+
const mb = (n) => `${(n / 1024 / 1024).toFixed(n < 10 * 1024 * 1024 ? 1 : 0)} MB`;
|
package/dist/router.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ProviderInfo } from "./catalog.js";
|
|
2
2
|
import { type ComputerRoute, RoutedComputer, type ComputerOs, type ComputerProvider, type ComputerProviderId, type ComputerSpec } from "./computers.js";
|
|
3
3
|
import { Ledger } from "./ledger.js";
|
|
4
|
+
import { type CopyOptions, type CopyResult, type FileBox, type MoveOptions } from "./move.js";
|
|
4
5
|
import { type Attempt, type ExecOptions, type ExecResult, type Provider, type ProviderId, type ProviderSandbox, type RouteOptions, type SandboxProcess, type SandboxSpec, type StartOptions } from "./types.js";
|
|
5
6
|
/** vCPUs and memory a sandbox gets. */
|
|
6
7
|
export interface Size {
|
|
@@ -227,6 +228,23 @@ export declare class Router {
|
|
|
227
228
|
/** Start a desktop or phone, routed like a sandbox (see createComputer). */
|
|
228
229
|
computer(spec?: ComputerSpec, route?: ComputerRoute): Promise<RoutedComputer>;
|
|
229
230
|
getComputer(id: string): Promise<RoutedComputer>;
|
|
231
|
+
/**
|
|
232
|
+
* Copy a folder from one sandbox to another, on any two providers. Files only: running processes,
|
|
233
|
+
* memory and env vars stay behind. See `CopyOptions`.
|
|
234
|
+
*/
|
|
235
|
+
copy(from: FileBox, to: FileBox, opts?: CopyOptions): Promise<CopyResult>;
|
|
236
|
+
/**
|
|
237
|
+
* Move a sandbox's folder to a new sandbox and kill the old one: on another provider by default,
|
|
238
|
+
* or on the ones `provider` names. The new sandbox keeps the old one's size where another provider
|
|
239
|
+
* sells it, else the default size. If the new one can't
|
|
240
|
+
* start or the copy fails, the old sandbox is left running and untouched.
|
|
241
|
+
*
|
|
242
|
+
* sbx = await router.move(sbx); // next-best provider
|
|
243
|
+
* sbx = await router.move(sbx, { provider: "e2b", path: "/workspace", exclude: ["node_modules"] });
|
|
244
|
+
*/
|
|
245
|
+
move(from: FileBox, opts?: MoveOptions): Promise<RoutedSandbox & {
|
|
246
|
+
moved: CopyResult;
|
|
247
|
+
}>;
|
|
230
248
|
/** Reattach to a sandbox by its routed id (`provider:nativeId`). */
|
|
231
249
|
get(id: string): Promise<RoutedSandbox>;
|
|
232
250
|
}
|
package/dist/router.js
CHANGED
|
@@ -5,6 +5,7 @@ import { loadBench, median } from "./bench-store.js";
|
|
|
5
5
|
import { PUBLISHED } from "./published.js";
|
|
6
6
|
import { Ledger, defaultLedgerFile } from "./ledger.js";
|
|
7
7
|
import { DEFAULT_EXEC_TIMEOUT_S, LIMIT_ERROR, SETUP_ERRORS, errorStatus, timeoutError, withDeadline } from "./util.js";
|
|
8
|
+
import { copyFiles, moveSandbox } from "./move.js";
|
|
8
9
|
import { BILLED_VS_LIST } from "./billing.js";
|
|
9
10
|
import { FAILING, VERIFIED } from "./verified.js";
|
|
10
11
|
import { isPort, validate, validateStart } from "./validate.js";
|
|
@@ -471,6 +472,25 @@ export class Router {
|
|
|
471
472
|
const e = this.ledger?.list().find((x) => x.id === id);
|
|
472
473
|
return new RoutedComputer(provider, await p.connectComputer(id.slice(i + 1)), [], e?.usdHour, this.ledger);
|
|
473
474
|
}
|
|
475
|
+
/**
|
|
476
|
+
* Copy a folder from one sandbox to another, on any two providers. Files only: running processes,
|
|
477
|
+
* memory and env vars stay behind. See `CopyOptions`.
|
|
478
|
+
*/
|
|
479
|
+
copy(from, to, opts = {}) {
|
|
480
|
+
return copyFiles(from, to, opts);
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Move a sandbox's folder to a new sandbox and kill the old one: on another provider by default,
|
|
484
|
+
* or on the ones `provider` names. The new sandbox keeps the old one's size where another provider
|
|
485
|
+
* sells it, else the default size. If the new one can't
|
|
486
|
+
* start or the copy fails, the old sandbox is left running and untouched.
|
|
487
|
+
*
|
|
488
|
+
* sbx = await router.move(sbx); // next-best provider
|
|
489
|
+
* sbx = await router.move(sbx, { provider: "e2b", path: "/workspace", exclude: ["node_modules"] });
|
|
490
|
+
*/
|
|
491
|
+
move(from, opts = {}) {
|
|
492
|
+
return moveSandbox({ candidates: async (spec, route) => this.plan(spec, route), create: (spec, route) => this.create(spec, route) }, from, opts);
|
|
493
|
+
}
|
|
474
494
|
/** Reattach to a sandbox by its routed id (`provider:nativeId`). */
|
|
475
495
|
async get(id) {
|
|
476
496
|
const { provider, nativeId } = parseId(id);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sandboxrouter/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "One API for every sandbox provider: route AI agents' code by price, speed or capability, with automatic fallback. Free and open source.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -184,14 +184,14 @@
|
|
|
184
184
|
"@e2b/desktop": "^2.5.0",
|
|
185
185
|
"@fly/sprites": "^0.2.4",
|
|
186
186
|
"@hopx-ai/sdk": "^0.5.1",
|
|
187
|
-
"@limrun/api": "^0.
|
|
187
|
+
"@limrun/api": "^0.73.2",
|
|
188
188
|
"@mobilerun/sdk": "^6.1.0",
|
|
189
189
|
"@northflank/js-client": "^0.12.0",
|
|
190
190
|
"@runloop/api-client": "^3.0.0",
|
|
191
191
|
"@smithy/signature-v4": "^5.7.5",
|
|
192
192
|
"@tensorlakeai/tensorlake": "^0.5.161",
|
|
193
193
|
"@types/node": "^26.6.6",
|
|
194
|
-
"@vercel/sandbox": "^
|
|
194
|
+
"@vercel/sandbox": "^4.0.0",
|
|
195
195
|
"e2b": "^2.63.0",
|
|
196
196
|
"modal": "^0.11.1",
|
|
197
197
|
"morphcloud": "^0.0.20",
|