@quietrobot/sandboxes 0.0.0-stage → 0.2.1
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/LICENSE +201 -0
- package/README.md +139 -2
- package/dist/e2b.d.ts +238 -0
- package/dist/e2b.js +353 -0
- package/dist/index.d.ts +692 -0
- package/dist/index.js +639 -0
- package/dist/kernel.d.ts +1 -0
- package/dist/kernel.js +2 -0
- package/package.json +48 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,639 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quiet Robot Sandboxes: TypeScript client.
|
|
3
|
+
*
|
|
4
|
+
* const qr = new Sandboxes({ apiKey: process.env.QR_API_KEY });
|
|
5
|
+
* const sbx = await qr.create({ egress: { mode: "allowlist", allow: ["pypi.org"] } });
|
|
6
|
+
* const run = await sbx.exec("python3 -c 'print(42)'");
|
|
7
|
+
* await sbx.destroy();
|
|
8
|
+
*/
|
|
9
|
+
import { KERNEL_B64 } from "./kernel.js";
|
|
10
|
+
/** The hosted service. Change it with scripts/set-sdk-base-url.sh so both SDKs stay in step. */
|
|
11
|
+
export const DEFAULT_BASE_URL = "https://api.quietrobot.ai";
|
|
12
|
+
/** Where preview URLs live until an API answer says otherwise. */
|
|
13
|
+
export const DEFAULT_PREVIEW_DOMAIN = "quietrobot.dev";
|
|
14
|
+
/** The sandbox user's home folder. Relative paths (files and cwd) are relative to it. */
|
|
15
|
+
export const HOME = "/home/sandbox";
|
|
16
|
+
/** A cwd as the API needs it: absolute, with relative paths and ~ taken from the home folder. */
|
|
17
|
+
function homePath(p) {
|
|
18
|
+
if (!p)
|
|
19
|
+
return p;
|
|
20
|
+
if (p === "~")
|
|
21
|
+
return HOME;
|
|
22
|
+
if (p.startsWith("~/"))
|
|
23
|
+
return `${HOME}/${p.slice(2)}`;
|
|
24
|
+
return p.startsWith("/") ? p : `${HOME}/${p}`;
|
|
25
|
+
}
|
|
26
|
+
export class SandboxesError extends Error {
|
|
27
|
+
status;
|
|
28
|
+
code;
|
|
29
|
+
constructor(status, code, message) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.status = status;
|
|
32
|
+
this.code = code;
|
|
33
|
+
this.name = "SandboxesError";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Thrown when a person denies the command. */
|
|
37
|
+
export class CommandDeniedError extends SandboxesError {
|
|
38
|
+
execution;
|
|
39
|
+
constructor(execution) {
|
|
40
|
+
super(403, "denied", `Command denied by ${execution.approval?.decidedBy ?? "an approver"}${execution.approval?.note ? `: ${execution.approval.note}` : ""}`);
|
|
41
|
+
this.execution = execution;
|
|
42
|
+
this.name = "CommandDeniedError";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
46
|
+
const enc = encodeURIComponent;
|
|
47
|
+
function query(params) {
|
|
48
|
+
const q = new URLSearchParams(Object.entries(params)
|
|
49
|
+
.filter(([, v]) => v !== undefined && v !== null)
|
|
50
|
+
.map(([k, v]) => [k, String(v)])).toString();
|
|
51
|
+
return q ? `?${q}` : "";
|
|
52
|
+
}
|
|
53
|
+
export class Sandboxes {
|
|
54
|
+
apiKey;
|
|
55
|
+
base;
|
|
56
|
+
f;
|
|
57
|
+
/** @internal */
|
|
58
|
+
previewDomain = DEFAULT_PREVIEW_DOMAIN;
|
|
59
|
+
constructor(opts = {}) {
|
|
60
|
+
const env = typeof process !== "undefined" && process ? process.env : {};
|
|
61
|
+
this.apiKey = opts.apiKey ?? env.QR_API_KEY ?? "";
|
|
62
|
+
if (!this.apiKey)
|
|
63
|
+
throw new Error("No API key. Set QR_API_KEY (or pass apiKey). Create a key at https://quietrobot.ai/app/dashboard/keys");
|
|
64
|
+
this.base = (opts.baseUrl ?? env.QR_BASE_URL ?? DEFAULT_BASE_URL).replace(/\/$/, "") + "/api/v1";
|
|
65
|
+
this.f = opts.fetch ?? fetch;
|
|
66
|
+
}
|
|
67
|
+
/** @internal */
|
|
68
|
+
async request(method, path, body, raw = false) {
|
|
69
|
+
const isBytes = body instanceof Uint8Array || body instanceof ArrayBuffer || typeof body === "string";
|
|
70
|
+
const res = await this.f(this.base + path, {
|
|
71
|
+
method,
|
|
72
|
+
headers: {
|
|
73
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
74
|
+
...(body !== undefined && !isBytes ? { "Content-Type": "application/json" } : {}),
|
|
75
|
+
},
|
|
76
|
+
body: body === undefined ? undefined : isBytes ? body : JSON.stringify(body),
|
|
77
|
+
});
|
|
78
|
+
if (!res.ok) {
|
|
79
|
+
const j = (await res.json().catch(() => null));
|
|
80
|
+
throw new SandboxesError(res.status, j?.error?.code ?? "http_error", j?.error?.message ?? `HTTP ${res.status}`);
|
|
81
|
+
}
|
|
82
|
+
return (raw ? new Uint8Array(await res.arrayBuffer()) : await res.json());
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Keys and tokens a sandbox can use without holding them. Values are
|
|
86
|
+
* write-only: list() shows names and hosts, never values.
|
|
87
|
+
*/
|
|
88
|
+
secrets = {
|
|
89
|
+
list: async () => (await this.request("GET", "/secrets")).secrets,
|
|
90
|
+
/** Adds a secret, or replaces the value and hosts of one with the same name. */
|
|
91
|
+
set: (name, value, hosts) => this.request("POST", "/secrets", { name, value, hosts }),
|
|
92
|
+
delete: (name) => this.request("DELETE", `/secrets/${enc(name)}`),
|
|
93
|
+
};
|
|
94
|
+
/** Folders kept between sandboxes. Attach one with create({ volumes: [{ name, path }] }). */
|
|
95
|
+
volumes = {
|
|
96
|
+
list: async () => (await this.request("GET", "/volumes")).volumes,
|
|
97
|
+
create: (name) => this.request("POST", "/volumes", { name }),
|
|
98
|
+
get: (id) => this.request("GET", `/volumes/${enc(id)}`),
|
|
99
|
+
delete: (id) => this.request("DELETE", `/volumes/${enc(id)}`),
|
|
100
|
+
};
|
|
101
|
+
/** Lifecycle events sent to your own URLs, signed the Standard Webhooks way. Check them with verifyWebhook(). */
|
|
102
|
+
webhooks = {
|
|
103
|
+
list: () => this.request("GET", "/webhooks"),
|
|
104
|
+
/** The answer carries the signing secret, shown this once. events defaults to sandbox.*, approval.* and volume.save_failed. */
|
|
105
|
+
create: (opts) => this.request("POST", "/webhooks", opts),
|
|
106
|
+
get: (id) => this.request("GET", `/webhooks/${enc(id)}`),
|
|
107
|
+
update: (id, opts) => this.request("PATCH", `/webhooks/${enc(id)}`, opts),
|
|
108
|
+
delete: (id) => this.request("DELETE", `/webhooks/${enc(id)}`),
|
|
109
|
+
test: (id) => this.request("POST", `/webhooks/${enc(id)}/test`),
|
|
110
|
+
rotateSecret: (id) => this.request("POST", `/webhooks/${enc(id)}/rotate-secret`),
|
|
111
|
+
deliveries: (id) => this.request("GET", `/webhooks/${enc(id)}/deliveries`),
|
|
112
|
+
redeliver: (id, deliveryId) => this.request("POST", `/webhooks/${enc(id)}/deliveries/${enc(deliveryId)}/redeliver`),
|
|
113
|
+
};
|
|
114
|
+
async create(opts = {}) {
|
|
115
|
+
return new Sandbox(this, await this.request("POST", "/sandboxes", opts));
|
|
116
|
+
}
|
|
117
|
+
/** A sandbox by id, or by name for a durable one. */
|
|
118
|
+
async get(id) {
|
|
119
|
+
return new Sandbox(this, await this.request("GET", `/sandboxes/${enc(id)}`));
|
|
120
|
+
}
|
|
121
|
+
/** Same as get(): attach to a sandbox started elsewhere. */
|
|
122
|
+
connect(id) {
|
|
123
|
+
return this.get(id);
|
|
124
|
+
}
|
|
125
|
+
async list(status) {
|
|
126
|
+
const r = await this.request("GET", `/sandboxes${query({ status })}`);
|
|
127
|
+
return r.sandboxes;
|
|
128
|
+
}
|
|
129
|
+
async snapshots() {
|
|
130
|
+
return (await this.request("GET", "/snapshots")).snapshots;
|
|
131
|
+
}
|
|
132
|
+
async deleteSnapshot(id) {
|
|
133
|
+
return this.request("DELETE", `/snapshots/${enc(id)}`);
|
|
134
|
+
}
|
|
135
|
+
async reservations() {
|
|
136
|
+
return (await this.request("GET", "/reservations")).reservations;
|
|
137
|
+
}
|
|
138
|
+
async execution(id) {
|
|
139
|
+
return this.request("GET", `/executions/${enc(id)}`);
|
|
140
|
+
}
|
|
141
|
+
/** Your templates, and ours that can start now. */
|
|
142
|
+
async templates() {
|
|
143
|
+
return this.request("GET", "/templates");
|
|
144
|
+
}
|
|
145
|
+
/** One of your templates by id or name, with its recent builds. */
|
|
146
|
+
async template(idOrName) {
|
|
147
|
+
return this.request("GET", `/templates/${enc(idOrName)}`);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Builds your own template from a Dockerfile. Its last stage must start FROM
|
|
151
|
+
* one of ours (quietrobot/base, quietrobot/browser, ...). There is no build
|
|
152
|
+
* context: fetch files with RUN or ADD a URL. Builds are billed at Standard
|
|
153
|
+
* rates. wait: true (the default) waits until the build is ready or fails.
|
|
154
|
+
*/
|
|
155
|
+
async createTemplate(opts) {
|
|
156
|
+
const { wait = true, timeoutMs, ...body } = opts;
|
|
157
|
+
const t = await this.request("POST", "/templates", body);
|
|
158
|
+
return wait ? this.waitForTemplate(t.id, timeoutMs) : t;
|
|
159
|
+
}
|
|
160
|
+
/** Builds a template again, with a new Dockerfile or the same one. */
|
|
161
|
+
async rebuildTemplate(idOrName, dockerfile) {
|
|
162
|
+
return this.request("POST", `/templates/${enc(idOrName)}/builds`, dockerfile === undefined ? {} : { dockerfile });
|
|
163
|
+
}
|
|
164
|
+
async updateTemplate(idOrName, changes) {
|
|
165
|
+
return this.request("PATCH", `/templates/${enc(idOrName)}`, changes);
|
|
166
|
+
}
|
|
167
|
+
async deleteTemplate(idOrName) {
|
|
168
|
+
return this.request("DELETE", `/templates/${enc(idOrName)}`);
|
|
169
|
+
}
|
|
170
|
+
/** A build and the end of its log. */
|
|
171
|
+
async templateBuild(id) {
|
|
172
|
+
return this.request("GET", `/template-builds/${enc(id)}`);
|
|
173
|
+
}
|
|
174
|
+
/** Waits until a template's build is ready (returns it) or failed (throws with the build's error). Default 30 minutes. */
|
|
175
|
+
async waitForTemplate(idOrName, timeoutMs = 30 * 60_000) {
|
|
176
|
+
const deadline = Date.now() + timeoutMs;
|
|
177
|
+
let delay = 2000;
|
|
178
|
+
for (;;) {
|
|
179
|
+
const t = await this.template(idOrName);
|
|
180
|
+
if (t.status === "ready")
|
|
181
|
+
return t;
|
|
182
|
+
if (t.status === "failed") {
|
|
183
|
+
const b = t.builds?.[0];
|
|
184
|
+
throw new SandboxesError(422, "build_failed", b?.error ?? `Template ${t.name} failed to build`);
|
|
185
|
+
}
|
|
186
|
+
if (Date.now() > deadline)
|
|
187
|
+
throw new SandboxesError(408, "build_timeout", `Template ${t.name} is still building`);
|
|
188
|
+
await sleep(delay);
|
|
189
|
+
delay = Math.min(delay * 1.5, 10_000);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Undoes a command: puts the sandbox's files back as they were just before
|
|
194
|
+
* it ran. Works for commands that were held for approval or ran with sudo,
|
|
195
|
+
* which save the files first (a setting on the dashboard's Policy page);
|
|
196
|
+
* others answer 409. The current files are saved as a snapshot first.
|
|
197
|
+
*/
|
|
198
|
+
async undo(executionId) {
|
|
199
|
+
return this.request("POST", `/executions/${enc(executionId)}/undo`);
|
|
200
|
+
}
|
|
201
|
+
/** This month's usage and limits, or the last `days` days. */
|
|
202
|
+
async usage(days) {
|
|
203
|
+
return this.request("GET", `/usage${query({ days })}`);
|
|
204
|
+
}
|
|
205
|
+
async audit(opts = {}) {
|
|
206
|
+
return (await this.request("GET", `/audit${query(opts)}`)).events;
|
|
207
|
+
}
|
|
208
|
+
/** @internal Waits while a command is held for approval (and, for a plain run, until it finishes). */
|
|
209
|
+
async settle(e, opts, until) {
|
|
210
|
+
if (e.status === "pending_approval") {
|
|
211
|
+
if (opts.waitForApproval === false)
|
|
212
|
+
return e;
|
|
213
|
+
opts.onPending?.(e);
|
|
214
|
+
}
|
|
215
|
+
const deadline = Date.now() + (opts.approvalTimeoutMs ?? 30 * 60_000);
|
|
216
|
+
let delay = 1000;
|
|
217
|
+
while (e.status === "pending_approval" || (until === "finished" && e.status === "running")) {
|
|
218
|
+
if (Date.now() > deadline)
|
|
219
|
+
throw new SandboxesError(408, "approval_timeout", `No decision on ${e.id} in time`);
|
|
220
|
+
await sleep(delay);
|
|
221
|
+
delay = Math.min(delay * 1.5, 5000);
|
|
222
|
+
e = await this.execution(e.id);
|
|
223
|
+
}
|
|
224
|
+
if (e.status === "denied")
|
|
225
|
+
throw new CommandDeniedError(e);
|
|
226
|
+
return e;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Checks a webhook request's signature (Standard Webhooks: the webhook-id,
|
|
231
|
+
* webhook-timestamp and webhook-signature headers) and returns its parsed
|
|
232
|
+
* body. Throws if the signature is wrong or the timestamp is more than five
|
|
233
|
+
* minutes away. Pass the raw body text, before any JSON parsing.
|
|
234
|
+
*/
|
|
235
|
+
export async function verifyWebhook(secret, headers, body, toleranceSec = 300) {
|
|
236
|
+
const h = (n) => {
|
|
237
|
+
const v = headers instanceof Headers ? headers.get(n) : headers[n];
|
|
238
|
+
return Array.isArray(v) ? v[0] : (v ?? undefined);
|
|
239
|
+
};
|
|
240
|
+
const id = h("webhook-id");
|
|
241
|
+
const ts = h("webhook-timestamp");
|
|
242
|
+
const sigs = h("webhook-signature");
|
|
243
|
+
if (!id || !ts || !sigs)
|
|
244
|
+
throw new SandboxesError(400, "bad_signature", "Missing webhook headers");
|
|
245
|
+
if (Math.abs(Date.now() / 1000 - Number(ts)) > toleranceSec)
|
|
246
|
+
throw new SandboxesError(400, "bad_signature", "Webhook timestamp is too far from now");
|
|
247
|
+
const raw = atob(secret.replace(/^whsec_/, ""));
|
|
248
|
+
const key = await crypto.subtle.importKey("raw", Uint8Array.from(raw, (c) => c.charCodeAt(0)), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
249
|
+
const mac = new Uint8Array(await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(`${id}.${ts}.${body}`)));
|
|
250
|
+
const expected = btoa(String.fromCharCode(...mac));
|
|
251
|
+
const ok = sigs.split(" ").some((s) => {
|
|
252
|
+
const [v, sig] = s.split(",");
|
|
253
|
+
if (v !== "v1" || !sig || sig.length !== expected.length)
|
|
254
|
+
return false;
|
|
255
|
+
let diff = 0;
|
|
256
|
+
for (let i = 0; i < sig.length; i++)
|
|
257
|
+
diff |= sig.charCodeAt(i) ^ expected.charCodeAt(i);
|
|
258
|
+
return diff === 0;
|
|
259
|
+
});
|
|
260
|
+
if (!ok)
|
|
261
|
+
throw new SandboxesError(400, "bad_signature", "Webhook signature does not match");
|
|
262
|
+
return JSON.parse(body);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* A command started with spawn() or terminal(): running in the background,
|
|
266
|
+
* output read as it arrives.
|
|
267
|
+
*/
|
|
268
|
+
export class Process {
|
|
269
|
+
client;
|
|
270
|
+
execution;
|
|
271
|
+
out = 0;
|
|
272
|
+
err = 0;
|
|
273
|
+
/** Bytes lost because they weren't read before the sandbox's buffer filled. */
|
|
274
|
+
missed = 0;
|
|
275
|
+
done = false;
|
|
276
|
+
exitCode = null;
|
|
277
|
+
constructor(client, execution) {
|
|
278
|
+
this.client = client;
|
|
279
|
+
this.execution = execution;
|
|
280
|
+
}
|
|
281
|
+
get id() {
|
|
282
|
+
return this.execution.id;
|
|
283
|
+
}
|
|
284
|
+
/** The next output, waiting up to waitMs (max 25 s) for some to arrive. */
|
|
285
|
+
async read(waitMs = 25_000) {
|
|
286
|
+
const c = await this.client.request("GET", `/executions/${enc(this.id)}/output${query({ out: this.out, err: this.err, wait: waitMs })}`);
|
|
287
|
+
this.out = c.out;
|
|
288
|
+
this.err = c.err;
|
|
289
|
+
this.missed += c.missed;
|
|
290
|
+
if (c.done) {
|
|
291
|
+
this.done = true;
|
|
292
|
+
this.exitCode = c.exitCode;
|
|
293
|
+
}
|
|
294
|
+
return c;
|
|
295
|
+
}
|
|
296
|
+
async *[Symbol.asyncIterator]() {
|
|
297
|
+
while (!this.done) {
|
|
298
|
+
const t = Date.now();
|
|
299
|
+
const c = await this.read();
|
|
300
|
+
if (c.stdout)
|
|
301
|
+
yield { stream: "stdout", data: c.stdout };
|
|
302
|
+
if (c.stderr)
|
|
303
|
+
yield { stream: "stderr", data: c.stderr };
|
|
304
|
+
// A paused sandbox answers at once with nothing new; don't spin.
|
|
305
|
+
if (!c.stdout && !c.stderr && !c.done && Date.now() - t < 1000)
|
|
306
|
+
await sleep(1000);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
/** Waits for the end, passing output along as it arrives. stdout and stderr hold everything read. */
|
|
310
|
+
async wait(opts = {}) {
|
|
311
|
+
let stdout = "";
|
|
312
|
+
let stderr = "";
|
|
313
|
+
for await (const { stream, data } of this) {
|
|
314
|
+
if (stream === "stdout") {
|
|
315
|
+
stdout += data;
|
|
316
|
+
opts.onStdout?.(data);
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
stderr += data;
|
|
320
|
+
opts.onStderr?.(data);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
let e = await this.client.execution(this.id);
|
|
324
|
+
// The row is finished by whoever reads the end first; give it a moment.
|
|
325
|
+
for (let i = 0; i < 10 && e.status === "running"; i++) {
|
|
326
|
+
await sleep(300);
|
|
327
|
+
e = await this.client.execution(this.id);
|
|
328
|
+
}
|
|
329
|
+
this.execution = { ...e, stdout, stderr, exitCode: e.exitCode ?? this.exitCode };
|
|
330
|
+
return this.execution;
|
|
331
|
+
}
|
|
332
|
+
/** Sends input. close ends stdin (a terminal gets ^D). */
|
|
333
|
+
async sendStdin(data, close = false) {
|
|
334
|
+
await this.client.request("POST", `/executions/${enc(this.id)}/stdin`, { data, close });
|
|
335
|
+
}
|
|
336
|
+
async closeStdin() {
|
|
337
|
+
await this.sendStdin("", true);
|
|
338
|
+
}
|
|
339
|
+
/** Stops it and what it started. */
|
|
340
|
+
async kill(signal = "TERM") {
|
|
341
|
+
this.execution = await this.client.request("POST", `/executions/${enc(this.id)}/kill`, { signal });
|
|
342
|
+
return this.execution;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
/** An interactive shell on a pseudo-terminal. Write with sendStdin(), read with read() or for-await. */
|
|
346
|
+
export class Terminal extends Process {
|
|
347
|
+
async resize(cols, rows) {
|
|
348
|
+
await this.client.request("POST", `/executions/${enc(this.id)}/resize`, { cols, rows });
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
const KERNEL = "~/.qr/kernel1.py";
|
|
352
|
+
export class Sandbox {
|
|
353
|
+
client;
|
|
354
|
+
info;
|
|
355
|
+
kernelReady = false;
|
|
356
|
+
constructor(client, info) {
|
|
357
|
+
this.client = client;
|
|
358
|
+
this.info = info;
|
|
359
|
+
}
|
|
360
|
+
get id() {
|
|
361
|
+
return this.info.id;
|
|
362
|
+
}
|
|
363
|
+
path(p = "") {
|
|
364
|
+
return `/sandboxes/${enc(this.id)}${p}`;
|
|
365
|
+
}
|
|
366
|
+
async refresh() {
|
|
367
|
+
this.info = await this.client.request("GET", this.path());
|
|
368
|
+
return this.info;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Runs a shell command and waits for it. If a policy rule holds it for
|
|
372
|
+
* approval, waits until a person decides (unless waitForApproval is false).
|
|
373
|
+
* Throws CommandDeniedError if they deny it. With onStdout or onStderr, or a
|
|
374
|
+
* timeout over 5 minutes, output streams back while it runs.
|
|
375
|
+
*/
|
|
376
|
+
async exec(cmd, opts = {}) {
|
|
377
|
+
if (opts.onStdout || opts.onStderr || (opts.timeoutMs ?? 0) > 300_000) {
|
|
378
|
+
const p = await this.spawn(cmd, { ...opts, timeoutMs: opts.timeoutMs ?? 60_000 });
|
|
379
|
+
if (p.execution.status !== "running")
|
|
380
|
+
return p.execution;
|
|
381
|
+
return p.wait(opts);
|
|
382
|
+
}
|
|
383
|
+
const e = await this.client.request("POST", this.path("/exec"), {
|
|
384
|
+
cmd,
|
|
385
|
+
cwd: homePath(opts.cwd),
|
|
386
|
+
env: opts.env,
|
|
387
|
+
timeoutMs: opts.timeoutMs,
|
|
388
|
+
stdin: opts.stdin,
|
|
389
|
+
});
|
|
390
|
+
// "running" means the API answered before a long command finished; always wait for it.
|
|
391
|
+
return this.client.settle(e, opts, "finished");
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Starts a command in the background and returns at once. Read its output
|
|
395
|
+
* with for-await, read() or wait(); write to it with sendStdin() when
|
|
396
|
+
* started with interactive: true.
|
|
397
|
+
*/
|
|
398
|
+
async spawn(cmd, opts = {}) {
|
|
399
|
+
let e = await this.client.request("POST", this.path("/exec"), {
|
|
400
|
+
cmd,
|
|
401
|
+
cwd: homePath(opts.cwd),
|
|
402
|
+
env: opts.env,
|
|
403
|
+
timeoutMs: opts.timeoutMs,
|
|
404
|
+
stdin: opts.stdin,
|
|
405
|
+
interactive: opts.interactive,
|
|
406
|
+
background: true,
|
|
407
|
+
});
|
|
408
|
+
e = await this.client.settle(e, opts, "approved");
|
|
409
|
+
return new Process(this.client, e);
|
|
410
|
+
}
|
|
411
|
+
/** Opens an interactive shell on a pseudo-terminal. */
|
|
412
|
+
async terminal(opts = {}) {
|
|
413
|
+
let e = await this.client.request("POST", this.path("/terminal"), {
|
|
414
|
+
cols: opts.cols ?? 100,
|
|
415
|
+
rows: opts.rows ?? 30,
|
|
416
|
+
cmd: opts.cmd,
|
|
417
|
+
cwd: homePath(opts.cwd),
|
|
418
|
+
env: opts.env,
|
|
419
|
+
});
|
|
420
|
+
e = await this.client.settle(e, opts, "approved");
|
|
421
|
+
return new Terminal(this.client, e);
|
|
422
|
+
}
|
|
423
|
+
/** A command started earlier with spawn() or terminal(), by its execution id. */
|
|
424
|
+
async process(executionId) {
|
|
425
|
+
return new Process(this.client, await this.client.execution(executionId));
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Runs Python in a kernel that keeps its variables between calls, like a
|
|
429
|
+
* notebook. The code is part of the command, so policy rules and the audit
|
|
430
|
+
* log see every cell. Returns printed output, the last expression's value
|
|
431
|
+
* and any matplotlib figures as PNG.
|
|
432
|
+
*/
|
|
433
|
+
async runCode(code, opts = {}) {
|
|
434
|
+
if (!this.kernelReady) {
|
|
435
|
+
await this.exec(`mkdir -p ~/.qr && echo '${KERNEL_B64}' | base64 -d > ${KERNEL}.tmp && mv ${KERNEL}.tmp ${KERNEL}`, {
|
|
436
|
+
waitForApproval: opts.waitForApproval,
|
|
437
|
+
approvalTimeoutMs: opts.approvalTimeoutMs,
|
|
438
|
+
onPending: opts.onPending,
|
|
439
|
+
});
|
|
440
|
+
this.kernelReady = true;
|
|
441
|
+
}
|
|
442
|
+
let tag = "QR_CELL";
|
|
443
|
+
while (code.includes(tag))
|
|
444
|
+
tag += "_";
|
|
445
|
+
const e = await this.exec(`python3 ${KERNEL} run <<'${tag}'\n${code}\n${tag}`, { timeoutMs: 300_000, ...opts });
|
|
446
|
+
const line = (e.stdout ?? "").trim().split("\n").pop() ?? "";
|
|
447
|
+
let r;
|
|
448
|
+
try {
|
|
449
|
+
r = JSON.parse(line);
|
|
450
|
+
}
|
|
451
|
+
catch {
|
|
452
|
+
const why = (e.stderr || e.stdout || e.status).trim();
|
|
453
|
+
r = { stdout: e.stdout ?? "", stderr: e.stderr ?? "", results: [], error: { name: "KernelError", value: why, traceback: e.stderr ?? "" } };
|
|
454
|
+
}
|
|
455
|
+
return { ...r, execution: e };
|
|
456
|
+
}
|
|
457
|
+
/** Starts a fresh kernel for runCode(): variables are cleared. */
|
|
458
|
+
async restartCode() {
|
|
459
|
+
if (this.kernelReady)
|
|
460
|
+
await this.exec(`python3 ${KERNEL} restart`);
|
|
461
|
+
}
|
|
462
|
+
files = {
|
|
463
|
+
read: (path) => this.client.request("GET", this.path(`/files${query({ path })}`), undefined, true),
|
|
464
|
+
readText: async (path) => new TextDecoder().decode(await this.files.read(path)),
|
|
465
|
+
write: (path, data) => this.client.request("PUT", this.path(`/files${query({ path })}`), data),
|
|
466
|
+
remove: (path) => this.client.request("DELETE", this.path(`/files${query({ path })}`)),
|
|
467
|
+
list: (path) => this.client.request("GET", this.path(`/files/list${query({ path })}`)),
|
|
468
|
+
};
|
|
469
|
+
/**
|
|
470
|
+
* Preview URLs for web servers in the sandbox: https://<port>-<id>.quietrobot.dev.
|
|
471
|
+
* Private ports need the token or the share link; public ones are open to anyone.
|
|
472
|
+
*/
|
|
473
|
+
ports = {
|
|
474
|
+
list: async () => {
|
|
475
|
+
const r = await this.client.request("GET", this.path("/ports"));
|
|
476
|
+
if (r.domain)
|
|
477
|
+
this.client.previewDomain = r.domain;
|
|
478
|
+
return r.ports;
|
|
479
|
+
},
|
|
480
|
+
/** Replaces the exposed ports. rotate: true revokes every private link shared before. */
|
|
481
|
+
set: async (ports, opts = {}) => {
|
|
482
|
+
const r = await this.client.request("PUT", this.path("/ports"), {
|
|
483
|
+
ports: ports.map((p) => ({ port: p.port, access: p.access ?? "private" })),
|
|
484
|
+
rotate: opts.rotate,
|
|
485
|
+
});
|
|
486
|
+
if (r.domain)
|
|
487
|
+
this.client.previewDomain = r.domain;
|
|
488
|
+
return r.ports;
|
|
489
|
+
},
|
|
490
|
+
/** Exposes one port (keeping the others) and returns its URL. */
|
|
491
|
+
expose: async (port, access = "private") => {
|
|
492
|
+
const cur = (await this.ports.list()).filter((p) => p.port !== port).map((p) => ({ port: p.port, access: p.access }));
|
|
493
|
+
const next = await this.ports.set([...cur, { port, access }]);
|
|
494
|
+
return next.find((p) => p.port === port);
|
|
495
|
+
},
|
|
496
|
+
/** Stops exposing one port. */
|
|
497
|
+
close: async (port) => {
|
|
498
|
+
const cur = (await this.ports.list()).filter((p) => p.port !== port).map((p) => ({ port: p.port, access: p.access }));
|
|
499
|
+
return this.ports.set(cur);
|
|
500
|
+
},
|
|
501
|
+
};
|
|
502
|
+
/** The preview host for a port (no scheme), whether or not it is exposed yet. */
|
|
503
|
+
host(port) {
|
|
504
|
+
return `${port}-${this.id.replace(/_/g, "-")}.${this.client.previewDomain}`;
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Freezes the sandbox. Memory, files and running processes are kept, and
|
|
508
|
+
* paused time isn't billed. Fails with 409 paused_storage_full when the
|
|
509
|
+
* organization's paused sandboxes already hold the disk its plan allows.
|
|
510
|
+
*/
|
|
511
|
+
async pause() {
|
|
512
|
+
this.info = await this.client.request("POST", this.path("/pause"));
|
|
513
|
+
return this.info;
|
|
514
|
+
}
|
|
515
|
+
/** Resumes a paused sandbox with the session time it had left. */
|
|
516
|
+
async resume() {
|
|
517
|
+
this.info = await this.client.request("POST", this.path("/resume"));
|
|
518
|
+
return this.info;
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Saves a copy of the sandbox's files (its home folder, including packages
|
|
522
|
+
* installed there). The sandbox keeps running. Start new sandboxes from it
|
|
523
|
+
* with create({ snapshotId }).
|
|
524
|
+
*/
|
|
525
|
+
async snapshot(name) {
|
|
526
|
+
return this.client.request("POST", this.path("/snapshots"), { name });
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Snapshots this sandbox (or uses snapshotId) and starts up to 10 copies of it.
|
|
530
|
+
* cpuClass, cpus and memoryMb give the copies a different size: this is how a
|
|
531
|
+
* sandbox is resized (fork, then destroy the original). egress replaces the
|
|
532
|
+
* network rules, for example wider than a locked original allows.
|
|
533
|
+
*/
|
|
534
|
+
async fork(opts = {}) {
|
|
535
|
+
const r = await this.client.request("POST", this.path("/fork"), opts);
|
|
536
|
+
return { snapshot: r.snapshot, sandboxes: r.sandboxes.map((s) => new Sandbox(this.client, s)), errors: r.errors ?? [] };
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Gives this sandbox a new size. A running or paused sandbox can't change size in
|
|
540
|
+
* place, so this copies it (fork with the new size), destroys the original and
|
|
541
|
+
* returns the copy: a new id, the same files, name and rules. Processes and memory
|
|
542
|
+
* aren't carried over. A paused original gives a paused copy.
|
|
543
|
+
*/
|
|
544
|
+
async resize(size) {
|
|
545
|
+
if (!size.cpuClass && !size.cpus && !size.memoryMb)
|
|
546
|
+
throw new Error("resize: give cpuClass, cpus or memoryMb");
|
|
547
|
+
const wasPaused = (await this.refresh()).status === "paused";
|
|
548
|
+
const r = await this.fork({ name: this.info.name ?? undefined, cpuClass: size.cpuClass, cpus: size.cpus, memoryMb: size.memoryMb });
|
|
549
|
+
const copy = r.sandboxes[0];
|
|
550
|
+
if (!copy)
|
|
551
|
+
throw new Error("resize: the resized copy couldn't be started; the original is unchanged");
|
|
552
|
+
await this.destroy();
|
|
553
|
+
if (wasPaused)
|
|
554
|
+
await copy.pause();
|
|
555
|
+
return copy;
|
|
556
|
+
}
|
|
557
|
+
/** Puts the files back as they were in a snapshot (the latest one by default). saveCurrent keeps a snapshot of now first. */
|
|
558
|
+
async rewind(opts = {}) {
|
|
559
|
+
const r = await this.client.request("POST", this.path("/rewind"), opts);
|
|
560
|
+
this.info = r.sandbox;
|
|
561
|
+
this.kernelReady = false;
|
|
562
|
+
return r;
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Changes the network rules while the sandbox runs. Fields left out keep their value.
|
|
566
|
+
* Can widen up to the sandbox's maxMode; past it (a locked sandbox), 409 egress_too_wide: fork it with the new egress.
|
|
567
|
+
*/
|
|
568
|
+
async setEgress(egress) {
|
|
569
|
+
this.info = await this.client.request("PUT", this.path("/egress"), egress);
|
|
570
|
+
return this.info;
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* Learn mode: records the hosts the sandbox reaches so you can turn them
|
|
574
|
+
* into allow rules. Then read learnedEgress() and either applyLearnedEgress()
|
|
575
|
+
* or stopLearningEgress() to put the old rules back.
|
|
576
|
+
*/
|
|
577
|
+
async learnEgress() {
|
|
578
|
+
this.info = await this.client.request("POST", this.path("/egress/learn"));
|
|
579
|
+
return this.info;
|
|
580
|
+
}
|
|
581
|
+
async learnedEgress() {
|
|
582
|
+
return this.client.request("GET", this.path("/egress/learn"));
|
|
583
|
+
}
|
|
584
|
+
/** Stops learn mode and puts the old rules back. */
|
|
585
|
+
async stopLearningEgress() {
|
|
586
|
+
this.info = await this.client.request("DELETE", this.path("/egress/learn"));
|
|
587
|
+
return this.info;
|
|
588
|
+
}
|
|
589
|
+
/** Stops learn mode and allows only these hosts (by default, every suggestion). */
|
|
590
|
+
async applyLearnedEgress(allow) {
|
|
591
|
+
if (!allow)
|
|
592
|
+
allow = (await this.learnedEgress()).suggestions.map((s) => s.rule);
|
|
593
|
+
this.info = await this.client.request("POST", this.path("/egress/learn/apply"), { allow });
|
|
594
|
+
return this.info;
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Caps what this sandbox may spend, in dollars (null for none). An API key
|
|
598
|
+
* may only lower the cap; raising or removing it needs a person in the dashboard.
|
|
599
|
+
*/
|
|
600
|
+
async setSpendCap(capUsd) {
|
|
601
|
+
this.info = await this.client.request("PUT", this.path("/spend-cap"), { capUsd });
|
|
602
|
+
return this.info;
|
|
603
|
+
}
|
|
604
|
+
/** What the agent did: counts, every approval and who decided it, hosts reached and blocked, files and the timeline. Written from the audit log, no AI model. */
|
|
605
|
+
async report() {
|
|
606
|
+
return this.client.request("GET", this.path("/report"));
|
|
607
|
+
}
|
|
608
|
+
/** The same report as a PDF file. */
|
|
609
|
+
async reportPdf() {
|
|
610
|
+
return this.client.request("GET", this.path(`/report${query({ format: "pdf" })}`), undefined, true);
|
|
611
|
+
}
|
|
612
|
+
/** The sandbox's image and the exact package versions in it. */
|
|
613
|
+
async image() {
|
|
614
|
+
return this.client.request("GET", this.path("/image"));
|
|
615
|
+
}
|
|
616
|
+
/** Resets the deadline to now + timeoutSec. */
|
|
617
|
+
async setTimeout(timeoutSec) {
|
|
618
|
+
this.info = await this.client.request("POST", this.path("/timeout"), { timeoutSec });
|
|
619
|
+
return this.info;
|
|
620
|
+
}
|
|
621
|
+
/** CPU, memory, disk, runtime, storage and egress, with readings over the last `hours` (default 24, up to 168). */
|
|
622
|
+
async metrics(hours) {
|
|
623
|
+
return this.client.request("GET", this.path(`/metrics${query({ hours })}`));
|
|
624
|
+
}
|
|
625
|
+
/** Saves the attached volumes now (they're also saved on pause, stop and near the deadline). */
|
|
626
|
+
async syncVolumes() {
|
|
627
|
+
return (await this.client.request("POST", this.path("/volumes/sync"))).volumes;
|
|
628
|
+
}
|
|
629
|
+
async executions() {
|
|
630
|
+
return (await this.client.request("GET", this.path("/executions"))).executions;
|
|
631
|
+
}
|
|
632
|
+
async audit() {
|
|
633
|
+
return (await this.client.request("GET", this.path("/audit"))).events;
|
|
634
|
+
}
|
|
635
|
+
async destroy() {
|
|
636
|
+
this.info = await this.client.request("DELETE", this.path());
|
|
637
|
+
return this.info;
|
|
638
|
+
}
|
|
639
|
+
}
|
package/dist/kernel.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const KERNEL_B64 = "IiIiQSBzbWFsbCBwZXJzaXN0ZW50IFB5dGhvbiBrZXJuZWwgdGhhdCBydW5zIGluc2lkZSBhIHNhbmRib3guCgpUaGUgU0RLcycgcnVuX2NvZGUoKSAvIHJ1bkNvZGUoKSBjb3BpZXMgdGhpcyBmaWxlIGludG8gdGhlIHNhbmRib3ggb25jZSBhbmQKdGhlbiBydW5zIGVhY2ggY2VsbCB3aXRoIGEgcGxhaW4gY29tbWFuZDoKCiAgICBweXRob24zIH4vLnFyL2tlcm5lbC5weSBydW4gPDwnUVJfQ0VMTCcKICAgIC4uLmNvZGUuLi4KICAgIFFSX0NFTEwKClRoZSBmaXJzdCBjYWxsIHN0YXJ0cyBhIHNlcnZlciBwcm9jZXNzIHRoYXQga2VlcHMgdGhlIHZhcmlhYmxlcyBiZXR3ZWVuCmNlbGxzLCBzbyBhIG5vdGVib29rLXN0eWxlIHNlc3Npb24gd29ya3MgdGhlIHdheSBKdXB5dGVyIGRvZXMuIFRoZSBjb2RlIGlzIGluCnRoZSBjb21tYW5kIGl0c2VsZiwgc28gdGhlIHNhbmRib3gncyBwb2xpY3kgYW5kIGF1ZGl0IGxvZyBz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PSB7InRleHQiOiByZXByKHZhbHVlKX0KICAgIGZvciBhdHRyLCBrZXkgaW4gKCgiX3JlcHJfaHRtbF8iLCAiaHRtbCIpLCAoIl9yZXByX3BuZ18iLCAicG5nIiksICgiX3JlcHJfanNvbl8iLCAianNvbiIpKToKICAgICAgICBmbiA9IGdldGF0dHIodmFsdWUsIGF0dHIsIE5vbmUpCiAgICAgICAgaWYgY2FsbGFibGUoZm4pOgogICAgICAgICAgICB0cnk6CiAgICAgICAgICAgICAgICB2ID0gZm4oKQogICAgICAgICAgICBleGNlcHQgRXhjZXB0aW9uOgogICAgICAgICAgICAgICAgY29udGludWUKICAgICAgICAgICAgaWYgdiBpcyBOb25lOgogICAgICAgICAgICAgICAgY29udGludWUKICAgICAgICAgICAgaWYga2V5ID09ICJwbmciIGFuZCBpc2luc3RhbmNlKHYsIGJ5dGVzKToKICAgICAgICAgICAgICAgIHYgPSBiYXNlNjQuYjY0ZW5jb2RlKHYpLmRlY29kZSgpCiAgICAgICAgICAgIG91dFtrZXldID0gdgogICAgcmV0dXJuIG91dAoKCmRlZiBfZmlndXJlcygpOgogICAgIiIiUE5HcyBvZiBhbnkgb3BlbiBtYXRwbG90bGliIGZpZ3VyZXMsIHdoaWNoIGFyZSB0aGVuIGNsb3NlZC4iIiIKICAgIHBsdCA9IHN5cy5tb2R1bGVzLmdldCgibWF0cGxvdGxpYi5weXBsb3QiKQogICAgaWYgcGx0IGlzIE5vbmU6CiAgICAgICAgcmV0dXJuIFtdCiAgICBvdXQgPSBbXQogICAgZm9yIG51bSBpbiBwbHQuZ2V0X2ZpZ251bXMoKToKICAgICAgICBmaWcgPSBwbHQuZmlndXJlKG51bSkKICAgICAgICBidWYgPSBpby5CeXRlc0lPKCkKICAgICAgICB0cnk6CiAgICAgICAgICAgIGZpZy5zYXZlZmlnKGJ1ZiwgZm9ybWF0PSJwbmciLCBiYm94X2luY2hlcz0idGlnaHQiKQogICAgICAgICAgICBvdXQuYXBwZW5kKHsidGV4dCI6IC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FsdWUgPSBldmFsKGNvbXBpbGUobGFzdCwgIjxjZWxsPiIsICJldmFsIiksIHNlbGYuZ2xvYmFscykKICAgICAgICAgICAgICAgICAgICBpZiB2YWx1ZSBpcyBub3QgTm9uZToKICAgICAgICAgICAgICAgICAgICAgICAgc2VsZi5nbG9iYWxzWyJfIl0gPSB2YWx1ZQogICAgICAgICAgICAgICAgICAgICAgICByZXN1bHRzLmFwcGVuZChfcmljaCh2YWx1ZSkpCiAgICAgICAgICAgIGV4Y2VwdCBCYXNlRXhjZXB0aW9uIGFzIGU6ICAjIGEgY2VsbCBtYXkgcmFpc2UgYW55dGhpbmcsIFN5c3RlbUV4aXQgaW5jbHVkZWQKICAgICAgICAgICAgICAgIGVycm9yID0gewogICAgICAgICAgICAgICAgICAgICJuYW1lIjogdHlwZShlKS5fX25hbWVfXywKICAgICAgICAgICAgICAgICAgICAidmFsdWUiOiBzdHIoZSksCiAgICAgICAgICAgICAgICAgICAgInRyYWNlYmFjayI6ICIiLmpvaW4odHJhY2ViYWNrLmZvcm1hdF9leGNlcHRpb24odHlwZShlKSwgZSwgZS5fX3RyYWNlYmFja19fKSksCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIHJlc3VsdHMuZXh0ZW5kKF9maWd1cmVzKCkpCiAgICAgICAgcmV0dXJuIHsic3Rkb3V0Ijogc3Rkb3V0LmdldHZhbHVlKCksICJzdGRlcnIiOiBzdGRlcnIuZ2V0dmFsdWUoKSwgInJlc3VsdHMiOiByZXN1bHRzLCAiZXJyb3IiOiBlcnJvcn0KCgpkZWYgc2VydmUoKToKICAgIG9zLm1ha2VkaXJzKG9zLnBhdGguZGlybmFtZShTT0NLKSwgZXhpc3Rfb2s9VHJ1ZSkKICAgIG9zLmVudmlyb24uc2V0ZGVmYXVsdCgiTVBMQkFDS0VORCIsICJBZ2ciKQogICAgd2l0aCBjb250ZXh0bGliLnN1cHByZXNzKEZpbGVOb3RGb3VuZEVycm9yKToKICAgICAgICBvcy51bmxpbmsoU09DSykKICAgIGtlcm5lbCA9IEtlcm5lbCgpCiAgICBzcnYgPSBzb2NrZXQuc29ja2V0KHNvY2tldC5BRl9VTklYLCBzb2NrZXQuU09DS19TVFJFQU0pCiAgICBzcnYuYmluZChTT0NLKQogICAgb3MuY2htb2QoU09DSywgMG82MDApCiAgICBzcnYubGlzdGVuKDgpCiAgICB3aGlsZSBUcnVlOgogICAgICAgIGNvbm4sIF8gPSBzcnYuYWNjZXB0KCkKICAgICAgICB0cnk6CiAgICAgICAgICAgIGNvZGUgPSBfcmVjdl9hbGwoY29ubikuZGVjb2RlKCJ1dGYtOCIsICJyZXBsYWNlIikKICAgICAgICAgICAgaWYgY29kZSA9PSAiXDByZXN0YXJ0IjoKICAgICAgICAgICAgICAgICMgVGhlIG5leHQgY2VsbCBzdGFydHMgYSBmcmVzaCBrZXJuZWwgd2l0aCBubyB2YXJpYWJsZXMuCiAgICAgICAgICAgICAgICBzcnYuY2xvc2UoKQogICAgICAgICAgICAgICAgb3MudW5saW5rKFNPQ0spCiAgICAgICAgICAgICAgICBjb25uLnNlbmRhbGwoYid7InJlc3RhcnRlZCI6IHRydWV9JykKICAgICAgICAgICAgICAgIGNvbm4uY2xvc2UoKQogICAgICAgICAgICAgICAgb3MuX2V4aXQoMCkKICAgICAgICAgICAgY29ubi5zZW5kYWxsKGpzb24uZHVtcHMoa2VybmVsLnJ1bihjb2RlKSkuZW5jb2RlKCkpCiAgICAgICAgZXhjZXB0IEV4Y2VwdGlvbjoKICAgICAgICAgICAgcGFzcwogICAgICAgIGZpbmFsbHk6CiAgICAgICAgICAgIHdpdGggY29udGV4dGxpYi5zdXBwcmVzcyhFeGNlcHRpb24pOgogICAgICAgICAgICAgICAgY29ubi5jbG9zZSgpCgoKZGVmIF9jb25uZWN0KCk6CiAgICBzID0gc29ja2V0LnNvY2tldChzb2NrZXQuQUZfVU5JWCwgc29ja2V0LlNPQ0tfU1RSRUFNKQogICAgcy5jb25uZWN0KFNPQ0spCiAgICByZXR1cm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tYWluX18iOgogICAgbW9kZSA9IHN5cy5hcmd2WzFdIGlmIGxlbihzeXMuYXJndikgPiAxIGVsc2UgInJ1biIKICAgIGlmIG1vZGUgPT0gInNlcnZlIjoKICAgICAgICBzZXJ2ZSgpCiAgICBlbGlmIG1vZGUgPT0gInJlc3RhcnQiOgogICAgICAgIGNsaWVudCgiXDByZXN0YXJ0IikKICAgIGVsc2U6CiAgICAgICAgY2xpZW50KHN5cy5zdGRpbi5yZWFkKCkpCg==";
|
package/dist/kernel.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// Generated by scripts/sync-kernel.sh from python/src/quietrobot_sandboxes/_kernel.py. Do not edit.
|
|
2
|
+
export const KERNEL_B64 = "IiIiQSBzbWFsbCBwZXJzaXN0ZW50IFB5dGhvbiBrZXJuZWwgdGhhdCBydW5zIGluc2lkZSBhIHNhbmRib3guCgpUaGUgU0RLcycgcnVuX2NvZGUoKSAvIHJ1bkNvZGUoKSBjb3BpZXMgdGhpcyBmaWxlIGludG8gdGhlIHNhbmRib3ggb25jZSBhbmQKdGhlbiBydW5zIGVhY2ggY2VsbCB3aXRoIGEgcGxhaW4gY29tbWFuZDoKCiAgICBweXRob24zIH4vLnFyL2tlcm5lbC5weSBydW4gPDwnUVJfQ0VMTCcKICAgIC4uLmNvZGUuLi4KICAgIFFSX0NFTEwKClRoZSBmaXJzdCBjYWxsIHN0YXJ0cyBhIHNlcnZlciBwcm9jZXNzIHRoYXQga2VlcHMgdGhlIHZhcmlhYmxlcyBiZXR3ZWVuCmNlbGxzLCBzbyBhIG5vdGVib29rLXN0eWxlIHNlc3Npb24gd29ya3MgdGhlIHdheSBKdXB5dGVyIGRvZXMuIFRoZSBjb2RlIGlzIGluCnRoZSBjb21tYW5kIGl0c2VsZiwgc28gdGhlIHNhbmRib3gncyBwb2xpY3kgYW5kIGF1ZGl0IGxvZyBzZWUgZXZlcnkgY2VsbC4KCkVhY2ggY2VsbCBhbnN3ZXJzIG9uZSBKU09OIGx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3JlcHJfaHRtbF8iLCAiaHRtbCIpLCAoIl9yZXByX3BuZ18iLCAicG5nIiksICgiX3JlcHJfanNvbl8iLCAianNvbiIpKToKICAgICAgICBmbiA9IGdldGF0dHIodmFsdWUsIGF0dHIsIE5vbmUpCiAgICAgICAgaWYgY2FsbGFibGUoZm4pOgogICAgICAgICAgICB0cnk6CiAgICAgICAgICAgICAgICB2ID0gZm4oKQogICAgICAgICAgICBleGNlcHQgRXhjZXB0aW9uOgogICAgICAgICAgICAgICAgY29udGludWUKICAgICAgICAgICAgaWYgdiBpcyBOb25lOgogICAgICAgICAgICAgICAgY29udGludWUKICAgICAgICAgICAgaWYga2V5ID09ICJwbmciIGFuZCBpc2luc3RhbmNlKHYsIGJ5dGVzKToKICAgICAgICAgICAgICAgIHYgPSBiYXNlNjQuYjY0ZW5jb2RlKHYpLmRlY29kZSgpCiAgICAgICAgICAgIG91dFtrZXldID0gdgogICAgcmV0dXJuIG91dAoKCmRlZiBfZmlndXJlcygpOgogICAgIiIiUE5HcyBvZiBhbnkgb3BlbiBtYXRwbG90bGliIGZpZ3VyZXMsIHdoaWNoIGFyZSB0aGVuIGNsb3NlZC4iIiIKICAgIHBsdCA9IHN5cy5tb2R1bGVzLmdldCgibWF0cGxvdGxpYi5weXBsb3QiKQogICAgaWYgcGx0IGlzIE5vbmU6CiAgICAgICAgcmV0dXJuIFtdCiAgICBvdXQgPSBbXQogICAgZm9yIG51bSBpbiBwbHQuZ2V0X2ZpZ251bXMoKToKICAgICAgICBmaWcgPSBwbHQuZmlndXJlKG51bSkKICAgICAgICBidWYgPSBpby5CeXRlc0lPKCkKICAgICAgICB0cnk6CiAgICAgICAgICAgIGZpZy5zYXZlZmlnKGJ1ZiwgZm9ybWF0PSJwbmciLCBiYm94X2luY2hlcz0idGlnaHQiKQogICAgICAgICAgICBvdXQuYXBwZW5kKHsidGV4dCI6ICI8RmlndXJlPiIsICJwbmciOiBiYXNlNjQuYjY0ZW5jb2RlKGJ1Zi5nZXR2Y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YuZ2xvYmFscykKICAgICAgICAgICAgICAgICAgICBpZiB2YWx1ZSBpcyBub3QgTm9uZToKICAgICAgICAgICAgICAgICAgICAgICAgc2VsZi5nbG9iYWxzWyJfIl0gPSB2YWx1ZQogICAgICAgICAgICAgICAgICAgICAgICByZXN1bHRzLmFwcGVuZChfcmljaCh2YWx1ZSkpCiAgICAgICAgICAgIGV4Y2VwdCBCYXNlRXhjZXB0aW9uIGFzIGU6ICAjIGEgY2VsbCBtYXkgcmFpc2UgYW55dGhpbmcsIFN5c3RlbUV4aXQgaW5jbHVkZWQKICAgICAgICAgICAgICAgIGVycm9yID0gewogICAgICAgICAgICAgICAgICAgICJuYW1lIjogdHlwZShlKS5fX25hbWVfXywKICAgICAgICAgICAgICAgICAgICAidmFsdWUiOiBzdHIoZSksCiAgICAgICAgICAgICAgICAgICAgInRyYWNlYmFjayI6ICIiLmpvaW4odHJhY2ViYWNrLmZvcm1hdF9leGNlcHRpb24odHlwZShlKSwgZSwgZS5fX3RyYWNlYmFja19fKSksCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIHJlc3VsdHMuZXh0ZW5kKF9maWd1cmVzKCkpCiAgICAgICAgcmV0dXJuIHsic3Rkb3V0Ijogc3Rkb3V0LmdldHZhbHVlKCksICJzdGRlcnIiOiBzdGRlcnIuZ2V0dmFsdWUoKSwgInJlc3VsdHMiOiByZXN1bHRzLCAiZXJyb3IiOiBlcnJvcn0KCgpkZWYgc2VydmUoKToKICAgIG9zLm1ha2VkaXJzKG9zLnBhdGguZGlybmFtZShTT0NLKSwgZXhpc3Rfb2s9VHJ1ZSkKICAgIG9zLmVudmlyb24uc2V0ZGVmYXVsdCgiTVBMQkFDS0VORCIsICJBZ2ciKQogICAgd2l0aCBjb250ZXh0bGliLnN1cHByZXNzKEZpbGVOb3RGb3VuZEVycm9yKToKICAgICAgICBvcy51bmxpbmsoU09DSykKICAgIGtlcm5lbCA9IEtlcm5lbCgpCiAgICBzcnYgPSBzb2NrZXQuc29ja2V0KHNvY2tldC5BRl9VTklYLCBzb2NrZXQuU09DS19TVFJFQU0pCiAgICBzcnYuYmluZChTT0NLKQogICAgb3MuY2htb2QoU09DSywgMG82MDApCiAgICBzcnYubGlzdGVuKDgpCiAgICB3aGlsZSBUcnVlOgogICAgICAgIGNvbm4sIF8gPSBzcnYuYWNjZXB0KCkKICAgICAgICB0cnk6CiAgICAgICAgICAgIGNvZGUgPSBfcmVjdl9hbGwoY29ubikuZGVjb2RlKCJ1dGYtOCIsICJyZXBsYWNlIikKICAgICAgICAgICAgaWYgY29kZSA9PSAiXDByZXN0YXJ0IjoKICAgICAgICAgICAgICAgICMgVGhlIG5leHQgY2VsbCBzdGFydHMgYSBmcmVzaCBrZXJuZWwgd2l0aCBubyB2YXJpYWJsZXMuCiAgICAgICAgICAgICAgICBzcnYuY2xvc2UoKQogICAgICAgICAgICAgICAgb3MudW5saW5rKFNPQ0spCiAgICAgICAgICAgICAgICBjb25uLnNlbmRhbGwoYid7InJlc3RhcnRlZCI6IHRydWV9JykKICAgICAgICAgICAgICAgIGNvbm4uY2xvc2UoKQogICAgICAgICAgICAgICAgb3MuX2V4aXQoMCkKICAgICAgICAgICAgY29ubi5zZW5kYWxsKGpzb24uZHVtcHMoa2VybmVsLnJ1bihjb2RlKSkuZW5jb2RlKCkpCiAgICAgICAgZXhjZXB0IEV4Y2VwdGlvbjoKICAgICAgICAgICAgcGFzcwogICAgICAgIGZpbmFsbHk6CiAgICAgICAgICAgIHdpdGggY29udGV4dGxpYi5zdXBwcmVzcyhFeGNlcHRpb24pOgogICAgICAgICAgICAgICAgY29ubi5jbG9zZSgpCgoKZGVmIF9jb25uZWN0KCk6CiAgICBzID0gc29ja2V0LnNvY2tldChzb2NrZXQuQUZfVU5JWCwgc29ja2V0LlNPQ0tfU1RSRUFNKQogICAgcy5jb25uZWN0KFNPQ0spCiAgICByZXR1cm4gcwoKCmRlZiBfZW5zdXJlX3NlcnZlcigpOgogICAgdHJ5OgogICAgICAgIHJldHV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iAxIGVsc2UgInJ1biIKICAgIGlmIG1vZGUgPT0gInNlcnZlIjoKICAgICAgICBzZXJ2ZSgpCiAgICBlbGlmIG1vZGUgPT0gInJlc3RhcnQiOgogICAgICAgIGNsaWVudCgiXDByZXN0YXJ0IikKICAgIGVsc2U6CiAgICAgICAgY2xpZW50KHN5cy5zdGRpbi5yZWFkKCkpCg==";
|