@parcha/agentrun-computer 0.1.0-beta.67 → 0.1.0-beta.68
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 +189 -7
- package/box/install.sh +22 -6
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/computerd.json +1 -1
- package/dist/conformance/instabox.d.ts +36 -0
- package/dist/conformance/instabox.js +43 -0
- package/dist/conformance/sprites.d.ts +32 -0
- package/dist/conformance/sprites.js +40 -0
- package/dist/conformance/vercel.d.ts +35 -0
- package/dist/conformance/vercel.js +43 -0
- package/dist/descriptors/e2b.d.ts +13 -0
- package/dist/descriptors/e2b.js +18 -3
- package/dist/descriptors/index.d.ts +73 -1
- package/dist/descriptors/index.js +7 -2
- package/dist/descriptors/instabox.d.ts +19 -0
- package/dist/descriptors/instabox.js +20 -0
- package/dist/descriptors/sprites.d.ts +19 -0
- package/dist/descriptors/sprites.js +19 -0
- package/dist/descriptors/vercel.d.ts +23 -0
- package/dist/descriptors/vercel.js +24 -0
- package/dist/docker/egress-main.js +17 -10
- package/dist/docker/egress-proxy.d.ts +7 -0
- package/dist/docker/egress-proxy.js +12 -0
- package/dist/docker/egress.d.ts +3 -1
- package/dist/docker/egress.js +11 -4
- package/dist/docker/image.d.ts +8 -2
- package/dist/docker/image.js +24 -3
- package/dist/docker.d.ts +6 -0
- package/dist/docker.js +15 -5
- package/dist/e2b.d.ts +25 -10
- package/dist/e2b.js +36 -16
- package/dist/hosted/provider.js +14 -8
- package/dist/hosted/rest.js +23 -1
- package/dist/hosted/ssh-exec.d.ts +17 -2
- package/dist/hosted/ssh-exec.js +17 -6
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/instabox.d.ts +30 -0
- package/dist/instabox.js +424 -0
- package/dist/render.js +4 -3
- package/dist/sprites.d.ts +37 -0
- package/dist/sprites.js +309 -0
- package/dist/vercel.d.ts +26 -0
- package/dist/vercel.js +262 -0
- package/package.json +17 -2
package/dist/e2b.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export interface E2BConnectionOptions {
|
|
|
14
14
|
domain: string;
|
|
15
15
|
apiUrl: string;
|
|
16
16
|
debug: false;
|
|
17
|
+
httpVersion: "1.1";
|
|
17
18
|
proxy?: string;
|
|
18
19
|
requestTimeoutMs?: number;
|
|
19
20
|
signal?: AbortSignal;
|
|
@@ -26,8 +27,15 @@ export interface E2BProviderOptions extends Omit<HostedOptions, "maxLifetimeMs">
|
|
|
26
27
|
apiKey: string;
|
|
27
28
|
/** The SDK's Sandbox class: the host's `e2b` package's. */
|
|
28
29
|
Sandbox: E2BSandboxClass;
|
|
29
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* E2B's domain, or that of a cloud that speaks E2B's API (serve's AGENTRUN_E2B_DOMAIN): each sandbox's envd is under it,
|
|
32
|
+
* and the API is https://api.<domain> unless apiUrl names another. Default e2b.app.
|
|
33
|
+
*/
|
|
30
34
|
domain?: string;
|
|
35
|
+
/** The API's URL, for a cloud whose API is not https://api.<domain> (serve's AGENTRUN_E2B_API_URL): https, no login, query or fragment. */
|
|
36
|
+
apiUrl?: string;
|
|
37
|
+
/** The template prepareImage() answers, in place of the box template (serve's AGENTRUN_E2B_TEMPLATE): an E2B template's name or id. */
|
|
38
|
+
template?: string;
|
|
31
39
|
/** desktop (default): a template with an X server, started through the daemon; linux: no screen. */
|
|
32
40
|
kind?: "desktop" | "linux";
|
|
33
41
|
/** The longest lifetime check takes: E2B Hobby's 1 h by default, Pro's 24 h at most. */
|
|
@@ -48,10 +56,15 @@ export interface E2BOptions extends Omit<E2BProviderOptions, "Sandbox"> {
|
|
|
48
56
|
/** The SDK's Sandbox class; the e2b package's by default. */
|
|
49
57
|
Sandbox?: E2BSandboxClass;
|
|
50
58
|
}
|
|
51
|
-
/**
|
|
52
|
-
|
|
59
|
+
/**
|
|
60
|
+
* The connection options every SDK call is given: the API at apiUrl when given, else https://api.<domain>. Exported for
|
|
61
|
+
* the test that hands them to the real SDK. The SDK sends every call through its one proxy, so it is given one unless
|
|
62
|
+
* NO_PROXY exempts the whole domain (proxyForDomain) and a given API URL's host too.
|
|
63
|
+
*/
|
|
64
|
+
export declare function connectionOptions({ apiKey, domain, apiUrl }: {
|
|
53
65
|
apiKey: string;
|
|
54
66
|
domain: string;
|
|
67
|
+
apiUrl?: string;
|
|
55
68
|
}, env?: ProxyEnv): E2BConnectionOptions;
|
|
56
69
|
/**
|
|
57
70
|
* An E2BProvider from its options alone; it reads no environment but the guard ambientProblem keeps. The key is
|
|
@@ -64,16 +77,18 @@ export declare function create(options: E2BOptions): Promise<E2BProvider>;
|
|
|
64
77
|
export declare const conformance: () => Promise<typeof import("./conformance/e2b.js")>;
|
|
65
78
|
/**
|
|
66
79
|
* Computers that are E2B sandboxes, on the shared adapter. A spec's image is an E2B template (its name or id). A server
|
|
67
|
-
* starts every one, sandbox or desktop, from the
|
|
68
|
-
* with Archil's client and its root helper, Xvfb, xfwm4 and the desktop's apps, which the provider
|
|
69
|
-
* computerd (desktop.ts). Any other template a spec
|
|
80
|
+
* starts every one, sandbox or desktop, from the template prepareImage() answers: by default the box template, the box
|
|
81
|
+
* image (box/Dockerfile) with Archil's client and its root helper, Xvfb, xfwm4 and the desktop's apps, which the provider
|
|
82
|
+
* starts through computerd (desktop.ts). Any other template, options.template's or a spec's, must carry what the
|
|
83
|
+
* computer's kind needs.
|
|
70
84
|
*/
|
|
71
85
|
export declare class E2BProvider extends HostedProvider {
|
|
86
|
+
#private;
|
|
72
87
|
/**
|
|
73
|
-
* The provider contract's prepareImage (its descriptor declares it): the
|
|
74
|
-
* public under its E2B team (box-image.ts boxE2bTemplate), which any E2B account
|
|
75
|
-
* starts a
|
|
76
|
-
* from the same template as a sandbox: the kind is the provider's, not the image's.
|
|
88
|
+
* The provider contract's prepareImage (its descriptor declares it): the template options.template names, else the
|
|
89
|
+
* box template the release publishes, public under its E2B team (box-image.ts boxE2bTemplate), which any E2B account
|
|
90
|
+
* starts by that name. No call: E2B starts a template at create with nothing to pull ahead of it, so onWait is never
|
|
91
|
+
* told. A desktop starts from the same template as a sandbox: the kind is the provider's, not the image's.
|
|
77
92
|
*/
|
|
78
93
|
prepareImage(): Promise<Result<string>>;
|
|
79
94
|
constructor(options: E2BProviderOptions);
|
package/dist/e2b.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { boxE2bTemplate } from "./box-image.js";
|
|
2
2
|
import { E2B } from "./descriptors/e2b.js";
|
|
3
3
|
import { DEADLINE_LABEL, show } from "./drift.js";
|
|
4
|
-
import { installedProxy, proxyForDomain } from "./env-proxy.js";
|
|
4
|
+
import { installedProxy, proxyFor, proxyForDomain } from "./env-proxy.js";
|
|
5
5
|
import { HostError } from "./host.js";
|
|
6
6
|
import { deadlineOf, HostedProvider, isoOf, MAX_LABEL, timeoutsOf } from "./hosted/provider.js";
|
|
7
|
+
import { httpsBase } from "./hosted/rest.js";
|
|
7
8
|
import { dialLaunch } from "./hosted/scripts.js";
|
|
8
9
|
import { connectOf } from "./descriptor.js";
|
|
9
10
|
import { dateOf, DOMAIN, isWhole, sizeRefusals } from "./hosted/values.js";
|
|
@@ -11,10 +12,18 @@ import { PassThrough } from "node:stream";
|
|
|
11
12
|
import { ok } from "./result.js";
|
|
12
13
|
import { vendorSdk } from "./vendor-sdk.js";
|
|
13
14
|
const DEFAULT_DOMAIN = "e2b.app";
|
|
14
|
-
/** The
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
/** The server's name for the setting that fills `option` (its descriptor's key), for words that name what to fix. */
|
|
16
|
+
const settingName = (option) => E2B.keys.find((key) => key.option === option)?.name ?? option;
|
|
17
|
+
/**
|
|
18
|
+
* The connection options every SDK call is given: the API at apiUrl when given, else https://api.<domain>. Exported for
|
|
19
|
+
* the test that hands them to the real SDK. The SDK sends every call through its one proxy, so it is given one unless
|
|
20
|
+
* NO_PROXY exempts the whole domain (proxyForDomain) and a given API URL's host too.
|
|
21
|
+
*/
|
|
22
|
+
export function connectionOptions({ apiKey, domain, apiUrl }, env = installedProxy()) {
|
|
23
|
+
const proxy = proxyForDomain(domain, env) ?? (apiUrl === undefined ? undefined : proxyFor(new URL(apiUrl), env));
|
|
24
|
+
// HTTP/1.1 alone: when an idle HTTP/2 session times out, the SDK's undici client throws on a stream no one listens to,
|
|
25
|
+
// and that unhandled 'error' ends the whole process (index.mjs buildDispatchedFetch, allowH2 unless httpVersion "1.1").
|
|
26
|
+
return { apiKey, domain, apiUrl: apiUrl ?? `https://api.${domain}`, debug: false, httpVersion: "1.1", ...(proxy ? { proxy: proxy.href } : {}) };
|
|
18
27
|
}
|
|
19
28
|
/**
|
|
20
29
|
* The SDK takes sandboxUrl from E2B_SANDBOX_URL when it is given none (index.mjs:1152, 1183-1185), and no option can
|
|
@@ -378,25 +387,28 @@ class E2BHost {
|
|
|
378
387
|
}
|
|
379
388
|
/**
|
|
380
389
|
* Computers that are E2B sandboxes, on the shared adapter. A spec's image is an E2B template (its name or id). A server
|
|
381
|
-
* starts every one, sandbox or desktop, from the
|
|
382
|
-
* with Archil's client and its root helper, Xvfb, xfwm4 and the desktop's apps, which the provider
|
|
383
|
-
* computerd (desktop.ts). Any other template a spec
|
|
390
|
+
* starts every one, sandbox or desktop, from the template prepareImage() answers: by default the box template, the box
|
|
391
|
+
* image (box/Dockerfile) with Archil's client and its root helper, Xvfb, xfwm4 and the desktop's apps, which the provider
|
|
392
|
+
* starts through computerd (desktop.ts). Any other template, options.template's or a spec's, must carry what the
|
|
393
|
+
* computer's kind needs.
|
|
384
394
|
*/
|
|
385
395
|
export class E2BProvider extends HostedProvider {
|
|
396
|
+
/** The template options.template names, or undefined for the box template. */
|
|
397
|
+
#template;
|
|
386
398
|
/**
|
|
387
|
-
* The provider contract's prepareImage (its descriptor declares it): the
|
|
388
|
-
* public under its E2B team (box-image.ts boxE2bTemplate), which any E2B account
|
|
389
|
-
* starts a
|
|
390
|
-
* from the same template as a sandbox: the kind is the provider's, not the image's.
|
|
399
|
+
* The provider contract's prepareImage (its descriptor declares it): the template options.template names, else the
|
|
400
|
+
* box template the release publishes, public under its E2B team (box-image.ts boxE2bTemplate), which any E2B account
|
|
401
|
+
* starts by that name. No call: E2B starts a template at create with nothing to pull ahead of it, so onWait is never
|
|
402
|
+
* told. A desktop starts from the same template as a sandbox: the kind is the provider's, not the image's.
|
|
391
403
|
*/
|
|
392
404
|
async prepareImage() {
|
|
393
|
-
return ok(boxE2bTemplate());
|
|
405
|
+
return ok(this.#template ?? boxE2bTemplate());
|
|
394
406
|
}
|
|
395
407
|
constructor(options) {
|
|
396
408
|
// A caller who still names the option is told it is gone, whatever its value: it once let public traffic in.
|
|
397
409
|
if (typeof options === "object" && options !== null && Object.hasOwn(options, "publicStream"))
|
|
398
410
|
throw new Error(PUBLIC);
|
|
399
|
-
const { apiKey, Sandbox, domain = DEFAULT_DOMAIN, kind = "desktop", maxLifetimeMs = HOBBY_MAX_MS, connect, ...rest } = options;
|
|
411
|
+
const { apiKey, Sandbox, domain = DEFAULT_DOMAIN, apiUrl, template, kind = "desktop", maxLifetimeMs = HOBBY_MAX_MS, connect, ...rest } = options;
|
|
400
412
|
const via = connectOf(E2B, { connect });
|
|
401
413
|
if (typeof apiKey !== "string" || apiKey === "")
|
|
402
414
|
throw new Error("options.apiKey, the E2B API key, is required: the provider reads no environment, so the caller passes it");
|
|
@@ -407,7 +419,15 @@ export class E2BProvider extends HostedProvider {
|
|
|
407
419
|
if (ambient)
|
|
408
420
|
throw new Error(ambient);
|
|
409
421
|
if (typeof domain !== "string" || !DOMAIN.test(domain))
|
|
410
|
-
throw new Error(`the E2B domain must be a host name such as ${DEFAULT_DOMAIN}, not ${JSON.stringify(domain)}`);
|
|
411
|
-
|
|
422
|
+
throw new Error(`the E2B domain (${settingName("domain")}) must be a host name such as ${DEFAULT_DOMAIN}, not ${JSON.stringify(domain)}`);
|
|
423
|
+
// The key goes to the API URL: https alone, and words that give its origin alone (httpsBase).
|
|
424
|
+
const api = apiUrl === undefined ? undefined : httpsBase(String(apiUrl), `the E2B API URL (${settingName("apiUrl")})`);
|
|
425
|
+
// Trimmed, as serve reads the same setting to select it (resolve-computer.ts registryHere, computer-deps.ts computerSpecOf).
|
|
426
|
+
const named = typeof template === "string" ? template.trim() : template;
|
|
427
|
+
if (named !== undefined && (typeof named !== "string" || !TEMPLATE.test(named))) {
|
|
428
|
+
throw new Error(`the E2B template (${settingName("template")}) is the name or id of an E2B template, such as "${boxE2bTemplate()}" (the box template), not ${JSON.stringify(template)}`);
|
|
429
|
+
}
|
|
430
|
+
super(new E2BHost(Sandbox, connectionOptions({ apiKey, domain, ...(api === undefined ? {} : { apiUrl: api }) }), timeoutsOf(rest.timeouts).requestMs, via), { ...rest, kind, maxLifetimeMs });
|
|
431
|
+
this.#template = named;
|
|
412
432
|
}
|
|
413
433
|
}
|
package/dist/hosted/provider.js
CHANGED
|
@@ -580,8 +580,11 @@ export class HostedProvider {
|
|
|
580
580
|
return launched.error.code === "exists" ? this.#createOnce(spec, name, signal, launched) : launched;
|
|
581
581
|
const { ref, made } = launched.value;
|
|
582
582
|
// From here the machine exists: every step takes the caller's signal, and a failure or an abort deletes it.
|
|
583
|
-
// Another provider instance's create of this request may have made one too (#converge): the oldest is kept.
|
|
584
|
-
|
|
583
|
+
// Another provider instance's create of this request may have made one too (#converge): the oldest is kept. This
|
|
584
|
+
// first look may narrow by this spec's run and epoch (nameAsk: Render's one page by the whole name, not every page of
|
|
585
|
+
// the workspace). It only stops a create early: a machine of the request under another run or epoch is settled by
|
|
586
|
+
// the reads below, which never narrow, as each racing create makes them.
|
|
587
|
+
const first = await this.#converge(name, ref.id, signal, nameAsk(this.host, spec));
|
|
585
588
|
if (first.ok && first.value !== undefined && first.value.id !== ref.id)
|
|
586
589
|
return this.#again(spec, name, first.value, signal);
|
|
587
590
|
const prepared = await this.#prepare(spec, ref, made, signal);
|
|
@@ -631,11 +634,12 @@ export class HostedProvider {
|
|
|
631
634
|
* more than one machine holds the name, the oldest (createdAt, or the lowest id where any has none) is kept, and every
|
|
632
635
|
* other is deleted and read back gone, its Archil folder let go first. Every instance picks the same one from the
|
|
633
636
|
* same listing. Its value is the machine kept, or undefined when mine holds the name alone (or nothing is listed yet).
|
|
634
|
-
* The listing
|
|
635
|
-
* must still see each other's machine, so one is
|
|
637
|
+
* The listing that settles a create (after a failed prepare, and the last) is by the name alone, never narrowed
|
|
638
|
+
* (nameAsk): two creates of one request that ask another run or epoch must still see each other's machine, so one is
|
|
639
|
+
* kept and the other answered exists. `also` narrows the first look after the vendor's answer alone (#createOnce).
|
|
636
640
|
*/
|
|
637
|
-
async #converge(name, mine, signal) {
|
|
638
|
-
const listed = await foundBy(this.host, "the listing by the request's name", byName(name), this.#timeouts, signal);
|
|
641
|
+
async #converge(name, mine, signal, also) {
|
|
642
|
+
const listed = await foundBy(this.host, "the listing by the request's name", byName(name), this.#timeouts, signal, also);
|
|
639
643
|
if (!listed.ok)
|
|
640
644
|
return listed;
|
|
641
645
|
const holders = listed.value.filter((machine) => ours(machine.labels, name) && alive(machine.state));
|
|
@@ -1776,8 +1780,10 @@ const byName = (name) => ({ [COMPUTER_LABEL]: "1", [NAME_LABEL]: name });
|
|
|
1776
1780
|
* What a listing by a create's name asks beside byName on a host whose names carry the run and epoch (facts.labels.named):
|
|
1777
1781
|
* the spec's run and epoch, where it has both, so the host can look up the whole name. Only asked, never required: a
|
|
1778
1782
|
* machine of the name is kept whatever its get says of them (a sandbox before its labels file, read by its name alone).
|
|
1779
|
-
* Only the sweeps for a machine this create made ask it (#waitListed, #deleteNamed)
|
|
1780
|
-
*
|
|
1783
|
+
* Only the sweeps for a machine this create made ask it (#waitListed, #deleteNamed), and the first look for a racing
|
|
1784
|
+
* create's machine right after the vendor's answer, which only stops a create early: that machine's name is the whole
|
|
1785
|
+
* name. The first check and the convergence that settles a create look for any machine of the request, whatever run or
|
|
1786
|
+
* epoch it was made with.
|
|
1781
1787
|
*/
|
|
1782
1788
|
function nameAsk(host, spec) {
|
|
1783
1789
|
const run = spec.labels?.[RUN_LABEL];
|
package/dist/hosted/rest.js
CHANGED
|
@@ -35,6 +35,19 @@ export function jsonOf(bytes) {
|
|
|
35
35
|
return null;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* A Retry-After's wait in ms (RFC 9110 10.2.3): delay-seconds, or an HTTP date (0 once it has passed); undefined for no
|
|
40
|
+
* header or words that are neither.
|
|
41
|
+
*/
|
|
42
|
+
function retryAfterMs(value) {
|
|
43
|
+
if (value === null)
|
|
44
|
+
return undefined;
|
|
45
|
+
const text = value.trim();
|
|
46
|
+
if (/^[0-9]+$/.test(text))
|
|
47
|
+
return Number(text) * 1000;
|
|
48
|
+
const at = Date.parse(text);
|
|
49
|
+
return Number.isNaN(at) ? undefined : Math.max(0, at - Date.now());
|
|
50
|
+
}
|
|
38
51
|
/** Whether fetch failed on a redirect it was told not to follow. */
|
|
39
52
|
function redirected(cause) {
|
|
40
53
|
const inner = cause?.cause;
|
|
@@ -115,6 +128,8 @@ export function rest(options) {
|
|
|
115
128
|
bound?.addEventListener("abort", cut, { once: true });
|
|
116
129
|
let failure;
|
|
117
130
|
let retryable;
|
|
131
|
+
// The wait a refused answer's Retry-After asks of a retry.
|
|
132
|
+
let asked;
|
|
118
133
|
try {
|
|
119
134
|
const headers = init.json === undefined ? options.headers() : { ...options.headers(), "Content-Type": "application/json" };
|
|
120
135
|
const either = signal ? AbortSignal.any([signal, timeout.signal]) : timeout.signal;
|
|
@@ -131,6 +146,7 @@ export function rest(options) {
|
|
|
131
146
|
const bytes = await bytesOf(response, either);
|
|
132
147
|
const own = typeof init.retry === "function";
|
|
133
148
|
retryable = own ? init.retry(response.status, bytes) : init.retry === true && (response.status === 429 || response.status >= 500);
|
|
149
|
+
asked = retryable ? retryAfterMs(response.headers.get("retry-after")) : undefined;
|
|
134
150
|
const text = decoder.decode(bytes).replace(/\s+/g, " ").slice(0, 300);
|
|
135
151
|
const said = options.explain?.({ status: response.status, bytes, text, what }) ?? {};
|
|
136
152
|
failure = errorOf(said.code ?? httpCode(response.status, init.named), said.message ?? `${what}: ${response.status} ${text}`, options.vendor);
|
|
@@ -155,7 +171,13 @@ export function rest(options) {
|
|
|
155
171
|
}
|
|
156
172
|
if (!retryable || attempt >= attempts)
|
|
157
173
|
return { ok: false, error: failure };
|
|
158
|
-
|
|
174
|
+
// A send before the vendor's Retry-After is refused again, so the pause is the longer of it and the backoff. A
|
|
175
|
+
// Retry-After past the call's bound is not waited out: the call fails now, its words giving the wait.
|
|
176
|
+
if (asked !== undefined && asked > timeoutMs) {
|
|
177
|
+
const message = `${failure.message}; the vendor asks a retry to wait (Retry-After ${Math.round(asked / 100) / 10} s), past the call's bound of ${Math.round(timeoutMs / 100) / 10} s`;
|
|
178
|
+
return { ok: false, error: { ...failure, message } };
|
|
179
|
+
}
|
|
180
|
+
await wait(Math.max((options.retry?.baseMs ?? 0) * 2 ** (attempt - 1), asked ?? 0), signal);
|
|
159
181
|
}
|
|
160
182
|
}
|
|
161
183
|
const call = (method, url, init = {}, signal) => exchange(method, url, init, signal, async (response, cut) => ({ status: response.status, bytes: await bytesOf(response, cut) }));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Duplex } from "node:stream";
|
|
2
|
-
import type
|
|
2
|
+
import { type HostCall, type MachineProcess } from "../host.js";
|
|
3
3
|
/** A readable side of an ssh2 channel, as this provider uses it: piped, or drained. */
|
|
4
4
|
export interface Ssh2Readable {
|
|
5
5
|
pipe(destination: NodeJS.WritableStream): unknown;
|
|
@@ -29,6 +29,8 @@ export interface Ssh2ConnectConfig {
|
|
|
29
29
|
readyTimeout: number;
|
|
30
30
|
keepaliveInterval: number;
|
|
31
31
|
keepaliveCountMax: number;
|
|
32
|
+
/** Given the server's host key (its SSH wire blob), whether to go on: false ends the handshake before any login. */
|
|
33
|
+
hostVerifier?: (key: Buffer) => boolean;
|
|
32
34
|
}
|
|
33
35
|
/** The slice of an ssh2 Client this provider uses. */
|
|
34
36
|
export interface Ssh2Client {
|
|
@@ -68,7 +70,15 @@ export interface SshLogin {
|
|
|
68
70
|
password?: string;
|
|
69
71
|
/** What no error may carry, beside the key and the password, which never do: a key inside the username (Morph's). */
|
|
70
72
|
secrets?: readonly string[];
|
|
73
|
+
/**
|
|
74
|
+
* The sshd's host key, as OpenSSH's sha256 fingerprint (SHA256: and unpadded base64): a server with another key ends
|
|
75
|
+
* the handshake before the login is sent, and is not tried again. For a login that carries a credential (InstaBox's
|
|
76
|
+
* token as the username), which a host posing as the gateway would otherwise read.
|
|
77
|
+
*/
|
|
78
|
+
hostKey?: string;
|
|
71
79
|
}
|
|
80
|
+
/** A host key pin's form, OpenSSH's sha256 fingerprint: SHA256: and 43 characters of unpadded base64. */
|
|
81
|
+
export declare const HOST_KEY_PIN: RegExp;
|
|
72
82
|
export interface SshExecOptions {
|
|
73
83
|
/** The host's own ssh2 package, or anything with the same slice. */
|
|
74
84
|
ssh2: Ssh2Module;
|
|
@@ -81,11 +91,16 @@ export interface SshExecOptions {
|
|
|
81
91
|
* or past: a refused login fails at once.
|
|
82
92
|
*/
|
|
83
93
|
deniedUntil?: (id: string) => number;
|
|
94
|
+
/**
|
|
95
|
+
* Every login must carry hostKey of HOST_KEY_PIN's form: one without is refused (vendor) before its tunnel opens, so
|
|
96
|
+
* its credential never leaves. For a host whose login is itself a credential (InstaBox's token as the username).
|
|
97
|
+
*/
|
|
98
|
+
pinned?: boolean;
|
|
84
99
|
}
|
|
85
100
|
/** MachineHost.exec over SSH: argv as the host's login, as channels on one connection per machine, shared by its execs. */
|
|
86
101
|
export declare class SshExec {
|
|
87
102
|
#private;
|
|
88
|
-
constructor({ ssh2, loginOf, tunnelOf, deniedUntil }: SshExecOptions);
|
|
103
|
+
constructor({ ssh2, loginOf, tunnelOf, deniedUntil, pinned }: SshExecOptions);
|
|
89
104
|
/** Ends every connection to machine id, channels and all: the vendor calls it once the machine is deleted. */
|
|
90
105
|
closeAll(id: string): void;
|
|
91
106
|
/**
|
package/dist/hosted/ssh-exec.js
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
// the machine's sshd (Agent37's WebSocket tunnel) and as the login the host gives (Agent37's root and key). Every error it throws or
|
|
4
4
|
// rejects with is redacted of the login's secrets. The host's own ssh2 package does the protocol; this package names
|
|
5
5
|
// only the slice it uses (Ssh2Module) and imports nothing at load.
|
|
6
|
-
import { createPrivateKey, randomBytes } from "node:crypto";
|
|
6
|
+
import { createHash, createPrivateKey, randomBytes } from "node:crypto";
|
|
7
7
|
import { PassThrough } from "node:stream";
|
|
8
|
+
import { HostError } from "../host.js";
|
|
8
9
|
import { boundOf, redact } from "./process.js";
|
|
9
10
|
import { PID_WRAPPER, pidKill, pidStderr, shellLine } from "./scripts.js";
|
|
10
11
|
import { sshString } from "./ssh-key.js";
|
|
@@ -48,6 +49,10 @@ const isBound = (error) => {
|
|
|
48
49
|
const name = error?.name;
|
|
49
50
|
return name === "TimeoutError" || name === "AbortError";
|
|
50
51
|
};
|
|
52
|
+
/** OpenSSH's sha256 fingerprint of a host key's wire blob. */
|
|
53
|
+
const fingerprintOf = (key) => `SHA256:${createHash("sha256").update(key).digest("base64").replace(/=+$/, "")}`;
|
|
54
|
+
/** A host key pin's form, OpenSSH's sha256 fingerprint: SHA256: and 43 characters of unpadded base64. */
|
|
55
|
+
export const HOST_KEY_PIN = /^SHA256:[A-Za-z0-9+/]{43}$/;
|
|
51
56
|
/** The pause between two logins an sshd refused, while deniedUntil says the key may still reach it. */
|
|
52
57
|
const DENIED_RETRY_MS = 2_000;
|
|
53
58
|
/** MachineHost.exec over SSH: argv as the host's login, as channels on one connection per machine, shared by its execs. */
|
|
@@ -56,16 +61,18 @@ export class SshExec {
|
|
|
56
61
|
#loginOf;
|
|
57
62
|
#tunnelOf;
|
|
58
63
|
#deniedUntil;
|
|
64
|
+
#pinned;
|
|
59
65
|
/**
|
|
60
66
|
* The SSH connections to each machine, opening, open, or done and still held, until each ends: one, and a second
|
|
61
67
|
* past CHANNELS_PER_CONNECTION channels. A done one takes no new channel; closeAll ends them all.
|
|
62
68
|
*/
|
|
63
69
|
#links = new Map();
|
|
64
|
-
constructor({ ssh2, loginOf, tunnelOf, deniedUntil }) {
|
|
70
|
+
constructor({ ssh2, loginOf, tunnelOf, deniedUntil, pinned = false }) {
|
|
65
71
|
this.#ssh2 = ssh2;
|
|
66
72
|
this.#loginOf = loginOf;
|
|
67
73
|
this.#tunnelOf = tunnelOf;
|
|
68
74
|
this.#deniedUntil = deniedUntil;
|
|
75
|
+
this.#pinned = pinned;
|
|
69
76
|
}
|
|
70
77
|
/** Ends every connection to machine id, channels and all: the vendor calls it once the machine is deleted. */
|
|
71
78
|
closeAll(id) {
|
|
@@ -112,10 +119,15 @@ export class SshExec {
|
|
|
112
119
|
}
|
|
113
120
|
}
|
|
114
121
|
/**
|
|
115
|
-
* One tunnel and one SSH handshake over it
|
|
116
|
-
* WebSocket (opening or open), the stream and the
|
|
122
|
+
* One tunnel and one SSH handshake over it, the login had first: a pinned exec's login with no pin opens no tunnel.
|
|
123
|
+
* On a failure, or once stop aborts before the handshake is done, the WebSocket (opening or open), the stream and the
|
|
124
|
+
* client are dropped.
|
|
117
125
|
*/
|
|
118
126
|
async #handshake(id, timeoutMs, stop) {
|
|
127
|
+
const { username, privateKey, password, hostKey } = this.#loginOf(id);
|
|
128
|
+
if (this.#pinned && !(typeof hostKey === "string" && HOST_KEY_PIN.test(hostKey))) {
|
|
129
|
+
throw new HostError("vendor", `the SSH login to ${id} names no host key (SHA256:...) to pin its sshd by, and this host pins every login: no connection was made`);
|
|
130
|
+
}
|
|
119
131
|
const { duplex, opened, host } = this.#tunnelOf(id);
|
|
120
132
|
const client = new this.#ssh2.Client();
|
|
121
133
|
const givenUp = () => new SshTunnelError(`the SSH tunnel to ${host} was given up on`);
|
|
@@ -130,14 +142,13 @@ export class SshExec {
|
|
|
130
142
|
quit(givenUp());
|
|
131
143
|
};
|
|
132
144
|
stop.addEventListener("abort", drop, { once: true });
|
|
133
|
-
const { username, privateKey, password } = this.#loginOf(id);
|
|
134
145
|
try {
|
|
135
146
|
await Promise.race([opened, quitted]);
|
|
136
147
|
await Promise.race([
|
|
137
148
|
new Promise((resolve, reject) => {
|
|
138
149
|
client.once("ready", resolve);
|
|
139
150
|
client.once("error", reject);
|
|
140
|
-
client.connect({ sock: duplex, username, privateKey, password, readyTimeout: timeoutMs, keepaliveInterval: KEEPALIVE_MS, keepaliveCountMax: KEEPALIVE_COUNT_MAX });
|
|
151
|
+
client.connect({ sock: duplex, username, privateKey, password, readyTimeout: timeoutMs, keepaliveInterval: KEEPALIVE_MS, keepaliveCountMax: KEEPALIVE_COUNT_MAX, ...(hostKey === undefined ? {} : { hostVerifier: (key) => fingerprintOf(key) === hostKey }) });
|
|
141
152
|
}),
|
|
142
153
|
quitted,
|
|
143
154
|
]);
|
package/dist/index.d.ts
CHANGED
|
@@ -16,9 +16,10 @@ export type { HostCall, HostFacts, Machine, MachineHost, MachineProcess, Machine
|
|
|
16
16
|
export { HostedProvider, type HostedDial, type HostedOptions, type HostedTimeouts, hostedDaemonPath } from "./hosted/provider.js";
|
|
17
17
|
export { httpsBase, keyBase } from "./hosted/rest.js";
|
|
18
18
|
export { type DockerVolume, VOLUME_SUBPATH_ENGINE } from "./docker/volume.js";
|
|
19
|
-
export { DEFAULT_DOCKER_IMAGE, DOCKER_BASE, DOCKER_RECIPE, DOCKER_RECIPE_HAS, ensureImage, type EnsureImageOptions, IMAGE_REPOSITORY, IMAGE_TIMEOUT_MS, type ImageSource, imageSourceProblem, type Making, RECIPE_LABEL, recipeHash, recipeTag, } from "./docker/image.js";
|
|
19
|
+
export { DEFAULT_DOCKER_IMAGE, DOCKER_BASE, DOCKER_NODE_SHA256, DOCKER_NODE_VERSION, DOCKER_RECIPE, DOCKER_RECIPE_HAS, ensureImage, type EnsureImageOptions, IMAGE_REPOSITORY, IMAGE_TIMEOUT_MS, type ImageSource, imageSourceProblem, type Making, RECIPE_LABEL, recipeHash, recipeTag, } from "./docker/image.js";
|
|
20
20
|
export { ADB_ENV_NAMES, adbEnv, BASE_ENV_NAMES, CHROME_ENV_NAMES, childEnv, chromeEnv, DOCKER_ENV_NAMES, dockerEnv, type HostEnv } from "./child-env.js";
|
|
21
21
|
export { containerSigns, EGRESS_IMAGE, EGRESS_LABEL, EGRESS_MOUNT, EGRESS_SOCKET } from "./docker/egress.js";
|
|
22
|
+
export { DEFAULT_MAX_TUNNELS, MAX_TUNNELS_CEILING, maxTunnelsOf } from "./docker/egress-proxy.js";
|
|
22
23
|
export { ARCHIL_HELPER, ARCHIL_SYNC_SOCKET, ARCHIL_TOOL_UID, ARCHIL_TOOL_USER, ARCHIL_VERSION, type ArchilMount, type ArchilEgress, type ArchilMountOptions, type ArchilRoot, type ProviderNote, archilEgressOf, archilLabels, archilMount, archilReadBack, archilRefusals, archilRelease, archilSync, claimEpoch, helperSha256, MOUNT_LABEL, mountDrift, mountWords, type RecordedFolder, type RecordedSource, readMount, recordedFolder, recordedMount, SYNC_LABELS, syncingClient, } from "./mount-archil.js";
|
|
23
24
|
export { type BrowserComputerProvider, type BrowserDownloads, type BrowserFile, type BrowserProfiles, type BrowserSessionUsage, browserSpecRefusals, type BrowserStream, isBrowserProvider, BrowserVendorError, CREATE_LABEL, ATTEMPT_LABEL, causeOf, memoryUrls, RECOVER_MS, recoverCreate, recoveriesInFlight, type RecoveryInFlight, type ReleaseConfirm, type RestReply, type UrlStore, } from "./browser.js";
|
|
24
25
|
export { CHROME_ENV, CHROME_FLAGS, checkChrome, chromeFence, findChrome, killTree, NO_CHROME } from "./chrome.js";
|
package/dist/index.js
CHANGED
|
@@ -20,9 +20,10 @@ export { httpsBase, keyBase } from "./hosted/rest.js";
|
|
|
20
20
|
// (providerFor), or from its own subpath (@parcha/agentrun-computer/docker, /daytona, /modal, /e2b, /agent37, /morph, /orgo,
|
|
21
21
|
// /phone-harness, /browserbase, /kernel, /local, /smolcloud, /groundbox: each the provider file's name).
|
|
22
22
|
export { VOLUME_SUBPATH_ENGINE } from "./docker/volume.js";
|
|
23
|
-
export { DEFAULT_DOCKER_IMAGE, DOCKER_BASE, DOCKER_RECIPE, DOCKER_RECIPE_HAS, ensureImage, IMAGE_REPOSITORY, IMAGE_TIMEOUT_MS, imageSourceProblem, RECIPE_LABEL, recipeHash, recipeTag, } from "./docker/image.js";
|
|
23
|
+
export { DEFAULT_DOCKER_IMAGE, DOCKER_BASE, DOCKER_NODE_SHA256, DOCKER_NODE_VERSION, DOCKER_RECIPE, DOCKER_RECIPE_HAS, ensureImage, IMAGE_REPOSITORY, IMAGE_TIMEOUT_MS, imageSourceProblem, RECIPE_LABEL, recipeHash, recipeTag, } from "./docker/image.js";
|
|
24
24
|
export { ADB_ENV_NAMES, adbEnv, BASE_ENV_NAMES, CHROME_ENV_NAMES, childEnv, chromeEnv, DOCKER_ENV_NAMES, dockerEnv } from "./child-env.js";
|
|
25
25
|
export { containerSigns, EGRESS_IMAGE, EGRESS_LABEL, EGRESS_MOUNT, EGRESS_SOCKET } from "./docker/egress.js";
|
|
26
|
+
export { DEFAULT_MAX_TUNNELS, MAX_TUNNELS_CEILING, maxTunnelsOf } from "./docker/egress-proxy.js";
|
|
26
27
|
export { ARCHIL_HELPER, ARCHIL_SYNC_SOCKET, ARCHIL_TOOL_UID, ARCHIL_TOOL_USER, ARCHIL_VERSION, archilEgressOf, archilLabels, archilMount, archilReadBack, archilRefusals, archilRelease, archilSync, claimEpoch, helperSha256, MOUNT_LABEL, mountDrift, mountWords, readMount, recordedFolder, recordedMount, SYNC_LABELS, syncingClient, } from "./mount-archil.js";
|
|
27
28
|
export { browserSpecRefusals, isBrowserProvider, BrowserVendorError, CREATE_LABEL, ATTEMPT_LABEL, causeOf, memoryUrls, RECOVER_MS, recoverCreate, recoveriesInFlight, } from "./browser.js";
|
|
28
29
|
// Local Chrome's provider class is on its provider id's subpath (@parcha/agentrun-computer/local-chrome), as every
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { HostedProvider, type HostedOptions } from "./hosted/provider.js";
|
|
2
|
+
import { type Ssh2Module } from "./hosted/ssh-exec.js";
|
|
3
|
+
/** The InstaBox provider's options: the key and ssh2, then the shared adapter's (HostedOptions). */
|
|
4
|
+
export interface InstaboxProviderOptions extends Omit<HostedOptions, "kind" | "desktop"> {
|
|
5
|
+
/** The workspace's API key. The caller passes it; this provider never reads it from the environment. */
|
|
6
|
+
apiKey: string;
|
|
7
|
+
/** The ssh2 package: the host's own, or anything with the same slice. */
|
|
8
|
+
ssh2: Ssh2Module;
|
|
9
|
+
/** The fetch every REST call goes through; default the global one. */
|
|
10
|
+
fetch?: typeof fetch;
|
|
11
|
+
/** The API's root; default https://api.instabox.sh. */
|
|
12
|
+
apiUrl?: string;
|
|
13
|
+
}
|
|
14
|
+
/** What create() takes: the provider's options, ssh2 optional (default the host's ssh2 package). */
|
|
15
|
+
export interface InstaboxOptions extends Omit<InstaboxProviderOptions, "ssh2"> {
|
|
16
|
+
ssh2?: Ssh2Module;
|
|
17
|
+
}
|
|
18
|
+
export declare const DEFAULT_API_URL = "https://api.instabox.sh";
|
|
19
|
+
/** The workspace a key reaches, in words: the key named by its sha256 prefix alone. */
|
|
20
|
+
export declare function accountOf(apiKey: string, apiUrl?: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* An InstaboxProvider from its options alone; it reads no environment. The key is options.apiKey, nowhere else (serve
|
|
23
|
+
* passes its INSTABOX_API_KEY, the conformance module what it reads), and ssh2 is the host's package unless given.
|
|
24
|
+
*/
|
|
25
|
+
export declare function create(options: InstaboxOptions): Promise<InstaboxProvider>;
|
|
26
|
+
export declare const conformance: () => Promise<typeof import("./conformance/instabox.js")>;
|
|
27
|
+
/** Computers that are InstaBox machines, on the shared adapter: a sandbox from an InstaBox template, no desktop. */
|
|
28
|
+
export declare class InstaboxProvider extends HostedProvider {
|
|
29
|
+
constructor(options: InstaboxProviderOptions);
|
|
30
|
+
}
|