@parcha/agentrun-computer 0.0.0-stage → 0.1.0-beta.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +8 -0
  3. package/README.md +2411 -2
  4. package/box/Dockerfile +69 -0
  5. package/box/agentrun-archil +168 -0
  6. package/box/build-daytona.py +26 -0
  7. package/box/build-e2b.mjs +32 -0
  8. package/box/build-modal.py +17 -0
  9. package/dist/actions.d.ts +18 -0
  10. package/dist/actions.js +139 -0
  11. package/dist/browser.d.ts +151 -0
  12. package/dist/browser.js +305 -0
  13. package/dist/browserbase.d.ts +139 -0
  14. package/dist/browserbase.js +408 -0
  15. package/dist/child.d.ts +40 -0
  16. package/dist/child.js +127 -0
  17. package/dist/client.d.ts +22 -0
  18. package/dist/client.js +136 -0
  19. package/dist/computerd-linux-amd64 +0 -0
  20. package/dist/computerd-linux-arm64 +0 -0
  21. package/dist/conformance/archil.d.ts +68 -0
  22. package/dist/conformance/archil.js +152 -0
  23. package/dist/conformance/browserbase.d.ts +35 -0
  24. package/dist/conformance/browserbase.js +45 -0
  25. package/dist/conformance/cases/apps.d.ts +2 -0
  26. package/dist/conformance/cases/apps.js +155 -0
  27. package/dist/conformance/cases/browser.d.ts +4 -0
  28. package/dist/conformance/cases/browser.js +105 -0
  29. package/dist/conformance/cases/drift.d.ts +2 -0
  30. package/dist/conformance/cases/drift.js +64 -0
  31. package/dist/conformance/cases/exec.d.ts +2 -0
  32. package/dist/conformance/cases/exec.js +125 -0
  33. package/dist/conformance/cases/files.d.ts +2 -0
  34. package/dist/conformance/cases/files.js +294 -0
  35. package/dist/conformance/cases/health.d.ts +2 -0
  36. package/dist/conformance/cases/health.js +71 -0
  37. package/dist/conformance/cases/index.d.ts +9 -0
  38. package/dist/conformance/cases/index.js +37 -0
  39. package/dist/conformance/cases/input.d.ts +12 -0
  40. package/dist/conformance/cases/input.js +109 -0
  41. package/dist/conformance/cases/isolation.d.ts +21 -0
  42. package/dist/conformance/cases/isolation.js +98 -0
  43. package/dist/conformance/cases/lifetime.d.ts +2 -0
  44. package/dist/conformance/cases/lifetime.js +64 -0
  45. package/dist/conformance/cases/mount.d.ts +2 -0
  46. package/dist/conformance/cases/mount.js +252 -0
  47. package/dist/conformance/cases/process.d.ts +2 -0
  48. package/dist/conformance/cases/process.js +240 -0
  49. package/dist/conformance/cases/provider.d.ts +2 -0
  50. package/dist/conformance/cases/provider.js +302 -0
  51. package/dist/conformance/cases/screen.d.ts +9 -0
  52. package/dist/conformance/cases/screen.js +230 -0
  53. package/dist/conformance/cases/settings.d.ts +57 -0
  54. package/dist/conformance/cases/settings.js +142 -0
  55. package/dist/conformance/cases/touch.d.ts +2 -0
  56. package/dist/conformance/cases/touch.js +117 -0
  57. package/dist/conformance/cases/util.d.ts +7 -0
  58. package/dist/conformance/cases/util.js +8 -0
  59. package/dist/conformance/cdp.d.ts +13 -0
  60. package/dist/conformance/cdp.js +88 -0
  61. package/dist/conformance/cli.d.ts +29 -0
  62. package/dist/conformance/cli.js +231 -0
  63. package/dist/conformance/daytona-sweep.d.ts +18 -0
  64. package/dist/conformance/daytona-sweep.js +126 -0
  65. package/dist/conformance/daytona.d.ts +83 -0
  66. package/dist/conformance/daytona.js +107 -0
  67. package/dist/conformance/docker.d.ts +38 -0
  68. package/dist/conformance/docker.js +70 -0
  69. package/dist/conformance/drift-daemon.d.ts +8 -0
  70. package/dist/conformance/drift-daemon.js +41 -0
  71. package/dist/conformance/e2b-diagnose.d.ts +16 -0
  72. package/dist/conformance/e2b-diagnose.js +61 -0
  73. package/dist/conformance/e2b-sweep.d.ts +18 -0
  74. package/dist/conformance/e2b-sweep.js +132 -0
  75. package/dist/conformance/e2b.d.ts +74 -0
  76. package/dist/conformance/e2b.js +111 -0
  77. package/dist/conformance/fixture.d.ts +65 -0
  78. package/dist/conformance/fixture.js +98 -0
  79. package/dist/conformance/index.d.ts +8 -0
  80. package/dist/conformance/index.js +8 -0
  81. package/dist/conformance/kernel.d.ts +31 -0
  82. package/dist/conformance/kernel.js +40 -0
  83. package/dist/conformance/kind.d.ts +23 -0
  84. package/dist/conformance/kind.js +58 -0
  85. package/dist/conformance/modal-sweep.d.ts +22 -0
  86. package/dist/conformance/modal-sweep.js +213 -0
  87. package/dist/conformance/modal.d.ts +69 -0
  88. package/dist/conformance/modal.js +76 -0
  89. package/dist/conformance/orgo.d.ts +41 -0
  90. package/dist/conformance/orgo.js +69 -0
  91. package/dist/conformance/phone-harness.d.ts +61 -0
  92. package/dist/conformance/phone-harness.js +241 -0
  93. package/dist/conformance/png.d.ts +16 -0
  94. package/dist/conformance/png.js +132 -0
  95. package/dist/conformance/report.d.ts +2 -0
  96. package/dist/conformance/report.js +86 -0
  97. package/dist/conformance/runner.d.ts +11 -0
  98. package/dist/conformance/runner.js +585 -0
  99. package/dist/conformance/tar.d.ts +13 -0
  100. package/dist/conformance/tar.js +105 -0
  101. package/dist/conformance/types.d.ts +257 -0
  102. package/dist/conformance/types.js +24 -0
  103. package/dist/daemon-copy.d.ts +40 -0
  104. package/dist/daemon-copy.js +259 -0
  105. package/dist/daytona.d.ts +180 -0
  106. package/dist/daytona.js +1498 -0
  107. package/dist/desktop.d.ts +24 -0
  108. package/dist/desktop.js +68 -0
  109. package/dist/docker/egress-main.d.ts +1 -0
  110. package/dist/docker/egress-main.js +68 -0
  111. package/dist/docker/egress-proxy.d.ts +53 -0
  112. package/dist/docker/egress-proxy.js +450 -0
  113. package/dist/docker/egress-table.d.ts +39 -0
  114. package/dist/docker/egress-table.js +197 -0
  115. package/dist/docker/egress.d.ts +109 -0
  116. package/dist/docker/egress.js +318 -0
  117. package/dist/docker/image.d.ts +49 -0
  118. package/dist/docker/image.js +302 -0
  119. package/dist/docker/stage.d.ts +21 -0
  120. package/dist/docker/stage.js +290 -0
  121. package/dist/docker/volume.d.ts +24 -0
  122. package/dist/docker/volume.js +67 -0
  123. package/dist/docker.d.ts +156 -0
  124. package/dist/docker.js +1277 -0
  125. package/dist/drift.d.ts +200 -0
  126. package/dist/drift.js +416 -0
  127. package/dist/e2b.d.ts +337 -0
  128. package/dist/e2b.js +1516 -0
  129. package/dist/entry.d.ts +2 -0
  130. package/dist/entry.js +24 -0
  131. package/dist/files.d.ts +50 -0
  132. package/dist/files.js +208 -0
  133. package/dist/index.d.ts +27 -0
  134. package/dist/index.js +26 -0
  135. package/dist/isolation.d.ts +29 -0
  136. package/dist/isolation.js +71 -0
  137. package/dist/janitor.d.ts +50 -0
  138. package/dist/janitor.js +135 -0
  139. package/dist/kernel.d.ts +113 -0
  140. package/dist/kernel.js +358 -0
  141. package/dist/kinds.d.ts +79 -0
  142. package/dist/kinds.js +133 -0
  143. package/dist/labels.d.ts +23 -0
  144. package/dist/labels.js +50 -0
  145. package/dist/modal.d.ts +302 -0
  146. package/dist/modal.js +1374 -0
  147. package/dist/mount-archil.d.ts +164 -0
  148. package/dist/mount-archil.js +471 -0
  149. package/dist/mount.d.ts +57 -0
  150. package/dist/mount.js +104 -0
  151. package/dist/orgo-channel.d.ts +96 -0
  152. package/dist/orgo-channel.js +391 -0
  153. package/dist/orgo.d.ts +139 -0
  154. package/dist/orgo.js +1006 -0
  155. package/dist/phone-harness.d.ts +185 -0
  156. package/dist/phone-harness.js +1420 -0
  157. package/dist/processes.d.ts +24 -0
  158. package/dist/processes.js +40 -0
  159. package/dist/protocol.d.ts +729 -0
  160. package/dist/protocol.js +54 -0
  161. package/dist/provider.d.ts +245 -0
  162. package/dist/provider.js +37 -0
  163. package/dist/providers.d.ts +68 -0
  164. package/dist/providers.js +25 -0
  165. package/dist/result.d.ts +15 -0
  166. package/dist/result.js +2 -0
  167. package/dist/screen-watch.d.ts +150 -0
  168. package/dist/screen-watch.js +490 -0
  169. package/dist/test-connection.d.ts +17 -0
  170. package/dist/test-connection.js +26 -0
  171. package/dist/wait.d.ts +23 -0
  172. package/dist/wait.js +65 -0
  173. package/package.json +62 -4
@@ -0,0 +1,197 @@
1
+ // The address rule of a Docker computer's egress, written for AgentRun: which addresses a computer may reach through its
2
+ // egress proxy. Everything public; nothing private or local. It judges the binary address a socket would connect to,
3
+ // never the text a client wrote, so a single decimal number, octal or hex parts, or a bracketed IPv6 address is the
4
+ // address it parses to. An IPv6 address that carries an IPv4 one (mapped, NAT64, 6to4) is judged by the IPv4 inside. The
5
+ // host's own interface addresses are refused too: the caller passes them in, so the table itself stays pure. This is the
6
+ // one place the rule lives; the key gate's denylist marker accepts exactly these literals, and a test pins the list
7
+ // against drift. Moved from serve's egress-table.ts; the CIDR entries an allowlist may hold (cidrOf) are new here.
8
+ // It imports only node: modules: the proxy container runs it in a bare Node image.
9
+ import { isIP } from "node:net";
10
+ /** The refused ranges, specific ones first (the first match decides): a single metadata address before the range it sits
11
+ * in, the broadcast address before the reserved block. Past the table, an IPv6 address outside global unicast
12
+ * (2000::/3) is refused as reserved, in code: the IPv4-compatible form (::a.b.c.d) and every unassigned block among
13
+ * them. The mapped and NAT64 forms sit outside 2000::/3 too, and are judged by their IPv4 before that rule. */
14
+ const TABLE = [
15
+ { cidr: "0.0.0.0/8", class: "unspecified" }, // key-gate: denylist unspecified, refused by the egress proxy
16
+ { cidr: "127.0.0.0/8", class: "loopback" }, // key-gate: loopback-rule loopback, refused by the egress proxy
17
+ { cidr: "10.0.0.0/8", class: "private" }, // key-gate: denylist RFC 1918, refused by the egress proxy
18
+ { cidr: "172.16.0.0/12", class: "private" }, // key-gate: denylist RFC 1918, refused by the egress proxy
19
+ { cidr: "192.168.0.0/16", class: "private" }, // key-gate: denylist RFC 1918, refused by the egress proxy
20
+ { cidr: "192.0.0.0/24", class: "private" }, // key-gate: denylist IETF protocol assignments, refused by the egress proxy
21
+ { cidr: "100.100.100.200/32", class: "metadata" }, // key-gate: denylist a cloud metadata address, refused by the egress proxy
22
+ { cidr: "100.64.0.0/10", class: "cgnat" }, // key-gate: denylist shared address space, refused by the egress proxy
23
+ { cidr: "168.63.129.16/32", class: "metadata" }, // key-gate: denylist a cloud metadata address, refused by the egress proxy
24
+ { cidr: "169.254.0.0/16", class: "link-local" }, // key-gate: denylist link-local, refused by the egress proxy
25
+ { cidr: "198.18.0.0/15", class: "benchmarking" }, // key-gate: denylist benchmarking, refused by the egress proxy
26
+ { cidr: "192.0.2.0/24", class: "reserved" }, // key-gate: denylist documentation, refused by the egress proxy
27
+ { cidr: "198.51.100.0/24", class: "reserved" }, // key-gate: denylist documentation, refused by the egress proxy
28
+ { cidr: "203.0.113.0/24", class: "reserved" }, // key-gate: denylist documentation, refused by the egress proxy
29
+ { cidr: "192.88.99.0/24", class: "reserved" }, // key-gate: denylist the 6to4 relay anycast, refused by the egress proxy
30
+ { cidr: "224.0.0.0/4", class: "multicast" }, // key-gate: denylist multicast, refused by the egress proxy
31
+ { cidr: "255.255.255.255/32", class: "broadcast" }, // key-gate: denylist broadcast, refused by the egress proxy
32
+ { cidr: "240.0.0.0/4", class: "reserved" }, // key-gate: denylist reserved, refused by the egress proxy
33
+ { cidr: "::1/128", class: "loopback" }, // key-gate: loopback-rule loopback, refused by the egress proxy
34
+ { cidr: "::/128", class: "unspecified" }, // key-gate: denylist unspecified, refused by the egress proxy
35
+ { cidr: "::ffff:0:0/96", class: "last32" }, // key-gate: denylist IPv4-mapped, judged by the IPv4 inside
36
+ { cidr: "64:ff9b::/96", class: "last32" }, // key-gate: denylist NAT64, judged by the IPv4 inside
37
+ // Local-use NAT64 (RFC 8215): its operator picks a prefix of /48 to /96 inside it, so where an IPv4 sits cannot be read
38
+ // from the address alone. The whole block is refused.
39
+ { cidr: "64:ff9b:1::/48", class: "private" }, // key-gate: denylist local-use NAT64, refused by the egress proxy
40
+ { cidr: "2002::/16", class: "6to4" }, // key-gate: denylist 6to4, judged by the IPv4 inside
41
+ { cidr: "2001::/32", class: "reserved" }, // key-gate: denylist Teredo, refused by the egress proxy
42
+ { cidr: "2001:db8::/32", class: "reserved" }, // key-gate: denylist documentation, refused by the egress proxy
43
+ { cidr: "fd00:ec2::/32", class: "metadata" }, // key-gate: denylist a cloud metadata range, refused by the egress proxy
44
+ { cidr: "fc00::/7", class: "private" }, // key-gate: denylist unique local, refused by the egress proxy
45
+ { cidr: "fe80::/10", class: "link-local" }, // key-gate: denylist link-local, refused by the egress proxy
46
+ { cidr: "ff00::/8", class: "multicast" }, // key-gate: denylist multicast, refused by the egress proxy
47
+ ];
48
+ /** The table's ranges as written, in order: what the no-drift test pins. */
49
+ export const EGRESS_RANGES = TABLE.map((entry) => entry.cidr);
50
+ /**
51
+ * An IP address's bytes (4 or 16), or undefined when `text` is not one. Takes what a socket or a URL could carry for a
52
+ * host: a dotted IPv4 address, or the forms the classic resolver reads as one (a single number, 0x hex and 0 octal
53
+ * parts, fewer than four parts with the last filling the rest), and an IPv6 address, bracketed or not, with or without a
54
+ * zone. Never a name.
55
+ */
56
+ export function addressBytes(text) {
57
+ let host = text.trim();
58
+ if (host.startsWith("[") && host.endsWith("]"))
59
+ host = host.slice(1, -1);
60
+ const zone = host.indexOf("%");
61
+ if (zone >= 0 && host.includes(":"))
62
+ host = host.slice(0, zone);
63
+ if (isIP(host) === 6)
64
+ return v6Bytes(host);
65
+ return v4Bytes(host);
66
+ }
67
+ /** The classic resolver's reading of an IPv4 address (inet_aton): 1 to 4 parts, each decimal, 0x hex or 0 octal. */
68
+ function v4Bytes(text) {
69
+ const parts = text.split(".");
70
+ if (parts.length < 1 || parts.length > 4)
71
+ return undefined;
72
+ const values = [];
73
+ for (const part of parts) {
74
+ let value;
75
+ if (/^0[xX][0-9a-fA-F]*$/.test(part))
76
+ value = part.length === 2 ? 0 : parseInt(part.slice(2), 16);
77
+ else if (/^0[0-7]*$/.test(part))
78
+ value = parseInt(part, 8);
79
+ else if (/^[1-9][0-9]*$/.test(part))
80
+ value = parseInt(part, 10);
81
+ else
82
+ return undefined;
83
+ if (!Number.isSafeInteger(value))
84
+ return undefined;
85
+ values.push(value);
86
+ }
87
+ const last = values.pop();
88
+ if (values.some((v) => v > 255) || last >= 2 ** (8 * (4 - values.length)))
89
+ return undefined;
90
+ const out = new Uint8Array(4);
91
+ values.forEach((v, i) => (out[i] = v));
92
+ for (let i = 3, rest = last; i >= values.length; i--, rest = Math.floor(rest / 256))
93
+ out[i] = rest % 256;
94
+ return out;
95
+ }
96
+ /** An IPv6 address's 16 bytes; `text` is one `isIP` accepts. */
97
+ function v6Bytes(text) {
98
+ let head = text;
99
+ const dotted = /^(.*:)(\d+\.\d+\.\d+\.\d+)$/.exec(text);
100
+ if (dotted) {
101
+ const v4 = v4Bytes(dotted[2]);
102
+ if (!v4 || dotted[2].split(".").length !== 4)
103
+ return undefined;
104
+ head = `${dotted[1]}${((v4[0] << 8) | v4[1]).toString(16)}:${((v4[2] << 8) | v4[3]).toString(16)}`;
105
+ }
106
+ const [left, right] = head.split("::");
107
+ const groups = (s) => (s === "" ? [] : s.split(":").map((g) => parseInt(g, 16)));
108
+ const l = groups(left);
109
+ const r = right === undefined ? [] : groups(right);
110
+ const fill = right === undefined ? 0 : 8 - l.length - r.length;
111
+ const all = [...l, ...Array(Math.max(fill, 0)).fill(0), ...r];
112
+ if (all.length !== 8 || all.some((g) => !(g >= 0 && g <= 0xffff)))
113
+ return undefined;
114
+ const out = new Uint8Array(16);
115
+ all.forEach((g, i) => {
116
+ out[2 * i] = g >> 8;
117
+ out[2 * i + 1] = g & 0xff;
118
+ });
119
+ return out;
120
+ }
121
+ const RANGES = TABLE.map((entry) => {
122
+ const [base, bits] = entry.cidr.split("/");
123
+ return { bytes: addressBytes(base), bits: Number(bits), class: entry.class, cidr: entry.cidr };
124
+ });
125
+ /** Whether the first `bits` bits of `a` and `b` (of one family) are the same. */
126
+ const samePrefix = (a, b, bits) => {
127
+ for (let bit = 0; bit < bits; bit += 8) {
128
+ const mask = bits - bit >= 8 ? 0xff : (0xff << (8 - (bits - bit))) & 0xff;
129
+ if ((a[bit / 8] & mask) !== (b[bit / 8] & mask))
130
+ return false;
131
+ }
132
+ return true;
133
+ };
134
+ const within = (address, range) => address.length === range.bytes.length && samePrefix(address, range.bytes, range.bits);
135
+ const same = (a, b) => a.length === b.length && a.every((byte, i) => byte === b[i]);
136
+ /**
137
+ * Whether a computer may reach `address` (its bytes, or an address's text: never a name). `local` is the host's own
138
+ * addresses: an address equal to one of them is refused as "this-host". An IPv6 address that carries an IPv4 one is
139
+ * judged by the IPv4 inside, and is then still the host's own if the host holds that IPv6 address itself (the dial goes
140
+ * to the IPv6 address, not to the IPv4 inside it).
141
+ */
142
+ export function checkAddress(address, local) {
143
+ const bytes = typeof address === "string" ? addressBytes(address) : address;
144
+ if (!bytes || (bytes.length !== 4 && bytes.length !== 16))
145
+ return { ok: false, class: "invalid" };
146
+ for (const range of RANGES) {
147
+ if (!within(bytes, range))
148
+ continue;
149
+ if (range.class === "last32" || range.class === "6to4") {
150
+ const inner = checkAddress(range.class === "last32" ? bytes.slice(12, 16) : bytes.slice(2, 6), local);
151
+ return inner.ok ? ownAddress(bytes, local) : inner;
152
+ }
153
+ return { ok: false, class: range.class };
154
+ }
155
+ if (bytes.length === 16 && (bytes[0] & 0xe0) !== 0x20)
156
+ return { ok: false, class: "reserved" };
157
+ return ownAddress(bytes, local);
158
+ }
159
+ /** Refused as "this-host" when `bytes` is one of the host's own addresses, as it is written there. */
160
+ function ownAddress(bytes, local) {
161
+ for (const text of local) {
162
+ const own = addressBytes(text);
163
+ if (own && same(own, bytes))
164
+ return { ok: false, class: "this-host" };
165
+ }
166
+ return { ok: true };
167
+ }
168
+ /** A dotted IPv4 address of four decimal parts, or an IPv6 address with no zone, then / and a prefix length. */
169
+ const CIDR = /^([0-9.]+|[0-9a-f:.]*:[0-9a-f:.]*)\/(\d{1,3})$/;
170
+ /**
171
+ * A CIDR entry of an allowlist; or why it is not one, in words, when it reads as one; or undefined when it is not a CIDR
172
+ * at all. A CIDR is an IPv4 address in four decimal parts or an IPv6 address (no zone), then a prefix length its family
173
+ * holds. Its host bits are zero; it overlaps no range the table refuses; and an IPv6 one lies inside global unicast
174
+ * (2000::/3). A CIDR that could name a private or local address is refused here, though the table would refuse each
175
+ * such address at the dial anyway: a list never claims what it cannot reach. Lowercase is the caller's.
176
+ */
177
+ export function cidrOf(text) {
178
+ const match = CIDR.exec(text);
179
+ const v4 = match !== null && /^\d{1,3}(\.\d{1,3}){3}$/.test(match[1]) && match[1].split(".").every((part) => part === "0" || /^[1-9]\d*$/.test(part));
180
+ const bytes = match === null ? undefined : v4 ? v4Bytes(match[1]) : isIP(match[1]) === 6 ? v6Bytes(match[1]) : undefined;
181
+ const bits = Number(match?.[2]);
182
+ if (!bytes || !(bits <= bytes.length * 8) || String(bits) !== match?.[2])
183
+ return undefined;
184
+ for (let bit = bits; bit < bytes.length * 8; bit++) {
185
+ if ((bytes[bit >> 3] >> (7 - (bit & 7))) & 1)
186
+ return `has host bits set past its /${bits}: write its network address`;
187
+ }
188
+ const cidr = { bytes, bits };
189
+ const refused = RANGES.find((range) => range.bytes.length === bytes.length && samePrefix(bytes, range.bytes, Math.min(bits, range.bits)));
190
+ if (refused)
191
+ return `covers addresses the egress proxy refuses (the refused range ${refused.cidr})`;
192
+ if (bytes.length === 16 && (bits < 3 || (bytes[0] & 0xe0) !== 0x20))
193
+ return "is outside global unicast (2000::/3), which the egress proxy refuses";
194
+ return cidr;
195
+ }
196
+ /** Whether `address` lies inside `cidr`: of the same family, IPv4 or IPv6, and with the same prefix. */
197
+ export const inCidr = (address, cidr) => within(address, cidr);
@@ -0,0 +1,109 @@
1
+ import { type DockerInspect } from "../drift.js";
2
+ import type { NetworkPolicy } from "../provider.js";
3
+ /** The proxy container's image: node:22.23.4-bookworm-slim, pinned to its multi-arch index digest (as serve pins its
4
+ * own), so every host runs the same Node. The provider's `egress.image` replaces it. */
5
+ export declare const EGRESS_IMAGE = "node:22.23.4-bookworm-slim@sha256:de170b39439eb0e5a3444ad7d60b015614a381e10fecae2e30ec9e735122f38d";
6
+ /** The label the proxy container and the volume carry: the computer's name. In the provider's own namespace, which a
7
+ * spec's labels cannot use. */
8
+ export declare const EGRESS_LABEL = "agentrun.computer.egress";
9
+ /** Where the computer mounts the volume, read-only, and the proxy's socket in it: what init's relay connects to. */
10
+ export declare const EGRESS_MOUNT = "/opt/agentrun/egress";
11
+ export declare const EGRESS_SOCKET = "/opt/agentrun/egress/egress.sock";
12
+ /** Init's flag for the relay: computerd init --egress <socket>. */
13
+ export declare const RELAY_FLAG = "--egress";
14
+ /** The most entries of each kind an allowlist holds: Docker's own bound, so the list fits one argv element. */
15
+ export declare const MAX_ALLOW = 256;
16
+ /** How long create waits for the proxy's ready line, by default. */
17
+ export declare const EGRESS_READY_MS = 10000;
18
+ /** The files the proxy container runs, in dist/docker. */
19
+ export declare const CODE_FILES: string[];
20
+ /** The proxy container's name, and the volume's, for computer `name`. */
21
+ export declare const egressNameOf: (name: string) => string;
22
+ /** Where the proxy's code is on this machine: this package's dist/docker, and its package.json, which makes Node read
23
+ * the files as modules. */
24
+ export interface EgressCode {
25
+ dir: string;
26
+ packageJson: string;
27
+ /** With the provider's volume option: the code is staged below the volume's root in one tree (src/docker/stage.ts),
28
+ * `root` its subpath (undefined when unknown), which the proxy mounts whole at /code. */
29
+ volume?: {
30
+ name: string;
31
+ root?: string;
32
+ /** For a read-back: whether a proxy may be mounted on this subpath, any verified copy of the code (stage.ts
33
+ * egressStaged), not only `root`. Without it, `root` alone. */
34
+ accepts?: (subpath: string) => boolean;
35
+ };
36
+ }
37
+ /** This package's own build: the directory this file is in, and the package's package.json. */
38
+ export declare function egressCode(): EgressCode;
39
+ /**
40
+ * Why the proxy's code cannot be bound, in words, or undefined when it can: every file built, each readable by `user`
41
+ * (uid:gid) and its directory searchable, by the owner's, group's or others' bits as the kernel picks them, since the
42
+ * proxy runs as the computer's user with no capability.
43
+ */
44
+ export declare function egressCodeProblem({ dir, packageJson }: EgressCode, user: string): string | undefined;
45
+ /**
46
+ * A spec's allowlist, normalized as the proxy reads it (parseAllow: lowercase, a name's trailing dot dropped, no
47
+ * repeats), or why Docker cannot hold it, in words.
48
+ */
49
+ export declare function allowOf(entries: unknown): {
50
+ list: string[];
51
+ } | {
52
+ problem: string;
53
+ };
54
+ /** Whether two allowlists hold the same entries, normalized, in any order. */
55
+ export declare function sameAllow(a: readonly string[], b: readonly string[]): boolean;
56
+ /** This machine's own public addresses, as its interfaces hold them: the proxy refuses them as the host's. A private or
57
+ * local one needs no entry; the address rule refuses it anyway. They are the Docker host's only when this provider runs
58
+ * on it, not in a container and not against a daemon elsewhere (containerSigns, and the provider's own check). */
59
+ export declare function hostAddresses(): string[];
60
+ /**
61
+ * What shows this process runs in a container, under `root` (the filesystem's root; a test's seam): /.dockerenv (Docker),
62
+ * /run/.containerenv (Podman), or a line of /proc/self/cgroup naming a container's cgroup. Undefined when none does. A
63
+ * cgroup namespace's bare root (a lone slash after the hierarchy) is no evidence either way. A container with none of these is not seen: the
64
+ * caller then still has its own interfaces, which is why egress.hostAddresses exists.
65
+ */
66
+ export declare function containerSigns(root?: string): string | undefined;
67
+ /** `docker volume create` of a computer's volume: tmpfs, so nothing of it outlives the daemon, and its user's alone. It
68
+ * carries the computer's name, its deadline and the spec's labels, so the janitor finds it when the computer is gone. */
69
+ export declare function egressVolumeArgs(name: string, user: string, deadline: string, labels?: Record<string, string>): string[];
70
+ export interface EgressRun {
71
+ name: string;
72
+ user: string;
73
+ image: string;
74
+ allow: readonly string[];
75
+ local: readonly string[];
76
+ deadline: string;
77
+ code: EgressCode;
78
+ hint?: string;
79
+ /** The spec's labels, which the proxy container carries too. */
80
+ labels?: Record<string, string>;
81
+ }
82
+ /** `docker run` of a computer's proxy container (see the head of this file). Pinned by a golden test. */
83
+ export declare function egressRunArgs({ name, user, image, allow, local, deadline, code, hint, labels }: EgressRun): string[];
84
+ /** What a computer's read-back needs of the computer itself. */
85
+ export interface EgressOwner {
86
+ name: string;
87
+ /** The computer's Config.User. */
88
+ user: unknown;
89
+ /** The computer's deadline label. */
90
+ deadline: unknown;
91
+ running: boolean;
92
+ }
93
+ /**
94
+ * A computer's allowlist, read back from its proxy container's inspect: the list its argv holds, when the container is
95
+ * the computer's own (its label and deadline), running while the computer runs, and as create makes one (Docker's
96
+ * default bridge alone, no port, the computer's user, a read-only root, no capability or privilege, exactly its volume
97
+ * and its code, `code`'s when given), refusing every one of `local`, the Docker host's own addresses the provider
98
+ * requires now (more is fine). Anything less is `{ other }` in words, never an allowlist. A host whose addresses
99
+ * changed since the proxy was made reads as other: fail closed.
100
+ */
101
+ export declare function egressOf(proxy: DockerInspect | null | undefined, owner: EgressOwner, code?: EgressCode, local?: readonly string[]): {
102
+ allow: string[];
103
+ } | {
104
+ other: string;
105
+ };
106
+ /** The ports each entry of a Docker allowlist opens. */
107
+ export declare const ALLOW_PORTS: number[];
108
+ /** A policy as a refusal or a read-back names it. */
109
+ export declare const policyWords: (policy: NetworkPolicy) => string;
@@ -0,0 +1,318 @@
1
+ // A Docker computer's way out to the network when its spec asks for an allowlist ({ allow: [names or CIDRs] }): the
2
+ // computer stays `--network none`, and its own egress proxy runs in a second container the provider makes, reads back
3
+ // and removes with it. Moved from serve's box-egress.ts and rewritten onto the provider: the proxy no longer lives in the
4
+ // process that made the computer, so the computer keeps its network when that process ends, and attach and list read it
5
+ // back from Docker anywhere.
6
+ //
7
+ // - The volume `<computer>-egress`: a tmpfs of 1 MiB, mode 0700, owned by the computer's uid:gid. The proxy's Unix
8
+ // socket is made in it; the computer mounts it read-only at EGRESS_MOUNT.
9
+ // - The proxy container `<computer>-egress`: this package's own proxy (egress-main.ts, egress-proxy.ts, egress-table.ts,
10
+ // bound read-only from dist/docker with the package's package.json), in a pinned Node image, on Docker's default
11
+ // bridge alone, publishing no port, as the computer's uid:gid, with a read-only root, no capability, no privilege to
12
+ // gain, and bounded memory, pids and log. Its argv holds the list, the computer's deadline (it ends itself then), the
13
+ // Docker host's own public addresses (refused as this host's) and the hint. It holds no key.
14
+ // - The computer: init gets `--egress <socket>` and relays its loopback port 3128 to the socket, and tells every program
15
+ // it starts that port is its HTTP and HTTPS proxy. A program that ignores that reaches nothing: there is no route.
16
+ // - Both carry the label EGRESS_LABEL=<computer>; release finds the proxy and the volume by it, never by name alone.
17
+ import { existsSync, readFileSync, statSync } from "node:fs";
18
+ import { networkInterfaces } from "node:os";
19
+ import { fileURLToPath } from "node:url";
20
+ import { DEADLINE_LABEL } from "../drift.js";
21
+ import { LISTED_PORTS, parseAllow } from "./egress-proxy.js";
22
+ import { checkAddress } from "./egress-table.js";
23
+ /** The proxy container's image: node:22.23.4-bookworm-slim, pinned to its multi-arch index digest (as serve pins its
24
+ * own), so every host runs the same Node. The provider's `egress.image` replaces it. */
25
+ export const EGRESS_IMAGE = "node:22.23.4-bookworm-slim@sha256:de170b39439eb0e5a3444ad7d60b015614a381e10fecae2e30ec9e735122f38d";
26
+ /** The label the proxy container and the volume carry: the computer's name. In the provider's own namespace, which a
27
+ * spec's labels cannot use. */
28
+ export const EGRESS_LABEL = "agentrun.computer.egress";
29
+ /** Where the computer mounts the volume, read-only, and the proxy's socket in it: what init's relay connects to. */
30
+ export const EGRESS_MOUNT = "/opt/agentrun/egress";
31
+ export const EGRESS_SOCKET = `${EGRESS_MOUNT}/egress.sock`;
32
+ /** Init's flag for the relay: computerd init --egress <socket>. */
33
+ export const RELAY_FLAG = "--egress";
34
+ /** The most entries of each kind an allowlist holds: Docker's own bound, so the list fits one argv element. */
35
+ export const MAX_ALLOW = 256;
36
+ /** How long create waits for the proxy's ready line, by default. */
37
+ export const EGRESS_READY_MS = 10_000;
38
+ /** In the proxy container: the volume, its socket, and its code. */
39
+ const PROXY_VOLUME = "/egress";
40
+ const PROXY_SOCKET = `${PROXY_VOLUME}/egress.sock`;
41
+ const PROXY_CODE = "/code/docker";
42
+ const PROXY_PACKAGE = "/code/package.json";
43
+ /** With the provider's volume option, the staged tree (src/docker/stage.ts) mounted whole: docker/ and package.json. */
44
+ const PROXY_ROOT = "/code";
45
+ const PROXY_MAIN = `${PROXY_CODE}/egress-main.js`;
46
+ /** The files the proxy container runs, in dist/docker. */
47
+ export const CODE_FILES = ["egress-main.js", "egress-proxy.js", "egress-table.js"];
48
+ const EXAMPLE = '["pypi.org", "*.pythonhosted.org", "93.184.215.0/24"]';
49
+ /** The proxy container's name, and the volume's, for computer `name`. */
50
+ export const egressNameOf = (name) => `${name}-egress`;
51
+ /** This package's own build: the directory this file is in, and the package's package.json. */
52
+ export function egressCode() {
53
+ return { dir: fileURLToPath(new URL(".", import.meta.url)).replace(/\/$/, ""), packageJson: fileURLToPath(new URL("../../package.json", import.meta.url)) };
54
+ }
55
+ /**
56
+ * Why the proxy's code cannot be bound, in words, or undefined when it can: every file built, each readable by `user`
57
+ * (uid:gid) and its directory searchable, by the owner's, group's or others' bits as the kernel picks them, since the
58
+ * proxy runs as the computer's user with no capability.
59
+ */
60
+ export function egressCodeProblem({ dir, packageJson }, user) {
61
+ const files = [...CODE_FILES.map((file) => `${dir}/${file}`), packageJson];
62
+ const missing = files.filter((path) => !existsSync(path) || !statSync(path).isFile());
63
+ if (missing.length > 0)
64
+ return `the egress proxy's code is not built (${missing.join(", ")}): run npm run build -w @parcha/agentrun-computer`;
65
+ if (/[,"\r\n]/.test(dir + packageJson))
66
+ return `the egress proxy's code is at a path a Docker mount cannot hold (a comma, a double quote or a line break): ${dir}`;
67
+ const [uid, gid] = user.split(":").map(Number);
68
+ const bits = (path) => {
69
+ const { uid: owner, gid: group, mode } = statSync(path);
70
+ return owner === uid ? (mode >> 6) & 7 : group === gid ? (mode >> 3) & 7 : mode & 7;
71
+ };
72
+ const closed = [...((bits(dir) & 5) === 5 ? [] : [dir]), ...files.filter((path) => (bits(path) & 4) === 0)];
73
+ if (closed.length > 0) {
74
+ return `the egress proxy's code is not readable by the computer's user ${user} (${closed.join(", ")}); the proxy runs as that user with no capabilities: chmod a+rX them`;
75
+ }
76
+ return undefined;
77
+ }
78
+ /**
79
+ * A spec's allowlist, normalized as the proxy reads it (parseAllow: lowercase, a name's trailing dot dropped, no
80
+ * repeats), or why Docker cannot hold it, in words.
81
+ */
82
+ export function allowOf(entries) {
83
+ if (!Array.isArray(entries) || !entries.every((entry) => typeof entry === "string"))
84
+ return { problem: `an allowlist is a list of names and CIDRs, such as ${EXAMPLE}` };
85
+ if (entries.length === 0)
86
+ return { problem: 'an allowlist needs at least one name or CIDR; for no network ask for "none"' };
87
+ let list;
88
+ try {
89
+ list = parseAllow(entries);
90
+ }
91
+ catch (error) {
92
+ return { problem: error.message };
93
+ }
94
+ if (list.length === 0)
95
+ return { problem: 'an allowlist needs at least one name or CIDR; for no network ask for "none"' };
96
+ const cidrs = list.filter((entry) => entry.includes("/")).length;
97
+ const names = list.length - cidrs;
98
+ if (names > MAX_ALLOW)
99
+ return { problem: `a Docker allowlist holds at most ${MAX_ALLOW} names, not ${names}` };
100
+ if (cidrs > MAX_ALLOW)
101
+ return { problem: `a Docker allowlist holds at most ${MAX_ALLOW} CIDRs, not ${cidrs}` };
102
+ return { list };
103
+ }
104
+ /** Whether two allowlists hold the same entries, normalized, in any order. */
105
+ export function sameAllow(a, b) {
106
+ const left = allowOf(a);
107
+ const right = allowOf(b);
108
+ if ("problem" in left || "problem" in right)
109
+ return false;
110
+ return left.list.length === right.list.length && left.list.every((entry) => right.list.includes(entry));
111
+ }
112
+ /** This machine's own public addresses, as its interfaces hold them: the proxy refuses them as the host's. A private or
113
+ * local one needs no entry; the address rule refuses it anyway. They are the Docker host's only when this provider runs
114
+ * on it, not in a container and not against a daemon elsewhere (containerSigns, and the provider's own check). */
115
+ export function hostAddresses() {
116
+ const all = Object.values(networkInterfaces()).flatMap((list) => (list ?? []).map((entry) => entry.address));
117
+ return [...new Set(all.filter((address) => checkAddress(address, []).ok))];
118
+ }
119
+ /** A container's cgroup path, under any manager that names one: Docker, containerd, Kubernetes, Podman, LXC, BuildKit. */
120
+ const CONTAINER_CGROUP = /(^|[/.:-])(docker|containerd|cri-containerd|kubepods|libpod|lxc|buildkit)([/.:-]|$)/;
121
+ /**
122
+ * What shows this process runs in a container, under `root` (the filesystem's root; a test's seam): /.dockerenv (Docker),
123
+ * /run/.containerenv (Podman), or a line of /proc/self/cgroup naming a container's cgroup. Undefined when none does. A
124
+ * cgroup namespace's bare root (a lone slash after the hierarchy) is no evidence either way. A container with none of these is not seen: the
125
+ * caller then still has its own interfaces, which is why egress.hostAddresses exists.
126
+ */
127
+ export function containerSigns(root = "/") {
128
+ const at = (path) => `${root.replace(/\/$/, "")}${path}`;
129
+ if (existsSync(at("/.dockerenv")))
130
+ return "/.dockerenv exists";
131
+ if (existsSync(at("/run/.containerenv")))
132
+ return "/run/.containerenv exists";
133
+ let cgroup = "";
134
+ try {
135
+ cgroup = readFileSync(at("/proc/self/cgroup"), "utf8");
136
+ }
137
+ catch {
138
+ return undefined;
139
+ }
140
+ const line = cgroup.split("\n").find((entry) => CONTAINER_CGROUP.test(entry.slice(entry.indexOf(":", entry.indexOf(":") + 1) + 1)));
141
+ return line === undefined ? undefined : `/proc/self/cgroup names a container's cgroup (${line.slice(0, 120)})`;
142
+ }
143
+ /** `docker volume create` of a computer's volume: tmpfs, so nothing of it outlives the daemon, and its user's alone. It
144
+ * carries the computer's name, its deadline and the spec's labels, so the janitor finds it when the computer is gone. */
145
+ export function egressVolumeArgs(name, user, deadline, labels = {}) {
146
+ const [uid, gid] = user.split(":");
147
+ const args = ["volume", "create", "--driver", "local", "--opt", "type=tmpfs", "--opt", "device=tmpfs", "--opt", `o=size=1m,uid=${uid},gid=${gid},mode=0700`];
148
+ args.push("--label", `${EGRESS_LABEL}=${name}`, "--label", `${DEADLINE_LABEL}=${deadline}`);
149
+ for (const [key, value] of Object.entries(labels))
150
+ args.push("--label", `${key}=${value}`);
151
+ return [...args, egressNameOf(name)];
152
+ }
153
+ /** The proxy container's bounds, as create sets them and the read-back holds it to: memory (swap the same), processes,
154
+ * half a CPU (a quota of each 100 ms, as a computer's cpus are; fixed, not the computer's own, since one proxy's work
155
+ * is its connections, not the computer's size), at most 1024 open files, and a bounded json-file log. */
156
+ const PROXY_MEMORY_MB = 256;
157
+ const PROXY_PIDS = 64;
158
+ const PROXY_CPU_PERIOD_US = 100_000;
159
+ const PROXY_CPU_QUOTA_US = 50_000;
160
+ const PROXY_NOFILE = 1024;
161
+ const PROXY_LOG = { driver: "json-file", options: { "max-size": "1m", "max-file": "2" } };
162
+ /** `docker run` of a computer's proxy container (see the head of this file). Pinned by a golden test. */
163
+ export function egressRunArgs({ name, user, image, allow, local, deadline, code, hint, labels = {} }) {
164
+ const proxy = egressNameOf(name);
165
+ const args = ["run", "--detach", "--name", proxy, "--label", `${EGRESS_LABEL}=${name}`, "--label", `${DEADLINE_LABEL}=${deadline}`];
166
+ for (const [key, value] of Object.entries(labels))
167
+ args.push("--label", `${key}=${value}`);
168
+ args.push("--user", user, "--read-only", "--cap-drop", "ALL", "--security-opt", "no-new-privileges", "--ipc", "private", "--cgroupns", "private");
169
+ const memory = `${PROXY_MEMORY_MB}m`;
170
+ args.push("--pids-limit", String(PROXY_PIDS), "--memory", memory, "--memory-swap", memory);
171
+ args.push("--cpu-period", String(PROXY_CPU_PERIOD_US), "--cpu-quota", String(PROXY_CPU_QUOTA_US), "--ulimit", `nofile=${PROXY_NOFILE}:${PROXY_NOFILE}`);
172
+ args.push("--log-driver", PROXY_LOG.driver);
173
+ for (const [key, value] of Object.entries(PROXY_LOG.options))
174
+ args.push("--log-opt", `${key}=${value}`);
175
+ args.push("--network", "bridge");
176
+ args.push("--mount", `type=volume,src=${proxy},dst=${PROXY_VOLUME}`);
177
+ if (code.volume === undefined) {
178
+ args.push("--mount", `type=bind,src=${code.dir},dst=${PROXY_CODE},readonly`, "--mount", `type=bind,src=${code.packageJson},dst=${PROXY_PACKAGE},readonly`);
179
+ }
180
+ else {
181
+ // With the provider's volume option, the staged tree, one directory, as the volume's subpath: the Docker daemon has
182
+ // none of this process's paths.
183
+ args.push("--mount", `type=volume,src=${code.volume.name},dst=${PROXY_ROOT},volume-subpath=${code.volume.root ?? ""},volume-nocopy,readonly`);
184
+ }
185
+ // Create pulled the image before it made the volume, so this run never pulls: the sweep's grace holds.
186
+ args.push("--pull", "never");
187
+ args.push("--entrypoint", "node", image, PROXY_MAIN, "--socket", PROXY_SOCKET, "--deadline", deadline, "--allow", allow.join(","));
188
+ if (local.length > 0)
189
+ args.push("--local", local.join(","));
190
+ if (hint !== undefined)
191
+ args.push("--hint", hint);
192
+ return args;
193
+ }
194
+ const show = (value) => (value === undefined ? "nothing" : JSON.stringify(value));
195
+ const blank = (value) => value === undefined || value === null || value === "" || value === 0 || value === false || (typeof value === "object" && Object.keys(value).length === 0);
196
+ /**
197
+ * A computer's allowlist, read back from its proxy container's inspect: the list its argv holds, when the container is
198
+ * the computer's own (its label and deadline), running while the computer runs, and as create makes one (Docker's
199
+ * default bridge alone, no port, the computer's user, a read-only root, no capability or privilege, exactly its volume
200
+ * and its code, `code`'s when given), refusing every one of `local`, the Docker host's own addresses the provider
201
+ * requires now (more is fine). Anything less is `{ other }` in words, never an allowlist. A host whose addresses
202
+ * changed since the proxy was made reads as other: fail closed.
203
+ */
204
+ export function egressOf(proxy, owner, code, local = []) {
205
+ const named = egressNameOf(owner.name);
206
+ const other = (what) => ({ other: `network allow, but its egress proxy ${named} ${what}` });
207
+ if (proxy === undefined || proxy === null)
208
+ return other("is gone: the computer reaches nothing");
209
+ const config = proxy.Config ?? {};
210
+ const host = proxy.HostConfig ?? {};
211
+ const labels = config.Labels ?? {};
212
+ if ((proxy.Name ?? "").replace(/^\//, "") !== named)
213
+ return other(`is named ${show(proxy.Name)}`);
214
+ if (labels[EGRESS_LABEL] !== owner.name)
215
+ return other(`does not carry the label ${EGRESS_LABEL}=${owner.name} (it reads ${show(labels[EGRESS_LABEL])})`);
216
+ if (labels[DEADLINE_LABEL] !== owner.deadline)
217
+ return other(`has the deadline label ${show(labels[DEADLINE_LABEL])}, not the computer's ${show(owner.deadline)}`);
218
+ if (owner.running && proxy.State?.Running !== true)
219
+ return other(`is not running (exit code ${show(proxy.State?.ExitCode)}): the computer reaches nothing`);
220
+ const networks = Object.keys(proxy.NetworkSettings?.Networks ?? {});
221
+ if (host.NetworkMode !== "bridge" || networks.length !== 1 || networks[0] !== "bridge")
222
+ return other(`is on network mode ${String(host.NetworkMode)} and networks ${networks.join(", ") || "none"}, not Docker's default bridge alone`);
223
+ if (host.Privileged !== false)
224
+ return other("is privileged");
225
+ const capDrop = host.CapDrop;
226
+ if (!Array.isArray(capDrop) || capDrop.length !== 1 || capDrop[0] !== "ALL" || !blank(host.CapAdd))
227
+ return other(`keeps capabilities (CapDrop ${show(capDrop)}, CapAdd ${show(host.CapAdd)})`);
228
+ const securityOpt = host.SecurityOpt;
229
+ if (!Array.isArray(securityOpt) || securityOpt.length !== 1 || securityOpt[0] !== "no-new-privileges")
230
+ return other(`lacks no-new-privileges alone (SecurityOpt ${show(securityOpt)})`);
231
+ if (host.ReadonlyRootfs !== true)
232
+ return other("has no read-only root");
233
+ const bytes = PROXY_MEMORY_MB * 1024 * 1024;
234
+ if (host.Memory !== bytes)
235
+ return other(`has memory ${show(host.Memory)}, not ${bytes}`);
236
+ if (host.MemorySwap !== bytes)
237
+ return other(`has memory swap ${show(host.MemorySwap)}, not ${bytes}`);
238
+ if (host.PidsLimit !== PROXY_PIDS)
239
+ return other(`has pids limit ${show(host.PidsLimit)}, not ${PROXY_PIDS}`);
240
+ if (host.IpcMode !== "private")
241
+ return other(`has IPC mode ${show(host.IpcMode)}, not "private"`);
242
+ if (host.CgroupnsMode !== "private")
243
+ return other(`has cgroup namespace ${show(host.CgroupnsMode)}, not "private"`);
244
+ if (host.CpuPeriod !== PROXY_CPU_PERIOD_US || host.CpuQuota !== PROXY_CPU_QUOTA_US) {
245
+ return other(`has CPU quota ${show(host.CpuQuota)} of ${show(host.CpuPeriod)}, not ${PROXY_CPU_QUOTA_US} of ${PROXY_CPU_PERIOD_US}`);
246
+ }
247
+ const ulimits = host.Ulimits;
248
+ const [nofile] = Array.isArray(ulimits) ? ulimits : [];
249
+ if (!Array.isArray(ulimits) || ulimits.length !== 1 || nofile?.Name !== "nofile" || nofile.Soft !== PROXY_NOFILE || nofile.Hard !== PROXY_NOFILE) {
250
+ return other(`has the open-file limit ${show(ulimits)}, not nofile ${PROXY_NOFILE}:${PROXY_NOFILE}`);
251
+ }
252
+ const log = (host.LogConfig ?? {});
253
+ const logOptions = log.Config ?? {};
254
+ const wanted = Object.entries(PROXY_LOG.options);
255
+ if (log.Type !== PROXY_LOG.driver || Object.keys(logOptions).length !== wanted.length || !wanted.every(([key, value]) => logOptions[key] === value)) {
256
+ return other(`has the log ${show(log)}, not ${PROXY_LOG.driver} with ${wanted.map(([key, value]) => `${key} ${value}`).join(" and ")}`);
257
+ }
258
+ if (!blank(host.PortBindings) || host.PublishAllPorts === true)
259
+ return other("publishes ports");
260
+ for (const field of ["Binds", "VolumesFrom", "Devices", "PidMode", "UsernsMode"])
261
+ if (!blank(host[field]))
262
+ return other(`has ${field} ${show(host[field])}`);
263
+ if (config.User !== owner.user)
264
+ return other(`runs as ${show(config.User).replaceAll('"', "")}, not the computer's ${show(owner.user).replaceAll('"', "")}`);
265
+ const mounts = proxy.Mounts ?? [];
266
+ // The code: binds of `code`'s paths, or, with the provider's volume option, the staged tree at /code, the volume's
267
+ // subpath (checked below in HostConfig.Mounts, which records it; Mounts shows the volume by name).
268
+ const shared = code?.volume;
269
+ const codeMounts = shared === undefined
270
+ ? [
271
+ { Type: "bind", Destination: PROXY_CODE, RW: false, ...(code ? { Source: code.dir } : {}) },
272
+ { Type: "bind", Destination: PROXY_PACKAGE, RW: false, ...(code ? { Source: code.packageJson } : {}) },
273
+ ]
274
+ : [{ Type: "volume", Name: shared.name, Destination: PROXY_ROOT, RW: false }];
275
+ const want = [{ Type: "volume", Name: named, Destination: PROXY_VOLUME, RW: true }, ...codeMounts];
276
+ const fits = mounts.length === want.length && want.every((wanted) => mounts.some((mount) => Object.entries(wanted).every(([key, value]) => mount[key] === value)));
277
+ if (!fits)
278
+ return other(`has mounts ${show(mounts.map((m) => `${m.Type} ${m.Name ?? m.Source} at ${m.Destination}${m.RW ? "" : " read-only"}`))}, not its volume read-write at ${PROXY_VOLUME} and its code read-only`);
279
+ if (shared !== undefined) {
280
+ const asked = (host.Mounts ?? []).filter((mount) => mount.Target === PROXY_ROOT);
281
+ const subpath = asked[0]?.VolumeOptions?.Subpath;
282
+ const right = asked.length === 1 && asked[0]?.Type === "volume" && asked[0].Source === shared.name && asked[0].ReadOnly === true && (typeof subpath === "string" && subpath !== "" && (shared.accepts !== undefined ? shared.accepts(subpath) : shared.root === undefined || subpath === shared.root));
283
+ if (!right)
284
+ return other(`mounts ${show(asked)} at ${PROXY_ROOT}, not the staged code's subpath ${show(shared.root)} of the volume ${shared.name}, read-only`);
285
+ }
286
+ const entrypoint = config.Entrypoint;
287
+ if (!Array.isArray(entrypoint) || entrypoint.length !== 1 || entrypoint[0] !== "node")
288
+ return other(`has the entrypoint ${show(entrypoint)}, not node`);
289
+ const cmd = Array.isArray(config.Cmd) ? config.Cmd : [];
290
+ const flags = new Map();
291
+ for (let at = 1; at + 1 < cmd.length; at += 2)
292
+ flags.set(String(cmd[at]), String(cmd[at + 1]));
293
+ if (cmd[0] !== PROXY_MAIN || cmd.length % 2 !== 1 || flags.size !== (cmd.length - 1) / 2)
294
+ return other(`runs ${show(cmd)}, not ${PROXY_MAIN} and its flags`);
295
+ if (!flags.has("--allow"))
296
+ return other("has no host list in its command");
297
+ if (flags.get("--socket") !== PROXY_SOCKET)
298
+ return other(`listens on ${show(flags.get("--socket"))}, not ${PROXY_SOCKET}`);
299
+ if (flags.get("--deadline") !== owner.deadline)
300
+ return other(`ends at ${show(flags.get("--deadline"))}, not the computer's deadline ${show(owner.deadline)}`);
301
+ const unknown = [...flags.keys()].filter((flag) => !["--socket", "--deadline", "--allow", "--local", "--hint"].includes(flag));
302
+ if (unknown.length > 0)
303
+ return other(`runs with flags ${unknown.join(", ")}, which create never gives`);
304
+ const read = allowOf((flags.get("--allow") ?? "").split(","));
305
+ if ("problem" in read)
306
+ return other(`holds a list this provider never makes: ${read.problem}`);
307
+ // The host block: a --local removed or shortened lets the computer reach the Docker host's own addresses.
308
+ const refused = new Set((flags.get("--local") ?? "").split(",").filter(Boolean));
309
+ const missing = local.filter((address) => !refused.has(address));
310
+ if (missing.length > 0) {
311
+ return other(`does not refuse the Docker host's ${missing.length === 1 ? "address" : "addresses"} ${missing.join(", ")} (its --local reads ${show(flags.get("--local"))})`);
312
+ }
313
+ return { allow: read.list };
314
+ }
315
+ /** The ports each entry of a Docker allowlist opens. */
316
+ export const ALLOW_PORTS = [...LISTED_PORTS];
317
+ /** A policy as a refusal or a read-back names it. */
318
+ export const policyWords = (policy) => (typeof policy === "string" ? policy : "other" in policy ? policy.other : JSON.stringify(policy));