@quietrobot/sandboxes 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -1
- package/dist/index.d.ts +200 -15
- package/dist/index.js +165 -16
- package/dist/kernel.d.ts +1 -1
- package/dist/kernel.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -85,13 +85,15 @@ const { entries } = await sbx.files.list("data");
|
|
|
85
85
|
await sbx.spawn("python3 -m http.server 8000");
|
|
86
86
|
const port = await sbx.ports.expose(8000); // private: port.shareUrl signs a browser in
|
|
87
87
|
await sbx.ports.expose(3000, "public"); // anyone with the URL
|
|
88
|
+
await sbx.ports.expose(5173, "public", { expiresIn: "24h" }); // stops answering in 24 hours
|
|
89
|
+
const link = await sbx.ports.link(8000, { expiresIn: "1h" }); // a private link that works for an hour
|
|
88
90
|
console.log(sbx.host(8000)); // 8000-sbx-....quietrobot.dev
|
|
89
91
|
|
|
90
92
|
await sbx.pause(); // memory and processes kept, not billed
|
|
91
93
|
await sbx.resume();
|
|
92
94
|
const snap = await sbx.snapshot("with-deps");
|
|
93
95
|
const copies = await sbx.fork({ count: 3 }); // three copies of this machine, as it is now
|
|
94
|
-
const
|
|
96
|
+
const big = await sbx.resize({ cpus: 4, memoryMb: 8192 }); // running or paused: a copy at the new size, original destroyed
|
|
95
97
|
await sbx.rewind({ snapshotId: snap.id }); // files back as they were in the snapshot
|
|
96
98
|
const fresh = await qr.create({ snapshotId: snap.id });
|
|
97
99
|
```
|
|
@@ -106,6 +108,18 @@ const fresh = await qr.create({ snapshotId: snap.id });
|
|
|
106
108
|
`ifExists`, `volumes`.
|
|
107
109
|
- Account: `qr.snapshots()`, `qr.deleteSnapshot(id)`, `qr.reservations()`,
|
|
108
110
|
`qr.usage(days)`, `qr.audit()`, `qr.secrets`, `qr.volumes`, `qr.webhooks`.
|
|
111
|
+
- Templates: start from one of ours with `template: "code-interpreter"` (or
|
|
112
|
+
`browser`, `desktop`, `coding-agent`, `fullstack-js`, `go`, `rust`,
|
|
113
|
+
`postgres`), or build your own from a Dockerfile:
|
|
114
|
+
`await qr.createTemplate({ name: "my-agent", dockerfile })` waits for the
|
|
115
|
+
build; also `qr.templates()`, `qr.template(name)`, `qr.rebuildTemplate()`,
|
|
116
|
+
`qr.updateTemplate()`, `qr.deleteTemplate()`, `qr.templateBuild(id)`.
|
|
117
|
+
- Outbound learn mode: `sbx.learnEgress()`, run your workload,
|
|
118
|
+
`sbx.learnedEgress()`, then `sbx.applyLearnedEgress()` (allow only what it
|
|
119
|
+
reached) or `sbx.stopLearningEgress()`.
|
|
120
|
+
- After the fact: `sbx.report()` (or `sbx.reportPdf()`) says what the agent
|
|
121
|
+
did; `qr.undo(executionId)` puts the files back to just before a command;
|
|
122
|
+
`sbx.image()` lists the exact package versions; `sbx.setSpendCap(dollars)`.
|
|
109
123
|
- Webhooks: `await verifyWebhook(secret, headers, rawBody)` checks the
|
|
110
124
|
signature and returns the event, or throws.
|
|
111
125
|
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,51 @@ export declare const DEFAULT_PREVIEW_DOMAIN = "quietrobot.dev";
|
|
|
13
13
|
/** The sandbox user's home folder. Relative paths (files and cwd) are relative to it. */
|
|
14
14
|
export declare const HOME = "/home/sandbox";
|
|
15
15
|
export type EgressMode = "deny" | "allowlist" | "open";
|
|
16
|
+
/** Our templates. Any name you gave one of your own templates works too. */
|
|
17
|
+
export type OfficialTemplate = "base" | "minimal" | "code-interpreter" | "browser" | "desktop" | "coding-agent" | "fullstack-js" | "go" | "rust" | "postgres";
|
|
18
|
+
/** A template you built from a Dockerfile (POST /templates). */
|
|
19
|
+
export interface TemplateInfo {
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
description: string | null;
|
|
23
|
+
/** ready once a build has finished; a template keeps its last good image while a rebuild runs. */
|
|
24
|
+
status: "building" | "ready" | "failed";
|
|
25
|
+
/** Which of our templates it's built on. */
|
|
26
|
+
base: OfficialTemplate | null;
|
|
27
|
+
sizeBytes: number | null;
|
|
28
|
+
warnings?: string[];
|
|
29
|
+
builds?: TemplateBuild[];
|
|
30
|
+
[k: string]: unknown;
|
|
31
|
+
}
|
|
32
|
+
export interface TemplateBuild {
|
|
33
|
+
id: string;
|
|
34
|
+
templateId: string | null;
|
|
35
|
+
status: "queued" | "building" | "sealing" | "ready" | "failed" | "cancelled";
|
|
36
|
+
base: string;
|
|
37
|
+
error: string | null;
|
|
38
|
+
sizeBytes: number | null;
|
|
39
|
+
/** The end of the build output (templateBuild() only). */
|
|
40
|
+
log?: string;
|
|
41
|
+
createdAt: string;
|
|
42
|
+
startedAt: string | null;
|
|
43
|
+
endedAt: string | null;
|
|
44
|
+
}
|
|
45
|
+
/** One of our templates, with its default size and the helper that starts its long-running part. */
|
|
46
|
+
export interface OfficialTemplateInfo {
|
|
47
|
+
name: OfficialTemplate;
|
|
48
|
+
title?: string;
|
|
49
|
+
[k: string]: unknown;
|
|
50
|
+
}
|
|
51
|
+
/** What learn mode has seen, as allow rules. */
|
|
52
|
+
export interface EgressSuggestions {
|
|
53
|
+
since: string | null;
|
|
54
|
+
how: "open" | "watch" | null;
|
|
55
|
+
suggestions: {
|
|
56
|
+
rule: string;
|
|
57
|
+
[k: string]: unknown;
|
|
58
|
+
}[];
|
|
59
|
+
[k: string]: unknown;
|
|
60
|
+
}
|
|
16
61
|
export interface SandboxInfo {
|
|
17
62
|
id: string;
|
|
18
63
|
name: string | null;
|
|
@@ -139,14 +184,72 @@ export interface VolumeInfo {
|
|
|
139
184
|
createdAt: string;
|
|
140
185
|
[k: string]: unknown;
|
|
141
186
|
}
|
|
187
|
+
/** What rewind() did. */
|
|
188
|
+
export interface RewindResult {
|
|
189
|
+
sandbox: SandboxInfo;
|
|
190
|
+
/** With saveCurrent: the files as they were just before, to rewind back to. */
|
|
191
|
+
savedSnapshot: SnapshotInfo | null;
|
|
192
|
+
/** Template services (such as Postgres) stopped for the rewind and started again. */
|
|
193
|
+
restarted?: string[];
|
|
194
|
+
/** A service that didn't start again, and the command that starts it. */
|
|
195
|
+
warnings?: string[];
|
|
196
|
+
}
|
|
142
197
|
export interface PortInfo {
|
|
143
198
|
port: number;
|
|
144
199
|
access: "private" | "public";
|
|
145
|
-
/** The
|
|
200
|
+
/** The address's name, e.g. "meeting-meter-k7qm2x". */
|
|
201
|
+
name?: string | null;
|
|
202
|
+
/** The preview URL, e.g. https://meeting-meter-k7qm2x.quietrobot.dev. A private one needs shareUrl or the token (header X-QR-Preview-Token). */
|
|
146
203
|
url: string;
|
|
147
|
-
/** Private
|
|
204
|
+
/** The link to give people. Private: a short link (https://s.quietrobot.dev/...) that signs a browser in and lands on url. Public: url. Null once the port has expired. */
|
|
148
205
|
shareUrl?: string | null;
|
|
149
206
|
token?: string | null;
|
|
207
|
+
/** When the port stops answering (ISO 8601), or null for never. */
|
|
208
|
+
expiresAt?: string | null;
|
|
209
|
+
/** Past expiresAt: every request to the port is refused. */
|
|
210
|
+
expired?: boolean;
|
|
211
|
+
}
|
|
212
|
+
/** When a shared port or link stops working: a duration ("30m", "1h", "24h", "7d", "2w", or seconds) or a time. */
|
|
213
|
+
export type Expiry = {
|
|
214
|
+
expiresIn: string | number;
|
|
215
|
+
} | {
|
|
216
|
+
expiresAt: string | Date;
|
|
217
|
+
};
|
|
218
|
+
/** One port to share. Leave expiresIn and expiresAt out to keep the port's current expiry (none for a new port); expiresAt: null lifts it. */
|
|
219
|
+
export interface PortSpec {
|
|
220
|
+
port: number;
|
|
221
|
+
access?: "private" | "public";
|
|
222
|
+
/** Words for the address, such as "meeting-meter" (a short random tail is added). Left out: the port keeps its address. */
|
|
223
|
+
name?: string;
|
|
224
|
+
expiresIn?: string | number;
|
|
225
|
+
expiresAt?: string | Date | null;
|
|
226
|
+
}
|
|
227
|
+
/** expose() options: the words of the address, and when it stops answering. */
|
|
228
|
+
export interface ExposeOptions {
|
|
229
|
+
name?: string;
|
|
230
|
+
expiresIn?: string | number;
|
|
231
|
+
expiresAt?: string | Date | null;
|
|
232
|
+
}
|
|
233
|
+
/** One of a private port's short links, from ports.links(). */
|
|
234
|
+
export interface PortLinkInfo {
|
|
235
|
+
code: string;
|
|
236
|
+
shareUrl: string;
|
|
237
|
+
/** The port's own link (its shareUrl); revoking it gives the port a new one. */
|
|
238
|
+
standing: boolean;
|
|
239
|
+
expiresAt: string | null;
|
|
240
|
+
expired: boolean;
|
|
241
|
+
createdAt: string;
|
|
242
|
+
}
|
|
243
|
+
/** A private link to one port, from ports.link(). */
|
|
244
|
+
export interface PortLink {
|
|
245
|
+
port: number;
|
|
246
|
+
/** The link's code, for ports.revokeLink(). */
|
|
247
|
+
code: string;
|
|
248
|
+
url: string;
|
|
249
|
+
shareUrl: string;
|
|
250
|
+
token: string;
|
|
251
|
+
/** When the link stops working: the time asked for, or the port's own expiry if sooner. */
|
|
252
|
+
expiresAt: string | null;
|
|
150
253
|
}
|
|
151
254
|
export interface WebhookInfo {
|
|
152
255
|
id: string;
|
|
@@ -182,7 +285,8 @@ export interface CodeRun {
|
|
|
182
285
|
}
|
|
183
286
|
export interface CreateOptions {
|
|
184
287
|
name?: string;
|
|
185
|
-
|
|
288
|
+
/** One of ours ("base" by default, or "code-interpreter", "browser", ...) or the name of one you built. */
|
|
289
|
+
template?: OfficialTemplate | (string & {});
|
|
186
290
|
/** standard = shared CPU (cheaper), performance = dedicated CPU (Pay as you go with a card). */
|
|
187
291
|
cpuClass?: "standard" | "performance";
|
|
188
292
|
cpus?: 1 | 2 | 4 | 8 | 16;
|
|
@@ -369,6 +473,48 @@ export declare class Sandboxes {
|
|
|
369
473
|
deleteSnapshot(id: string): Promise<SnapshotInfo>;
|
|
370
474
|
reservations(): Promise<Reservation[]>;
|
|
371
475
|
execution(id: string): Promise<Execution>;
|
|
476
|
+
/** Your templates, and ours that can start now. */
|
|
477
|
+
templates(): Promise<{
|
|
478
|
+
templates: TemplateInfo[];
|
|
479
|
+
official: OfficialTemplateInfo[];
|
|
480
|
+
}>;
|
|
481
|
+
/** One of your templates by id or name, with its recent builds. */
|
|
482
|
+
template(idOrName: string): Promise<TemplateInfo>;
|
|
483
|
+
/**
|
|
484
|
+
* Builds your own template from a Dockerfile. Its last stage must start FROM
|
|
485
|
+
* one of ours (quietrobot/base, quietrobot/browser, ...). There is no build
|
|
486
|
+
* context: fetch files with RUN or ADD a URL. Builds are billed at Standard
|
|
487
|
+
* rates. wait: true (the default) waits until the build is ready or fails.
|
|
488
|
+
*/
|
|
489
|
+
createTemplate(opts: {
|
|
490
|
+
name: string;
|
|
491
|
+
dockerfile: string;
|
|
492
|
+
description?: string;
|
|
493
|
+
warmPool?: number;
|
|
494
|
+
wait?: boolean;
|
|
495
|
+
timeoutMs?: number;
|
|
496
|
+
}): Promise<TemplateInfo>;
|
|
497
|
+
/** Builds a template again, with a new Dockerfile or the same one. */
|
|
498
|
+
rebuildTemplate(idOrName: string, dockerfile?: string): Promise<TemplateBuild>;
|
|
499
|
+
updateTemplate(idOrName: string, changes: {
|
|
500
|
+
description?: string | null;
|
|
501
|
+
warmPool?: number;
|
|
502
|
+
}): Promise<TemplateInfo>;
|
|
503
|
+
deleteTemplate(idOrName: string): Promise<TemplateInfo>;
|
|
504
|
+
/** A build and the end of its log. */
|
|
505
|
+
templateBuild(id: string): Promise<TemplateBuild>;
|
|
506
|
+
/** Waits until a template's build is ready (returns it) or failed (throws with the build's error). Default 30 minutes. */
|
|
507
|
+
waitForTemplate(idOrName: string, timeoutMs?: number): Promise<TemplateInfo>;
|
|
508
|
+
/**
|
|
509
|
+
* Undoes a command: puts the sandbox's files back as they were just before
|
|
510
|
+
* it ran. Works for commands that were held for approval or ran with sudo,
|
|
511
|
+
* which save the files first (a setting on the dashboard's Policy page);
|
|
512
|
+
* others answer 409. The current files are saved as a snapshot first.
|
|
513
|
+
*/
|
|
514
|
+
undo(executionId: string): Promise<{
|
|
515
|
+
sandbox: SandboxInfo;
|
|
516
|
+
savedSnapshot: SnapshotInfo | null;
|
|
517
|
+
}>;
|
|
372
518
|
/** This month's usage and limits, or the last `days` days. */
|
|
373
519
|
usage(days?: number): Promise<Record<string, unknown>>;
|
|
374
520
|
audit(opts?: {
|
|
@@ -435,7 +581,6 @@ export declare class Terminal extends Process {
|
|
|
435
581
|
export declare class Sandbox {
|
|
436
582
|
private client;
|
|
437
583
|
info: SandboxInfo;
|
|
438
|
-
private kernelReady;
|
|
439
584
|
constructor(client: Sandboxes, info: SandboxInfo);
|
|
440
585
|
get id(): string;
|
|
441
586
|
private path;
|
|
@@ -489,21 +634,31 @@ export declare class Sandbox {
|
|
|
489
634
|
};
|
|
490
635
|
/**
|
|
491
636
|
* Preview URLs for web servers in the sandbox: https://<port>-<id>.quietrobot.dev.
|
|
492
|
-
*
|
|
637
|
+
* Each port gets a readable address, https://<name>.quietrobot.dev. Private ports open with
|
|
638
|
+
* their short share link (https://s.quietrobot.dev/...) or the token; public ones are open to anyone.
|
|
639
|
+
* A port or a link can expire; nothing does unless you say so.
|
|
493
640
|
*/
|
|
494
641
|
readonly ports: {
|
|
495
642
|
list: () => Promise<PortInfo[]>;
|
|
496
643
|
/** Replaces the exposed ports. rotate: true revokes every private link shared before. */
|
|
497
|
-
set: (ports: {
|
|
498
|
-
port: number;
|
|
499
|
-
access?: "private" | "public";
|
|
500
|
-
}[], opts?: {
|
|
644
|
+
set: (ports: PortSpec[], opts?: {
|
|
501
645
|
rotate?: boolean;
|
|
502
646
|
}) => Promise<PortInfo[]>;
|
|
503
|
-
/**
|
|
504
|
-
|
|
647
|
+
/**
|
|
648
|
+
* Exposes one port (keeping the others and their expiry) and returns its URL.
|
|
649
|
+
* opts: name ("meeting-meter") picks the words of its address; expiresIn or expiresAt, when it stops answering.
|
|
650
|
+
*/
|
|
651
|
+
expose: (port: number, access?: "private" | "public", opts?: Expiry | ExposeOptions) => Promise<PortInfo>;
|
|
505
652
|
/** Stops exposing one port. */
|
|
506
653
|
close: (port: number) => Promise<PortInfo[]>;
|
|
654
|
+
/** A private port's short links: its standing one (its shareUrl) and any made with link(). */
|
|
655
|
+
links: (port: number) => Promise<PortLinkInfo[]>;
|
|
656
|
+
/** Revokes one short link at once, also for browsers it already signed in. */
|
|
657
|
+
revokeLink: (port: number, code: string) => Promise<{
|
|
658
|
+
revoked: string;
|
|
659
|
+
}>;
|
|
660
|
+
/** A private short link to one port that stops working at its own time (never later than the port's). revokeLink or rotate revokes it. */
|
|
661
|
+
link: (port: number, expiry?: Expiry) => Promise<PortLink>;
|
|
507
662
|
};
|
|
508
663
|
/** The preview host for a port (no scheme), whether or not it is exposed yet. */
|
|
509
664
|
host(port: number): string;
|
|
@@ -542,14 +697,22 @@ export declare class Sandbox {
|
|
|
542
697
|
sandboxes: Sandbox[];
|
|
543
698
|
errors: unknown[];
|
|
544
699
|
}>;
|
|
700
|
+
/**
|
|
701
|
+
* Gives this sandbox a new size. A running or paused sandbox can't change size in
|
|
702
|
+
* place, so this copies it (fork with the new size), destroys the original and
|
|
703
|
+
* returns the copy: a new id, the same files, name and rules. Processes and memory
|
|
704
|
+
* aren't carried over. A paused original gives a paused copy.
|
|
705
|
+
*/
|
|
706
|
+
resize(size: {
|
|
707
|
+
cpuClass?: CreateOptions["cpuClass"];
|
|
708
|
+
cpus?: CreateOptions["cpus"];
|
|
709
|
+
memoryMb?: number;
|
|
710
|
+
}): Promise<Sandbox>;
|
|
545
711
|
/** Puts the files back as they were in a snapshot (the latest one by default). saveCurrent keeps a snapshot of now first. */
|
|
546
712
|
rewind(opts?: {
|
|
547
713
|
snapshotId?: string;
|
|
548
714
|
saveCurrent?: boolean;
|
|
549
|
-
}): Promise<
|
|
550
|
-
sandbox: SandboxInfo;
|
|
551
|
-
savedSnapshot: SnapshotInfo | null;
|
|
552
|
-
}>;
|
|
715
|
+
}): Promise<RewindResult>;
|
|
553
716
|
/**
|
|
554
717
|
* Changes the network rules while the sandbox runs. Fields left out keep their value.
|
|
555
718
|
* Can widen up to the sandbox's maxMode; past it (a locked sandbox), 409 egress_too_wide: fork it with the new egress.
|
|
@@ -559,6 +722,28 @@ export declare class Sandbox {
|
|
|
559
722
|
allow?: string[];
|
|
560
723
|
deny?: string[];
|
|
561
724
|
}): Promise<SandboxInfo>;
|
|
725
|
+
/**
|
|
726
|
+
* Learn mode: records the hosts the sandbox reaches so you can turn them
|
|
727
|
+
* into allow rules. Then read learnedEgress() and either applyLearnedEgress()
|
|
728
|
+
* or stopLearningEgress() to put the old rules back.
|
|
729
|
+
*/
|
|
730
|
+
learnEgress(): Promise<SandboxInfo>;
|
|
731
|
+
learnedEgress(): Promise<EgressSuggestions>;
|
|
732
|
+
/** Stops learn mode and puts the old rules back. */
|
|
733
|
+
stopLearningEgress(): Promise<SandboxInfo>;
|
|
734
|
+
/** Stops learn mode and allows only these hosts (by default, every suggestion). */
|
|
735
|
+
applyLearnedEgress(allow?: string[]): Promise<SandboxInfo>;
|
|
736
|
+
/**
|
|
737
|
+
* Caps what this sandbox may spend, in dollars (null for none). An API key
|
|
738
|
+
* may only lower the cap; raising or removing it needs a person in the dashboard.
|
|
739
|
+
*/
|
|
740
|
+
setSpendCap(capUsd: number | null): Promise<SandboxInfo>;
|
|
741
|
+
/** 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. */
|
|
742
|
+
report(): Promise<Record<string, unknown>>;
|
|
743
|
+
/** The same report as a PDF file. */
|
|
744
|
+
reportPdf(): Promise<Uint8Array>;
|
|
745
|
+
/** The sandbox's image and the exact package versions in it. */
|
|
746
|
+
image(): Promise<Record<string, unknown>>;
|
|
562
747
|
/** Resets the deadline to now + timeoutSec. */
|
|
563
748
|
setTimeout(timeoutSec: number): Promise<SandboxInfo>;
|
|
564
749
|
/** CPU, memory, disk, runtime, storage and egress, with readings over the last `hours` (default 24, up to 168). */
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ function homePath(p) {
|
|
|
23
23
|
return `${HOME}/${p.slice(2)}`;
|
|
24
24
|
return p.startsWith("/") ? p : `${HOME}/${p}`;
|
|
25
25
|
}
|
|
26
|
+
const isoTime = (t) => (t instanceof Date ? t.toISOString() : t);
|
|
26
27
|
export class SandboxesError extends Error {
|
|
27
28
|
status;
|
|
28
29
|
code;
|
|
@@ -138,6 +139,66 @@ export class Sandboxes {
|
|
|
138
139
|
async execution(id) {
|
|
139
140
|
return this.request("GET", `/executions/${enc(id)}`);
|
|
140
141
|
}
|
|
142
|
+
/** Your templates, and ours that can start now. */
|
|
143
|
+
async templates() {
|
|
144
|
+
return this.request("GET", "/templates");
|
|
145
|
+
}
|
|
146
|
+
/** One of your templates by id or name, with its recent builds. */
|
|
147
|
+
async template(idOrName) {
|
|
148
|
+
return this.request("GET", `/templates/${enc(idOrName)}`);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Builds your own template from a Dockerfile. Its last stage must start FROM
|
|
152
|
+
* one of ours (quietrobot/base, quietrobot/browser, ...). There is no build
|
|
153
|
+
* context: fetch files with RUN or ADD a URL. Builds are billed at Standard
|
|
154
|
+
* rates. wait: true (the default) waits until the build is ready or fails.
|
|
155
|
+
*/
|
|
156
|
+
async createTemplate(opts) {
|
|
157
|
+
const { wait = true, timeoutMs, ...body } = opts;
|
|
158
|
+
const t = await this.request("POST", "/templates", body);
|
|
159
|
+
return wait ? this.waitForTemplate(t.id, timeoutMs) : t;
|
|
160
|
+
}
|
|
161
|
+
/** Builds a template again, with a new Dockerfile or the same one. */
|
|
162
|
+
async rebuildTemplate(idOrName, dockerfile) {
|
|
163
|
+
return this.request("POST", `/templates/${enc(idOrName)}/builds`, dockerfile === undefined ? {} : { dockerfile });
|
|
164
|
+
}
|
|
165
|
+
async updateTemplate(idOrName, changes) {
|
|
166
|
+
return this.request("PATCH", `/templates/${enc(idOrName)}`, changes);
|
|
167
|
+
}
|
|
168
|
+
async deleteTemplate(idOrName) {
|
|
169
|
+
return this.request("DELETE", `/templates/${enc(idOrName)}`);
|
|
170
|
+
}
|
|
171
|
+
/** A build and the end of its log. */
|
|
172
|
+
async templateBuild(id) {
|
|
173
|
+
return this.request("GET", `/template-builds/${enc(id)}`);
|
|
174
|
+
}
|
|
175
|
+
/** Waits until a template's build is ready (returns it) or failed (throws with the build's error). Default 30 minutes. */
|
|
176
|
+
async waitForTemplate(idOrName, timeoutMs = 30 * 60_000) {
|
|
177
|
+
const deadline = Date.now() + timeoutMs;
|
|
178
|
+
let delay = 2000;
|
|
179
|
+
for (;;) {
|
|
180
|
+
const t = await this.template(idOrName);
|
|
181
|
+
if (t.status === "ready")
|
|
182
|
+
return t;
|
|
183
|
+
if (t.status === "failed") {
|
|
184
|
+
const b = t.builds?.[0];
|
|
185
|
+
throw new SandboxesError(422, "build_failed", b?.error ?? `Template ${t.name} failed to build`);
|
|
186
|
+
}
|
|
187
|
+
if (Date.now() > deadline)
|
|
188
|
+
throw new SandboxesError(408, "build_timeout", `Template ${t.name} is still building`);
|
|
189
|
+
await sleep(delay);
|
|
190
|
+
delay = Math.min(delay * 1.5, 10_000);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Undoes a command: puts the sandbox's files back as they were just before
|
|
195
|
+
* it ran. Works for commands that were held for approval or ran with sudo,
|
|
196
|
+
* which save the files first (a setting on the dashboard's Policy page);
|
|
197
|
+
* others answer 409. The current files are saved as a snapshot first.
|
|
198
|
+
*/
|
|
199
|
+
async undo(executionId) {
|
|
200
|
+
return this.request("POST", `/executions/${enc(executionId)}/undo`);
|
|
201
|
+
}
|
|
141
202
|
/** This month's usage and limits, or the last `days` days. */
|
|
142
203
|
async usage(days) {
|
|
143
204
|
return this.request("GET", `/usage${query({ days })}`);
|
|
@@ -288,11 +349,11 @@ export class Terminal extends Process {
|
|
|
288
349
|
await this.client.request("POST", `/executions/${enc(this.id)}/resize`, { cols, rows });
|
|
289
350
|
}
|
|
290
351
|
}
|
|
291
|
-
const KERNEL = "~/.qr/
|
|
352
|
+
const KERNEL = "~/.qr/kernel2.py";
|
|
353
|
+
const NO_KERNEL = "QR_NO_KERNEL";
|
|
292
354
|
export class Sandbox {
|
|
293
355
|
client;
|
|
294
356
|
info;
|
|
295
|
-
kernelReady = false;
|
|
296
357
|
constructor(client, info) {
|
|
297
358
|
this.client = client;
|
|
298
359
|
this.info = info;
|
|
@@ -371,18 +432,22 @@ export class Sandbox {
|
|
|
371
432
|
* and any matplotlib figures as PNG.
|
|
372
433
|
*/
|
|
373
434
|
async runCode(code, opts = {}) {
|
|
374
|
-
|
|
435
|
+
let tag = "QR_CELL";
|
|
436
|
+
while (code.includes(tag))
|
|
437
|
+
tag += "_";
|
|
438
|
+
const cell = `[ -f ${KERNEL} ] || { echo ${NO_KERNEL}; exit 0; }; python3 ${KERNEL} run <<'${tag}'\n${code}\n${tag}`;
|
|
439
|
+
// One command per cell: the cell runs straight away, and the kernel file
|
|
440
|
+
// is copied in only when the sandbox doesn't have it yet. A cell that
|
|
441
|
+
// raises exits 1, so the audit log counts it as failed.
|
|
442
|
+
let e = await this.exec(cell, { timeoutMs: 300_000, ...opts });
|
|
443
|
+
if (e.status === "completed" && (e.stdout ?? "").trim() === NO_KERNEL) {
|
|
375
444
|
await this.exec(`mkdir -p ~/.qr && echo '${KERNEL_B64}' | base64 -d > ${KERNEL}.tmp && mv ${KERNEL}.tmp ${KERNEL}`, {
|
|
376
445
|
waitForApproval: opts.waitForApproval,
|
|
377
446
|
approvalTimeoutMs: opts.approvalTimeoutMs,
|
|
378
447
|
onPending: opts.onPending,
|
|
379
448
|
});
|
|
380
|
-
this.
|
|
449
|
+
e = await this.exec(cell, { timeoutMs: 300_000, ...opts });
|
|
381
450
|
}
|
|
382
|
-
let tag = "QR_CELL";
|
|
383
|
-
while (code.includes(tag))
|
|
384
|
-
tag += "_";
|
|
385
|
-
const e = await this.exec(`python3 ${KERNEL} run <<'${tag}'\n${code}\n${tag}`, { timeoutMs: 300_000, ...opts });
|
|
386
451
|
const line = (e.stdout ?? "").trim().split("\n").pop() ?? "";
|
|
387
452
|
let r;
|
|
388
453
|
try {
|
|
@@ -396,8 +461,7 @@ export class Sandbox {
|
|
|
396
461
|
}
|
|
397
462
|
/** Starts a fresh kernel for runCode(): variables are cleared. */
|
|
398
463
|
async restartCode() {
|
|
399
|
-
|
|
400
|
-
await this.exec(`python3 ${KERNEL} restart`);
|
|
464
|
+
await this.exec(`[ ! -f ${KERNEL} ] || python3 ${KERNEL} restart`);
|
|
401
465
|
}
|
|
402
466
|
files = {
|
|
403
467
|
read: (path) => this.client.request("GET", this.path(`/files${query({ path })}`), undefined, true),
|
|
@@ -408,7 +472,9 @@ export class Sandbox {
|
|
|
408
472
|
};
|
|
409
473
|
/**
|
|
410
474
|
* Preview URLs for web servers in the sandbox: https://<port>-<id>.quietrobot.dev.
|
|
411
|
-
*
|
|
475
|
+
* Each port gets a readable address, https://<name>.quietrobot.dev. Private ports open with
|
|
476
|
+
* their short share link (https://s.quietrobot.dev/...) or the token; public ones are open to anyone.
|
|
477
|
+
* A port or a link can expire; nothing does unless you say so.
|
|
412
478
|
*/
|
|
413
479
|
ports = {
|
|
414
480
|
list: async () => {
|
|
@@ -420,17 +486,20 @@ export class Sandbox {
|
|
|
420
486
|
/** Replaces the exposed ports. rotate: true revokes every private link shared before. */
|
|
421
487
|
set: async (ports, opts = {}) => {
|
|
422
488
|
const r = await this.client.request("PUT", this.path("/ports"), {
|
|
423
|
-
ports: ports.map((p) => ({ port: p.port, access: p.access ?? "private" })),
|
|
489
|
+
ports: ports.map((p) => ({ port: p.port, access: p.access ?? "private", name: p.name, expiresIn: p.expiresIn, expiresAt: isoTime(p.expiresAt) })),
|
|
424
490
|
rotate: opts.rotate,
|
|
425
491
|
});
|
|
426
492
|
if (r.domain)
|
|
427
493
|
this.client.previewDomain = r.domain;
|
|
428
494
|
return r.ports;
|
|
429
495
|
},
|
|
430
|
-
/**
|
|
431
|
-
|
|
496
|
+
/**
|
|
497
|
+
* Exposes one port (keeping the others and their expiry) and returns its URL.
|
|
498
|
+
* opts: name ("meeting-meter") picks the words of its address; expiresIn or expiresAt, when it stops answering.
|
|
499
|
+
*/
|
|
500
|
+
expose: async (port, access = "private", opts) => {
|
|
432
501
|
const cur = (await this.ports.list()).filter((p) => p.port !== port).map((p) => ({ port: p.port, access: p.access }));
|
|
433
|
-
const next = await this.ports.set([...cur, { port, access }]);
|
|
502
|
+
const next = await this.ports.set([...cur, { port, access, ...opts }]);
|
|
434
503
|
return next.find((p) => p.port === port);
|
|
435
504
|
},
|
|
436
505
|
/** Stops exposing one port. */
|
|
@@ -438,6 +507,15 @@ export class Sandbox {
|
|
|
438
507
|
const cur = (await this.ports.list()).filter((p) => p.port !== port).map((p) => ({ port: p.port, access: p.access }));
|
|
439
508
|
return this.ports.set(cur);
|
|
440
509
|
},
|
|
510
|
+
/** A private port's short links: its standing one (its shareUrl) and any made with link(). */
|
|
511
|
+
links: async (port) => (await this.client.request("GET", this.path(`/ports/${port}/links`))).links,
|
|
512
|
+
/** Revokes one short link at once, also for browsers it already signed in. */
|
|
513
|
+
revokeLink: (port, code) => this.client.request("DELETE", this.path(`/ports/${port}/links/${enc(code)}`)),
|
|
514
|
+
/** A private short link to one port that stops working at its own time (never later than the port's). revokeLink or rotate revokes it. */
|
|
515
|
+
link: (port, expiry) => {
|
|
516
|
+
const e = expiry;
|
|
517
|
+
return this.client.request("POST", this.path(`/ports/${port}/links`), { expiresIn: e?.expiresIn, expiresAt: isoTime(e?.expiresAt) });
|
|
518
|
+
},
|
|
441
519
|
};
|
|
442
520
|
/** The preview host for a port (no scheme), whether or not it is exposed yet. */
|
|
443
521
|
host(port) {
|
|
@@ -475,11 +553,38 @@ export class Sandbox {
|
|
|
475
553
|
const r = await this.client.request("POST", this.path("/fork"), opts);
|
|
476
554
|
return { snapshot: r.snapshot, sandboxes: r.sandboxes.map((s) => new Sandbox(this.client, s)), errors: r.errors ?? [] };
|
|
477
555
|
}
|
|
556
|
+
/**
|
|
557
|
+
* Gives this sandbox a new size. A running or paused sandbox can't change size in
|
|
558
|
+
* place, so this copies it (fork with the new size), destroys the original and
|
|
559
|
+
* returns the copy: a new id, the same files, name and rules. Processes and memory
|
|
560
|
+
* aren't carried over. A paused original gives a paused copy.
|
|
561
|
+
*/
|
|
562
|
+
async resize(size) {
|
|
563
|
+
if (!size.cpuClass && !size.cpus && !size.memoryMb)
|
|
564
|
+
throw new Error("resize: give cpuClass, cpus or memoryMb");
|
|
565
|
+
const wasPaused = (await this.refresh()).status === "paused";
|
|
566
|
+
const fork = () => this.fork({ name: this.info.name ?? undefined, cpuClass: size.cpuClass, cpus: size.cpus, memoryMb: size.memoryMb });
|
|
567
|
+
let copy;
|
|
568
|
+
try {
|
|
569
|
+
// A copy that fails to boot is tried once more before giving up.
|
|
570
|
+
copy = (await fork().catch((e) => (e instanceof SandboxesError && e.code === "start_failed" ? fork() : Promise.reject(e)))).sandboxes[0];
|
|
571
|
+
}
|
|
572
|
+
catch (e) {
|
|
573
|
+
// The failed copy is left in status error; the sandbox being resized is untouched.
|
|
574
|
+
const why = e instanceof SandboxesError ? `${e.code}: ${e.message}` : e instanceof Error ? e.message : String(e);
|
|
575
|
+
throw new SandboxesError(e instanceof SandboxesError ? e.status : 502, "resize_failed", `The resized copy couldn't be started (${why}). ${this.id} is unchanged and still ${(await this.refresh().catch(() => this.info)).status}; try the resize again.`);
|
|
576
|
+
}
|
|
577
|
+
if (!copy)
|
|
578
|
+
throw new SandboxesError(502, "resize_failed", `The resized copy couldn't be started. ${this.id} is unchanged; try the resize again.`);
|
|
579
|
+
await this.destroy();
|
|
580
|
+
if (wasPaused)
|
|
581
|
+
await copy.pause();
|
|
582
|
+
return copy;
|
|
583
|
+
}
|
|
478
584
|
/** Puts the files back as they were in a snapshot (the latest one by default). saveCurrent keeps a snapshot of now first. */
|
|
479
585
|
async rewind(opts = {}) {
|
|
480
586
|
const r = await this.client.request("POST", this.path("/rewind"), opts);
|
|
481
587
|
this.info = r.sandbox;
|
|
482
|
-
this.kernelReady = false;
|
|
483
588
|
return r;
|
|
484
589
|
}
|
|
485
590
|
/**
|
|
@@ -490,6 +595,50 @@ export class Sandbox {
|
|
|
490
595
|
this.info = await this.client.request("PUT", this.path("/egress"), egress);
|
|
491
596
|
return this.info;
|
|
492
597
|
}
|
|
598
|
+
/**
|
|
599
|
+
* Learn mode: records the hosts the sandbox reaches so you can turn them
|
|
600
|
+
* into allow rules. Then read learnedEgress() and either applyLearnedEgress()
|
|
601
|
+
* or stopLearningEgress() to put the old rules back.
|
|
602
|
+
*/
|
|
603
|
+
async learnEgress() {
|
|
604
|
+
this.info = await this.client.request("POST", this.path("/egress/learn"));
|
|
605
|
+
return this.info;
|
|
606
|
+
}
|
|
607
|
+
async learnedEgress() {
|
|
608
|
+
return this.client.request("GET", this.path("/egress/learn"));
|
|
609
|
+
}
|
|
610
|
+
/** Stops learn mode and puts the old rules back. */
|
|
611
|
+
async stopLearningEgress() {
|
|
612
|
+
this.info = await this.client.request("DELETE", this.path("/egress/learn"));
|
|
613
|
+
return this.info;
|
|
614
|
+
}
|
|
615
|
+
/** Stops learn mode and allows only these hosts (by default, every suggestion). */
|
|
616
|
+
async applyLearnedEgress(allow) {
|
|
617
|
+
if (!allow)
|
|
618
|
+
allow = (await this.learnedEgress()).suggestions.map((s) => s.rule);
|
|
619
|
+
this.info = await this.client.request("POST", this.path("/egress/learn/apply"), { allow });
|
|
620
|
+
return this.info;
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Caps what this sandbox may spend, in dollars (null for none). An API key
|
|
624
|
+
* may only lower the cap; raising or removing it needs a person in the dashboard.
|
|
625
|
+
*/
|
|
626
|
+
async setSpendCap(capUsd) {
|
|
627
|
+
this.info = await this.client.request("PUT", this.path("/spend-cap"), { capUsd });
|
|
628
|
+
return this.info;
|
|
629
|
+
}
|
|
630
|
+
/** 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. */
|
|
631
|
+
async report() {
|
|
632
|
+
return this.client.request("GET", this.path("/report"));
|
|
633
|
+
}
|
|
634
|
+
/** The same report as a PDF file. */
|
|
635
|
+
async reportPdf() {
|
|
636
|
+
return this.client.request("GET", this.path(`/report${query({ format: "pdf" })}`), undefined, true);
|
|
637
|
+
}
|
|
638
|
+
/** The sandbox's image and the exact package versions in it. */
|
|
639
|
+
async image() {
|
|
640
|
+
return this.client.request("GET", this.path("/image"));
|
|
641
|
+
}
|
|
493
642
|
/** Resets the deadline to now + timeoutSec. */
|
|
494
643
|
async setTimeout(timeoutSec) {
|
|
495
644
|
this.info = await this.client.request("POST", this.path("/timeout"), { timeoutSec });
|
package/dist/kernel.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const KERNEL_B64 = "
|
|
1
|
+
export declare const KERNEL_B64 = "IiIiQSBzbWFsbCBwZXJzaXN0ZW50IFB5dGhvbiBrZXJuZWwgdGhhdCBydW5zIGluc2lkZSBhIHNhbmRib3guCgpUaGUgU0RLcycgcnVuX2NvZGUoKSAvIHJ1bkNvZGUoKSBjb3BpZXMgdGhpcyBmaWxlIGludG8gdGhlIHNhbmRib3ggb25jZSBhbmQKdGhlbiBydW5zIGVhY2ggY2VsbCB3aXRoIGEgcGxhaW4gY29tbWFuZDoKCiAgICBweXRob24zIH4vLnFyL2tlcm5lbC5weSBydW4gPDwnUVJfQ0VMTCcKICAgIC4uLmNvZGUuLi4KICAgIFFSX0NFTEwKClRoZSBmaXJzdCBjYWxsIHN0YXJ0cyBhIHNlcnZlciBwcm9jZXNzIHRoYXQga2VlcHMgdGhlIHZhcmlhYmxlcyBiZXR3ZWVuCmNlbGxzLCBzbyBhIG5vdGVib29rLXN0eWxlIHNlc3Npb24gd29ya3MgdGhlIHdheSBKdXB5dGVyIGRvZXMuIFRoZSBjb2RlIGlzIGluCnRoZSBjb21tYW5kIGl0c2VsZiwgc28gdGhlIHNhbmRib3gncyBwb2xpY3kgYW5kIGF1ZGl0IGxvZyBzZWUgZXZlcnkgY2VsbC4KCkVhY2ggY2VsbCBhbnN3ZXJzIG9uZSBKU09OIGxpbmUgb24gc3Rkb3V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CAiaHRtbCIpLCAoIl9yZXByX3BuZ18iLCAicG5nIiksICgiX3JlcHJfanNvbl8iLCAianNvbiIpKToKICAgICAgICBmbiA9IGdldGF0dHIodmFsdWUsIGF0dHIsIE5vbmUpCiAgICAgICAgaWYgY2FsbGFibGUoZm4pOgogICAgICAgICAgICB0cnk6CiAgICAgICAgICAgICAgICB2ID0gZm4oKQogICAgICAgICAgICBleGNlcHQgRXhjZXB0aW9uOgogICAgICAgICAgICAgICAgY29udGludWUKICAgICAgICAgICAgaWYgdiBpcyBOb25lOgogICAgICAgICAgICAgICAgY29udGludWUKICAgICAgICAgICAgaWYga2V5ID09ICJwbmciIGFuZCBpc2luc3RhbmNlKHYsIGJ5dGVzKToKICAgICAgICAgICAgICAgIHYgPSBiYXNlNjQuYjY0ZW5jb2RlKHYpLmRlY29kZSgpCiAgICAgICAgICAgIG91dFtrZXldID0gdgogICAgcmV0dXJuIG91dAoKCmRlZiBfZmlndXJlcygpOgogICAgIiIiUE5HcyBvZiBhbnkgb3BlbiBtYXRwbG90bGliIGZpZ3VyZXMsIHdoaWNoIGFyZSB0aGVuIGNsb3NlZC4iIiIKICAgIHBsdCA9IHN5cy5tb2R1bGVzLmdldCgibWF0cGxvdGxpYi5weXBsb3QiKQogICAgaWYgcGx0IGlzIE5vbmU6CiAgICAgICAgcmV0dXJuIFtdCiAgICBvdXQgPSBbXQogICAgZm9yIG51bSBpbiBwbHQuZ2V0X2ZpZ251bXMoKToKICAgICAgICBmaWcgPSBwbHQuZmlndXJlKG51bSkKICAgICAgICBidWYgPSBpby5CeXRlc0lPKCkKICAgICAgICB0cnk6CiAgICAgICAgICAgIGZpZy5zYXZlZmlnKGJ1ZiwgZm9ybWF0PSJwbmciLCBiYm94X2luY2hlcz0idGlnaHQiKQogICAgICAgICAgICBvdXQuYXBwZW5kKHsidGV4dCI6ICI8RmlndXJlPiIsICJwbmciOiBiYXNlNjQuYjY0ZW5jb2RlKGJ1Zi5nZXR2YWx1ZSgpKS5kZWNvZGUoKX0pCiAgICAgICAgZXhjZXB0IEV4Y2VwdGlvbjoKICAgICAgICAgICAgcGFzcwogICAgcGx0LmNsb3NlKCJhbGwiKQogICAgcmV0dXJuIG91dAoKCmNsYXNzIEtlcm5lbDoKICAgIGRlZiBfX2luaXRfXyhzZWxmKToKICAgICAgICBzZWxmLmdsb2JhbHMgPSB7Il9fbmFtZV9fIjogIl9fbWFpbl9fIn0KICAgICAgICBzZWxmLmxvY2sgPSB0aHJlYWRpbmcuTG9jaygpCgogICAgZGVmIHJ1bihzZWxmLCBjb2RlKToKICAgICAgICBzdGRvdXQsIHN0ZGVyciA9IGlvLlN0cmluZ0lPKCksIGlvLlN0cmluZ0lPKCkKICAgICAgICByZXN1bHRzLCBlcnJvciA9IFtdLCBOb25lCiAgICAgICAgd2l0aCBzZWxmLmxvY2ssIGNvbnRleHRsaWIucmVkaXJlY3Rfc3Rkb3V0KHN0ZG91dCksIGNvbnRleHRsaWIucmVkaXJlY3Rfc3RkZXJyKHN0ZGVycik6CiAgICAgICAgICAgIHRyeToKICAgICAgICAgICAgICAgIHRyZWUgPSBhc3QucGFyc2UoY29kZSwgIjxjZWxsPiIsICJleGVjIikKICAgICAgICAgICAgICAgIGxhc3QgPSBOb25lCiAgICAgICAgICAgICAgICBpZiB0cmVlLmJvZHkgYW5kIGlzaW5zdGFuY2UodHJlZS5ib2R5Wy0xXSwgYXN0LkV4cHIpOgogICAgICAgICAgICAgICAgICAgIGxhc3QgPSBhc3QuRXhwcmVzc2lvbih0cmVlLmJvZHkucG9wKCkudmFsdWUpCiAgICAgICAgICAgICAgICBleGVjKGNvbXBpbGUodHJlZSwgIjxjZWxsPiIsICJleGVjIiksIHNlbGYuZ2xvYmFscykKICAgICAgICAgICAgICAgIGlmIGxhc3QgaXMgbm90IE5vbmU6CiAgICAgICAgICAgICAgICAgICAgdmFsdWUgPSBldmFsKGNvbXBpbGUobGFzdCwgIjxjZWxsPiIsICJldmFsIiksIHNlbGYuZ2xvYmFscykKICAgICAgICAgICAgICAgICAgICBpZiB2YWx1ZSBpcyBub3QgTm9uZToKICAgICAgICAgICAgICAgICAgICAgICAgc2VsZi5nbG9iYWxzWyJfIl0gPSB2YWx1ZQogICAgICAgICAgICAgICAgICAgICAgICByZXN1bHRzLmFwcGVuZChfcmljaCh2YWx1ZSkpCiAgICAgICAgICAgIGV4Y2VwdCBCYXNlRXhjZXB0aW9uIGFzIGU6ICAjIGEgY2VsbCBtYXkgcmFpc2UgYW55dGhpbmcsIFN5c3RlbUV4aXQgaW5jbHVkZWQKICAgICAgICAgICAgICAgIGVycm9yID0gewogICAgICAgICAgICAgICAgICAgICJuYW1lIjogdHlwZShlKS5fX25hbWVfXywKICAgICAgICAgICAgICAgICAgICAidmFsdWUiOiBzdHIoZSksCiAgICAgICAgICAgICAgICAgICAgInRyYWNlYmFjayI6ICIiLmpvaW4odHJhY2ViYWNrLmZvcm1hdF9leGNlcHRpb24odHlwZShlKSwgZSwgZS5fX3RyYWNlYmFja19fKSksCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIHJlc3VsdHMuZXh0ZW5kKF9maWd1cmVzKCkpCiAgICAgICAgcmV0dXJuIHsic3Rkb3V0Ijogc3Rkb3V0LmdldHZhbHVlKCksICJzdGRlcnIiOiBzdGRlcnIuZ2V0dmFsdWUoKSwgInJlc3VsdHMiOiByZXN1bHRzLCAiZXJyb3IiOiBlcnJvcn0KCgpkZWYgc2VydmUoKToKICAgIG9zLm1ha2VkaXJzKG9zLnBhdGguZGlybmFtZShTT0NLKSwgZXhpc3Rfb2s9VHJ1ZSkKICAgIG9zLmVudmlyb24uc2V0ZGVmYXVsdCgiTVBMQkFDS0VORCIsICJBZ2ciKQogICAgd2l0aCBjb250ZXh0bGliLnN1cHByZXNzKEZpbGVOb3RGb3VuZEVycm9yKToKICAgICAgICBvcy51bmxpbmsoU09DSykKICAgIGtlcm5lbCA9IEtlcm5lbCgpCiAgICBzcnYgPSBzb2NrZXQuc29ja2V0KHNvY2tldC5BRl9VTklYLCBzb2NrZXQuU09DS19TVFJFQU0pCiAgICBzcnYuYmluZChTT0NLKQogICAgb3MuY2htb2QoU09DSywgMG82MDApCiAgICBzcnYubGlzdGVuKDgpCiAgICB3aGlsZSBUcnVlOgogICAgICAgIGNvbm4sIF8gPSBzcnYuYWNjZXB0KCkKICAgICAgICB0cnk6CiAgICAgICAgICAgIGNvZGUgPSBfcmVjdl9hbGwoY29ubikuZGVjb2RlKCJ1dGYtOCIsICJyZXBsYWNlIikKICAgICAgICAgICAgaWYgY29kZSA9PSAiXDByZXN0YXJ0IjoKICAgICAgICAgICAgICAgICMgVGhlIG5leHQgY2VsbCBzdGFydHMgYSBmcmVzaCBrZXJuZWwgd2l0aCBubyB2YXJpYWJsZXMuCiAgICAgICAgICAgICAgICBzcnYuY2xvc2UoKQogICAgICAgICAgICAgICAgb3MudW5saW5rKFNPQ0spCiAgICAgICAgICAgICAgICBjb25uLnNlbmRhbGwoYid7InJlc3RhcnRlZCI6IHRydWV9JykKICAgICAgICAgICAgICAgIGNvbm4uY2xvc2UoKQogICAgICAgICAgICAgICAgb3MuX2V4aXQoMCkKICAgICAgICAgICAgY29ubi5zZW5kYWxsKGpzb24uZHVtcHMoa2VybmVsLnJ1bihjb2RlKSkuZW5jb2RlKCkpCiAgICAgICAgZXhjZXB0IEV4Y2VwdGlvbjoKICAgICAgICAgICAgcGFzcwogICAgICAgIGZpbmFsbHk6CiAgICAgICAgICAgIHdpdGggY29udGV4dGxpYi5zdXBwcmVzcyhFeGNlcHRpb24pOgogICAgICAgICAgICAgICAgY29ubi5jbG9zZSgpCgoKZGVmIF9jb25uZWN0KCk6CiAgICBzID0gc29ja2V0LnNvY2tldChzb2NrZXQuQUZfVU5JWCwgc29ja2V0LlNPQ0tfU1RSRUFNKQogICAgcy5jb25uZWN0KFNPQ0spCiAgICByZXR1cm4gcwoKCmRlZiBfZW5zdXJlX3NlcnZlcigpOgogICAgdHJ5OgogICAgICAgIHJldHVybiBfY29ubmVjdCgpC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FuZGJveCdzIGF1ZGl0IGxvZyBjb3VudHMgaXQgYXMgYQogICAgIyBmYWlsZWQgY29tbWFuZC4gVGhlIEpTT04gbGluZSBhYm92ZSBzdGlsbCBjYXJyaWVzIHRoZSBlcnJvci4KICAgIHRyeToKICAgICAgICBpZiBqc29uLmxvYWRzKG91dCkuZ2V0KCJlcnJvciIpOgogICAgICAgICAgICBzeXMuZXhpdCgxKQogICAgZXhjZXB0IFZhbHVlRXJyb3I6CiAgICAgICAgcGFzcwoKCmlmIF9fbmFtZV9fID09ICJfX21haW5fXyI6CiAgICBtb2RlID0gc3lzLmFyZ3ZbMV0gaWYgbGVuKHN5cy5hcmd2KSA+IDEgZWxzZSAicnVuIgogICAgaWYgbW9kZSA9PSAic2VydmUiOgogICAgICAgIHNlcnZlKCkKICAgIGVsaWYgbW9kZSA9PSAicmVzdGFydCI6CiAgICAgICAgY2xpZW50KCJcMHJlc3RhcnQiKQogICAgZWxzZToKICAgICAgICBjbGllbnQoc3lzLnN0ZGluLnJlYWQoKSkK";
|
package/dist/kernel.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by scripts/sync-kernel.sh from python/src/quietrobot_sandboxes/_kernel.py. Do not edit.
|
|
2
|
-
export const KERNEL_B64 = "
|
|
2
|
+
export const KERNEL_B64 = "IiIiQSBzbWFsbCBwZXJzaXN0ZW50IFB5dGhvbiBrZXJuZWwgdGhhdCBydW5zIGluc2lkZSBhIHNhbmRib3guCgpUaGUgU0RLcycgcnVuX2NvZGUoKSAvIHJ1bkNvZGUoKSBjb3BpZXMgdGhpcyBmaWxlIGludG8gdGhlIHNhbmRib3ggb25jZSBhbmQKdGhlbiBydW5zIGVhY2ggY2VsbCB3aXRoIGEgcGxhaW4gY29tbWFuZDoKCiAgICBweXRob24zIH4vLnFyL2tlcm5lbC5weSBydW4gPDwnUVJfQ0VMTCcKICAgIC4uLmNvZGUuLi4KICAgIFFSX0NFTEwKClRoZSBmaXJzdCBjYWxsIHN0Y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bm4ucmVjdig2NTUzNikKICAgICAgICBpZiBub3QgYjoKICAgICAgICAgICAgYnJlYWsKICAgICAgICBjaHVua3MuYXBwZW5kKGIpCiAgICByZXR1cm4gYiIiLmpvaW4oY2h1bmtzKQoKCmRlZiBfcmljaCh2YWx1ZSk6CiAgICAiIiJXaGF0IGEgbm90ZWJvb2sgd291bGQgc2hvdyBmb3IgdGhlIGNlbGwncyBsYXN0IGV4cHJlc3Npb24uIiIiCiAgICBvdXQgPSB7InRleHQiOiByZXByKHZhbHVlKX0KICAgIGZvciBhdHRyLCBrZXkgaW4gKCgiX3JlcHJfaHRtbF8iLCAiaHRtbCIpLCAoIl9yZXByX3BuZ18iLCAicG5nIiksICgiX3JlcHJfanNvbl8iLCAianNvbiIpKToKICAgICAgICBmbiA9IGdldGF0dHIodmFsdWUsIGF0dHIsIE5vbmUpCiAgICAgICAgaWYgY2FsbGFibGUoZm4pOgogICAgICAgICAgICB0cnk6CiAgICAgICAgICAgICAgICB2ID0gZm4oKQogICAgICAgICAgICBleGNlcHQgRXhjZXB0aW9uOgogICAgICAgICAgICAgICAgY29udGludWUKICAgICAgICAgICAgaWYgdiBpcyBOb25lOgogICAgICAgICAgICAgICAgY29udGludWUKICAgICAgICAgICAgaWYga2V5ID09ICJwbmciIGFuZCBpc2luc3RhbmNlKHYsIGJ5dGVzKToKICAgICAgICAgICAgICAgIHYgPSBiYXNlNjQuYjY0ZW5jb2RlKHYpLmRlY29kZSgpCiAgICAgICAgICAgIG91dFtrZXldID0gdgogICAgcmV0dXJuIG91dAoKCmRlZiBfZmlndXJlcygpOgogICAgIiIiUE5HcyBvZiBhbnkgb3BlbiBtYXRwbG90bGliIGZpZ3VyZXMsIHdoaWNoIGFyZSB0aGVuIGNsb3NlZC4iIiIKICAgIHBsdCA9IHN5cy5tb2R1bGVzLmdldCgibWF0cGxvdGxpYi5weXBsb3QiKQogICAgaWYgcGx0IGlzIE5vbmU6CiAgICAgICAgcmV0dXJuIFtdCiAgICBvdXQgP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Wy0xXSwgYXN0LkV4cHIpOgogICAgICAgICAgICAgICAgICAgIGxhc3QgPSBhc3QuRXhwcmVzc2lvbih0cmVlLmJvZHkucG9wKCkudmFsdWUpCiAgICAgICAgICAgICAgICBleGVjKGNvbXBpbGUodHJlZSwgIjxjZWxsPiIsICJleGVjIiksIHNlbGYuZ2xvYmFscykKICAgICAgICAgICAgICAgIGlmIGxhc3QgaXMgbm90IE5vbmU6CiAgICAgICAgICAgICAgICAgICAgdmFsdWUgPSBldmFsKGNvbXBpbGUobGFzdCwgIjxjZWxsPiIsICJldmFsIiksIHNlbGYuZ2xvYmFscykKICAgICAgICAgICAgICAgICAgICBpZiB2YWx1ZSBpcyBub3QgTm9uZToKICAgICAgICAgICAgICAgICAgICAgICAgc2VsZi5nbG9iYWxzWyJfIl0gPSB2YWx1ZQogICAgICAgICAgICAgICAgICAgICAgICByZXN1bHRzLmFwcGVuZChfcmljaCh2YWx1ZSkpCiAgICAgICAgICAgIGV4Y2VwdCBCYXNlRXhjZXB0aW9uIGFzIGU6ICAjIGEgY2VsbCBtYXkgcmFpc2UgYW55dGhpbmcsIFN5c3RlbUV4aXQgaW5jbHVkZWQKICAgICAgICAgICAgICAgIGVycm9yID0gewogICAgICAgICAgICAgICAgICAgICJuYW1lIjogdHlwZShlKS5fX25hbWVfXywKICAgICAgICAgICAgICAgICAgICAidmFsdWUiOiBzdHIoZSksCiAgICAgICAgICAgICAgICAgICAgInRyYWNlYmFjayI6ICIiLmpvaW4odHJhY2ViYWNrLmZvcm1hdF9leGNlcHRpb24odHlwZShlKSwgZSwgZS5fX3RyYWNlYmFja19fKSksCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIHJlc3VsdHMuZXh0ZW5kKF9maWd1cmVzKCkpCiAgICAgICAgcmV0dXJuIHsic3Rkb3V0Ijogc3Rkb3V0LmdldHZhbHVlKCksICJzdGRlcnIiOiBzdGRlcnIuZ2V0dmFsdWUoKSwgInJlc3VsdHMiOiByZXN1bHRzLCAiZXJyb3IiOiBlcnJvcn0KCgpkZWYgc2VydmUoKToKICAgIG9zLm1ha2VkaXJzKG9zLnBhdGguZGlybmFtZShTT0NLKSwgZXhpc3Rfb2s9VHJ1ZSkKICAgIG9zLmVudmlyb24uc2V0ZGVmYXVsdCgiTVBMQkFDS0VORCIsICJBZ2ciKQogICAgd2l0aCBjb250ZXh0bGliLnN1cHByZXNzKEZpbGVOb3RGb3VuZEVycm9yKToKICAgICAgICBvcy51bmxpbmsoU09DSykKICAgIGtlcm5lbCA9IEtlcm5lbCgpCiAgICBzcnYgPSBzb2NrZXQuc29ja2V0KHNvY2tldC5BRl9VTklYLCBzb2NrZXQuU09DS19TVFJFQU0pCiAgICBzcnYuYmluZChTT0NLKQogICAgb3MuY2htb2QoU09DSywgMG82MDApCiAgICBzcnYubGlzdGVuKDgpCiAgICB3aGlsZSBUcnVlOgogICAgICAgIGNvbm4sIF8gPSBzcnYuYWNjZXB0KCkKICAgICAgICB0cnk6CiAgICAgICAgICAgIGNvZGUgPSBfcmVjdl9hbGwoY29ubikuZGVjb2RlKCJ1dGYtOCIsICJyZXBsYWNlIikKICAgICAgICAgICAgaWYgY29kZSA9PSAiXDByZXN0YXJ0IjoKICAgICAgICAgICAgICAgICMgVGhlIG5leHQgY2VsbCBzdGFydHMgYSBmcmVzaCBrZXJuZWwgd2l0aCBubyB2YXJpYWJsZXMuCiAgICAgICAgICAgICAgICBzcnYuY2xvc2UoKQogICAgICAgICAgICAgICAgb3MudW5saW5rKFNPQ0spCiAgICAgICAgICAgICAgICBjb25uLnNlbmRhbGwoYid7InJlc3RhcnRlZCI6IHRydWV9JykKICAgICAgICAgICAgICAgIGNvbm4uY2xvc2UoKQogICAgICAgICAgICAgICAgb3MuX2V4aXQoMCkKICAgICAgICAgICAgY29ubi5zZW5kYWxsKGpzb24uZHVtcHMoa2VybmVsLnJ1bihjb2RlKSkuZW5jb2RlKCkpCiAgICAgICAgZXhjZXB0IEV4Y2VwdGlvbjoKICAgICAgICAgICAgcGFzcwogICAgICAgIGZpbmFsbHk6CiAgICAgICAgICAgIHdpdGggY29udGV4dGxpYi5zdXBwcmVzcyhFeGNlcHRpb24pOgogICAgICAgICAgICAgICAgY29ubi5jbG9zZSgpCgoKZGVmIF9jb25uZWN0KCk6CiAgICBzID0gc29ja2V0LnNvY2tldChzb2NrZXQuQUZfVU5JWCwgc29ja2V0LlNPQ0tfU1RSRUFNKQogICAgcy5jb25uZWN0KFNPQ0spCiAgICByZXR1cm4gcwoKCmRlZiBfZW5zdXJlX3NlcnZlcigpOgogICAgdHJ5OgogICAgICAgIHJldHVybiBfY29ubmVjdCgpCiAgICBleGNlcHQgT1NFcnJvcjoKICAgICAgICBwYXNzCiAgICBvcy5tYWtlZGlycyhvcy5wYXRoLmRpcm5hbWUoU09DSyksIGV4aXN0X29rPVRydWUpCiAgICB3aXRoIG9wZW4oTE9HLCAiYWIiKSBhcyBsb2c6CiAgICAgICAgc3VicHJvY2Vzcy5Qb3BlbigKICAgICAgICAgICAgW3N5cy5leGVjdXRhYmxlLCBvcy5wYXRoLmFic3BhdGgoX19maWxlX18pLCAic2VydmUiXSwKICAgICAgICAgICAgc3RkaW49c3VicHJvY2Vzcy5ERVZOVUxMLAogICAgICAgICAgICBzdGRvdXQ9bG9nLAogICAgICAgICAgICBzdGRlcnI9bG9nLAogICAgICAgICAgICBzdGFydF9uZXdfc2Vzc2lvbj1UcnVlLAogICAgICAgICAgICBjbG9zZV9mZHM9VHJ1ZSwKICAgICAgICApCiAgICBkZWFkbGluZSA9IHRpbWUudGltZSgpICsgMTUKICAgIHdoaWxlIHRpbWUudGltZSgpIDwgZGVhZGxpbmU6CiAgICAgICAgdHJ5OgogICAgICAgICAgICByZXR1cm4gX2Nvbm5lY3QoKQogICAgICAgIGV4Y2VwdCBPU0Vycm9yOgogICAgICAgICAgICB0aW1lLnNsZWVwKDAuMDUpCiAgICByYWlzZSBTeXN0ZW1FeGl0KCJrZXJuZWwgZGlkIG5vdCBzdGFydDsgc2VlICI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