@parcha/agentrun-computer 0.1.0-beta.49 → 0.1.0-beta.50

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 CHANGED
@@ -452,7 +452,7 @@ in the kernel's tool registry, keyed by these groups.
452
452
  | id | label | kinds | keys (required unless marked) | mounts | metered |
453
453
  | --- | --- | --- | --- | --- | --- |
454
454
  | docker | Docker | sandbox, desktop | none | bind | no |
455
- | daytona | Daytona | sandbox | `DAYTONA_API_KEY`; `DAYTONA_API_URL`, `DAYTONA_TARGET`, `DAYTONA_ARCHIL_EGRESS` (optional) | none (`unmounted`: archil); archil with `DAYTONA_ARCHIL_EGRESS` (`mountsWith`) | yes |
455
+ | daytona | Daytona | sandbox | `DAYTONA_API_KEY`; `DAYTONA_API_URL`, `DAYTONA_TARGET`, `DAYTONA_ARCHIL_EGRESS`, `DAYTONA_ATTACH_EGRESS` (optional) | none (`unmounted`: archil); archil with `DAYTONA_ARCHIL_EGRESS` (`mountsWith`) | yes |
456
456
  | modal | Modal | sandbox | `MODAL_TOKEN_ID`, `MODAL_TOKEN_SECRET` | archil | yes |
457
457
  | e2b | E2B | sandbox, desktop | `E2B_API_KEY` | archil | yes |
458
458
  | orgo | Orgo | desktop (Linux; Windows and macOS with `os`) | `ORGO_API_KEY` | none | yes |
@@ -1582,6 +1582,11 @@ the TTL.
1582
1582
  own namespace (`agentrun.computer`), `cpus`, `memoryMb` or `pids` (a snapshot's size is its own), `user`, `workdir`
1583
1583
  (the daemon works in `/work`), a GPU computer's snapshot other than the GPU snapshot or `"default"`, and any other
1584
1584
  field.
1585
+ - What the computer was given is the sandbox's own: `create` answers `resources` (`CreatedComputer.resources`) with
1586
+ the `cpu`, `memory` (GiB, as `memoryMb`), `disk` (GiB, as `diskGb`) and GPUs (`gpu` and `gpuType`) Daytona's read of
1587
+ the running sandbox says, each only where it says it. These are the figures Daytona bills by, and a host prices
1588
+ computer time by them (serve's `AGENTRUN_COMPUTE_USD_PER_*` settings). E2B's create answers its `getInfo`'s `cpuCount`
1589
+ and `memoryMB` the same way, and Fly's its machine guest's `cpus` and `memory_mb`; any other provider answers none.
1585
1590
  - `create(spec, { requestId })` names the computer `computer-<12 hex digits of sha256(requestId)>` and lists that name
1586
1591
  first: a retry of the same request finds the computer the first one made (the adapter's idempotent create,
1587
1592
  [PROVIDERS.md](PROVIDERS.md)). It sends `POST /sandbox` with that name, the snapshot (none for `"default"`), the
@@ -1708,14 +1713,19 @@ What each part of a dial sandbox rests on:
1708
1713
  ([api snapshot.service.ts:883-901](https://github.com/daytonaio/daytona/blob/b5a5d9e7/apps/api/src/sandbox/services/snapshot.service.ts#L883-L901)),
1709
1714
  so `box/build-daytona.py` names the Dockerfile's CMD as the snapshot's `entrypoint`. The box snapshots it built
1710
1715
  before, `agentrun-archil-<recipe hash>`, have none and never dial, so the snapshot it builds now has a name of its
1711
- own, `agentrun-box-<recipe hash>`, which no snapshot without the entrypoint holds. (The Dockerfile's comment that Daytona runs its
1712
- CMD is wrong; it stays until the recipe next changes, since editing it changes the hash.)
1716
+ own, `agentrun-box-<recipe hash>`, which no snapshot without the entrypoint holds.
1713
1717
  - **Outbound https, by tier.** Tier 1 and 2 organizations reach "essential services" alone, and those leave out shared
1714
1718
  hosting domains; Tier 3 and 4 have full access
1715
1719
  ([docs: tier-based network restrictions](https://www.daytona.io/docs/en/network-limits.md#tier-based-network-restrictions)).
1716
1720
  A server on such a domain (`*.onrender.com`) is out of a Tier 1 or 2 sandbox's reach unless Daytona adds that exact
1717
1721
  host to the list ([docs: essential services](https://www.daytona.io/docs/en/network-limits.md#essential-services)).
1718
1722
  **Unverified**: our organization's tier, and a dial from it.
1723
+ - **A target that reaches listed addresses alone: `attachEgress`.** A self-hosted target whose runners drop every
1724
+ sandbox connection outside an allow list never reaches a public server. Give the operator's relay on that list as
1725
+ `attachEgress` (`DAYTONA_ATTACH_EGRESS` in Settings), `<IPv4 relay>:<port>`, checked at construction: create puts it
1726
+ in the boot env as `AGENTRUN_ATTACH_EGRESS`, and `agentrun-dial`'s daemon fetch (curl `--connect-to`) and
1727
+ `computerd attach` both open TCP to it and speak TLS and HTTP to the public host through it, so the SNI, the
1728
+ certificate checked and `Host` stay the public host's and TLS is end to end. Unset, nothing changes.
1719
1729
  - **No GPU on dial**, refused in words: `daytona-gpu` holds no `agentrun-dial`, and Daytona runs a GPU sandbox
1720
1730
  unprivileged (`Privileged: gpuIndex == nil`,
1721
1731
  [runner container_configs.go:205](https://github.com/daytonaio/daytona/blob/b5a5d9e7/apps/runner/pkg/docker/container_configs.go#L205)),
package/box/Dockerfile CHANGED
@@ -36,7 +36,7 @@ COPY agentrun-archil /tmp/agentrun-box/agentrun-archil
36
36
  RUN sh /tmp/agentrun-box/install.sh && rm -rf /tmp/agentrun-box
37
37
 
38
38
  USER root
39
- # A computer's first process is its provider's own (Daytona's runs this when a snapshot names no entrypoint; Modal's and
40
- # E2B's are their own): never the base image's python. A machine whose create set AGENTRUN_ATTACH_URL dials the server
41
- # instead (install.sh's agentrun-dial).
39
+ # A computer's first process is its provider's own (Daytona's toolbox, Modal's and E2B's own), never the base image's
40
+ # python. Daytona never runs an image's CMD, only a snapshot's entrypoint, so box/build-daytona.py names this CMD as
41
+ # the snapshot's. A machine whose create set AGENTRUN_ATTACH_URL dials the server instead (install.sh's agentrun-dial).
42
42
  CMD ["sh", "-c", "[ -z \"${AGENTRUN_ATTACH_URL-}\" ] || exec agentrun-dial; exec sleep infinity"]
package/box/install.sh CHANGED
@@ -75,8 +75,10 @@ dial() {
75
75
  # where the provider's exec install puts it, starts `computerd init` as that start does, in a clean environment without
76
76
  # the token (with DISPLAY, for a desktop), and becomes `computerd attach` with the attach URL and the token alone in its environment. Before init, it
77
77
  # gives /workspace to init's user (its --user), 0700, where a synced folder's runner pushes the run's folder. A daemon
78
- # whose sha256 is not AGENTRUN_DAEMON_SHA256 is removed, and nothing runs. Exits 2 for env missing, 3 when the fetch
79
- # failed, 4 for a sha256 mismatch, 5 when init never listened, 6 when /workspace was not made init's user's; else it is
78
+ # whose sha256 is not AGENTRUN_DAEMON_SHA256 is removed, and nothing runs. With AGENTRUN_ATTACH_EGRESS, the operator's
79
+ # relay (<IPv4>:<port>), the fetch and attach's dial both connect to the relay and speak TLS and HTTP to the URL's host
80
+ # through it, and attach is given it too. Exits 2 for env missing or a malformed relay, 3 when the fetch failed, 4 for
81
+ # a sha256 mismatch, 5 when init never listened, 6 when /workspace was not made init's user's; else it is
80
82
  # `computerd attach` and exits as it does.
81
83
  set -euf
82
84
  DAEMON=/opt/agentrun/computerd
@@ -89,6 +91,16 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
89
91
  for v in AGENTRUN_ATTACH_URL AGENTRUN_ATTACH_TOKEN AGENTRUN_DAEMON_URL AGENTRUN_DAEMON_SHA256 AGENTRUN_INIT_ARGS; do
90
92
  eval "[ -n \"\${$v-}\" ]" || { echo "agentrun-dial: $v is not set; the provider's create sets it" >&2; exit 2; }
91
93
  done
94
+ # The operator's relay, where the machine reaches the server only through it (a provider's attach egress): curl connects
95
+ # there and speaks TLS and HTTP to the URL's host as it would directly (--connect-to keeps the SNI, the certificate check
96
+ # and the Host header the URL's). Digits, dots and colons alone, so it splits into exactly curl's two words; attach
97
+ # checks its shape whole.
98
+ relay=
99
+ case "${AGENTRUN_ATTACH_EGRESS-}" in
100
+ "") ;;
101
+ *[!0-9.:]*) echo "agentrun-dial: AGENTRUN_ATTACH_EGRESS is the relay's <IPv4>:<port>; the provider's create sets it" >&2; exit 2 ;;
102
+ *) relay="--connect-to ::$AGENTRUN_ATTACH_EGRESS" ;;
103
+ esac
92
104
  # init's user, uid:gid, from its --user: /workspace is that user's alone, never a link.
93
105
  user=
94
106
  set -- $AGENTRUN_INIT_ARGS
@@ -107,8 +119,8 @@ chmod 0700 "$SOCKET_DIR"
107
119
  rm -f "$DAEMON.part"
108
120
  # The token goes to curl on its stdin, never on a command line, which every user may read in /proc.
109
121
  printf 'Authorization: Bearer %s\n' "$AGENTRUN_ATTACH_TOKEN" |
110
- curl -fsS --connect-timeout 10 --retry 10 --retry-connrefused --retry-max-time 300 -H @- -o "$DAEMON.part" "$AGENTRUN_DAEMON_URL" ||
111
- { echo "agentrun-dial: fetching the daemon from $AGENTRUN_DAEMON_URL failed" >&2; rm -f "$DAEMON.part"; exit 3; }
122
+ curl -fsS --connect-timeout 10 --retry 10 --retry-connrefused --retry-max-time 300 $relay -H @- -o "$DAEMON.part" "$AGENTRUN_DAEMON_URL" ||
123
+ { echo "agentrun-dial: fetching the daemon from $AGENTRUN_DAEMON_URL${relay:+ through $AGENTRUN_ATTACH_EGRESS} failed" >&2; rm -f "$DAEMON.part"; exit 3; }
112
124
  sum=$(sha256sum "$DAEMON.part" | cut -c1-64)
113
125
  if [ "$sum" != "$AGENTRUN_DAEMON_SHA256" ]; then
114
126
  rm -f "$DAEMON.part"
@@ -128,9 +140,10 @@ until [ -S "$SOCKET_DIR/computerd.sock" ]; do
128
140
  [ "$i" -le 300 ] || { echo "agentrun-dial: init did not listen at $SOCKET_DIR/computerd.sock within 30 s; its log:" >&2; cat "$INIT_LOG" >&2; exit 5; }
129
141
  sleep 0.1
130
142
  done
131
- # attach's environment: the URL and token alone (it dials init at its default socket, SOCKET_DIR's).
143
+ # attach's environment: the URL and token alone, and the relay when given (it dials init at its default socket,
144
+ # SOCKET_DIR's).
132
145
  for v in $(env | sed -n 's/^\([A-Za-z_][A-Za-z0-9_]*\)=.*/\1/p'); do
133
- case "$v" in AGENTRUN_ATTACH_URL | AGENTRUN_ATTACH_TOKEN | DAEMON) ;; *) unset "$v" 2>/dev/null || : ;; esac
146
+ case "$v" in AGENTRUN_ATTACH_URL | AGENTRUN_ATTACH_TOKEN | AGENTRUN_ATTACH_EGRESS | DAEMON) ;; *) unset "$v" 2>/dev/null || : ;; esac
134
147
  done
135
148
  exec "$DAEMON" attach
136
149
  EOF
package/dist/attach.d.ts CHANGED
@@ -5,6 +5,15 @@ import { type Result } from "./result.js";
5
5
  export declare const ATTACH_PATH = "/v2/computers/attach";
6
6
  /** Where a hosted machine that dials fetches the server's computerd for its arch (?arch=amd64|arm64), with its token. */
7
7
  export declare const DAEMON_PATH = "/v2/computers/daemon";
8
+ /** The boot env name of a dial machine's attach egress (HostedOptions.attachEgress), which agentrun-dial and computerd attach read. */
9
+ export declare const ATTACH_EGRESS_ENV = "AGENTRUN_ATTACH_EGRESS";
10
+ /**
11
+ * Reads an attach egress, `<IPv4 relay>:<port>` such as 192.0.2.40:18443: the operator's relay a dial machine opens TCP
12
+ * to in place of the public host, for its daemon fetch and its attach socket alike, speaking TLS and HTTP to the public
13
+ * host through it (the SNI, the certificate checked and the Host header stay the public host's). computerd attach holds
14
+ * it to the same shape. Anything else throws, in words.
15
+ */
16
+ export declare function attachEgressOf(text: string): string;
8
17
  /** The WebSocket subprotocol a driver asks for: the protocol version it speaks. Serve answers with it or refuses. */
9
18
  export declare const ATTACH_SUBPROTOCOL = "agentrun.computer.0.2";
10
19
  /** Each side pings this often (WebSocket ping frames, not JSON-RPC), so a NAT keeps the path open. */
package/dist/attach.js CHANGED
@@ -15,6 +15,20 @@ import { fail, ok } from "./result.js";
15
15
  export const ATTACH_PATH = "/v2/computers/attach";
16
16
  /** Where a hosted machine that dials fetches the server's computerd for its arch (?arch=amd64|arm64), with its token. */
17
17
  export const DAEMON_PATH = "/v2/computers/daemon";
18
+ /** The boot env name of a dial machine's attach egress (HostedOptions.attachEgress), which agentrun-dial and computerd attach read. */
19
+ export const ATTACH_EGRESS_ENV = "AGENTRUN_ATTACH_EGRESS";
20
+ const ATTACH_EGRESS = /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d):(?:[1-9]\d{0,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/;
21
+ /**
22
+ * Reads an attach egress, `<IPv4 relay>:<port>` such as 192.0.2.40:18443: the operator's relay a dial machine opens TCP
23
+ * to in place of the public host, for its daemon fetch and its attach socket alike, speaking TLS and HTTP to the public
24
+ * host through it (the SNI, the certificate checked and the Host header stay the public host's). computerd attach holds
25
+ * it to the same shape. Anything else throws, in words.
26
+ */
27
+ export function attachEgressOf(text) {
28
+ if (!ATTACH_EGRESS.test(text))
29
+ throw new Error(`the attach egress is <IPv4 relay>:<port>, such as 192.0.2.40:18443, a port from 1 to 65535; not ${JSON.stringify(text)}`);
30
+ return text;
31
+ }
18
32
  /** The WebSocket subprotocol a driver asks for: the protocol version it speaks. Serve answers with it or refuses. */
19
33
  export const ATTACH_SUBPROTOCOL = `agentrun.computer.${PROTOCOL_VERSION}`;
20
34
  /** Each side pings this often (WebSocket ping frames, not JSON-RPC), so a NAT keeps the path open. */
Binary file
Binary file
@@ -1,4 +1,4 @@
1
1
  {
2
- "version": "0.1.0-beta.49",
3
- "source": "sha256:cda430945f036061ea4f8a49fe0d619a058f1876cd3dd6ae75b1e2514d5dba35"
2
+ "version": "0.1.0-beta.50",
3
+ "source": "sha256:e4c673ff5826d1db1bf27c6c237a80753cae1b5e218ab4d17d123af0075ccb4b"
4
4
  }
@@ -30,6 +30,8 @@ export declare const DAYTONA_ENV: {
30
30
  * provider takes an Archil mount; unset, it refuses one (Archil's client hangs on Daytona's hosted cloud).
31
31
  */
32
32
  readonly archilEgress: "COMPUTER_DAYTONA_ARCHIL_EGRESS";
33
+ /** attachEgress: a self-hosted Daytona target's attach relay, <IPv4 relay>:<port>, which its machines that dial go through. */
34
+ readonly attachEgress: "COMPUTER_DAYTONA_ATTACH_EGRESS";
33
35
  /** connect: exec (default) or dial, which needs the public server's process (dialKit). */
34
36
  readonly connect: "COMPUTER_DAYTONA_CONNECT";
35
37
  /** kind: linux (default) or desktop, which create() takes on dial alone. */
@@ -60,6 +62,8 @@ export declare const ENV: {
60
62
  * provider takes an Archil mount; unset, it refuses one (Archil's client hangs on Daytona's hosted cloud).
61
63
  */
62
64
  readonly archilEgress: "COMPUTER_DAYTONA_ARCHIL_EGRESS";
65
+ /** attachEgress: a self-hosted Daytona target's attach relay, <IPv4 relay>:<port>, which its machines that dial go through. */
66
+ readonly attachEgress: "COMPUTER_DAYTONA_ATTACH_EGRESS";
63
67
  /** connect: exec (default) or dial, which needs the public server's process (dialKit). */
64
68
  readonly connect: "COMPUTER_DAYTONA_CONNECT";
65
69
  /** kind: linux (default) or desktop, which create() takes on dial alone. */
@@ -40,6 +40,8 @@ export const DAYTONA_ENV = {
40
40
  * provider takes an Archil mount; unset, it refuses one (Archil's client hangs on Daytona's hosted cloud).
41
41
  */
42
42
  archilEgress: "COMPUTER_DAYTONA_ARCHIL_EGRESS",
43
+ /** attachEgress: a self-hosted Daytona target's attach relay, <IPv4 relay>:<port>, which its machines that dial go through. */
44
+ attachEgress: "COMPUTER_DAYTONA_ATTACH_EGRESS",
43
45
  /** connect: exec (default) or dial, which needs the public server's process (dialKit). */
44
46
  connect: "COMPUTER_DAYTONA_CONNECT",
45
47
  /** kind: linux (default) or desktop, which create() takes on dial alone. */
@@ -64,6 +66,7 @@ export function settingsFromEnv(env = process.env) {
64
66
  const user = named(DAYTONA_ENV.user);
65
67
  const gpuSnapshot = named(DAYTONA_ENV.gpuSnapshot);
66
68
  const archilEgress = named(DAYTONA_ENV.archilEgress);
69
+ const attachEgress = named(DAYTONA_ENV.attachEgress);
67
70
  const connect = named(DAYTONA_ENV.connect);
68
71
  return {
69
72
  apiKey,
@@ -79,6 +82,8 @@ export function settingsFromEnv(env = process.env) {
79
82
  ...(gpuSnapshot ? { gpuSnapshot: gpuSnapshot.value } : {}),
80
83
  // create() refuses one of another shape in words.
81
84
  ...(archilEgress ? { archilEgress: archilEgress.value } : {}),
85
+ // create() refuses one of another shape in words.
86
+ ...(attachEgress ? { attachEgress: attachEgress.value } : {}),
82
87
  // create() refuses any other value in words.
83
88
  ...(connect ? { connect: connect.value } : {}),
84
89
  };
@@ -1,12 +1,14 @@
1
1
  import type { Rect, UiFlag, UiRole, UiRoute } from "../protocol.js";
2
2
  /**
3
3
  * What pressing an element does, `after` ms later: go opens a screen in its window (through a transition of
4
- * animateMs), open opens a new window of the app on that screen, in front, and close closes the window it is in.
4
+ * animateMs), open opens a new window of the app on that screen, in front, close closes the window it is in, and launch
5
+ * brings another installed app in front, as a phone's press that opens another package's page does.
5
6
  */
6
7
  export interface FakeEffect {
7
8
  go?: string;
8
9
  open?: string;
9
10
  close?: true;
11
+ launch?: string;
10
12
  after?: number;
11
13
  animateMs?: number;
12
14
  }
package/dist/daytona.d.ts CHANGED
@@ -39,6 +39,13 @@ export interface DaytonaProviderOptions extends Omit<HostedOptions, "desktop" |
39
39
  * words, since Archil's client hangs on Daytona's hosted cloud. Set it only for such a target.
40
40
  */
41
41
  archilEgress?: string;
42
+ /**
43
+ * The operator's attach relay, `<IPv4 relay>:<port>` (HostedOptions.attachEgress, attachEgressOf): for a self-hosted
44
+ * Daytona target whose runners drop every sandbox connection outside an allow list that the public address is not on.
45
+ * A machine that dials (connect dial, and every desktop) fetches the daemon and opens its attach socket through it,
46
+ * with TLS end to end to the public host. Unset, it dials the public host; a machine on exec never reads it.
47
+ */
48
+ attachEgress?: string;
42
49
  /**
43
50
  * The snapshot GPU computers are made from: one of ours, box/Dockerfile built with a GPU (box/build-daytona.py --gpu
44
51
  * H100 prints its name, agentrun-archil-gpu-h100-<hash>), whose user is root; its GPU is the one its name says.
package/dist/daytona.js CHANGED
@@ -20,6 +20,20 @@ import { dateOf, isWhole, sizeRefusals } from "./hosted/values.js";
20
20
  import { MAX_LINE_BYTES } from "./protocol.js";
21
21
  import { checkGpu } from "./provider.js";
22
22
  import { ok, vendorFail } from "./result.js";
23
+ /** A positive finite figure of Daytona's answer, else undefined (absent, zero or not a number: never guessed). */
24
+ const given = (value) => (typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined);
25
+ /** What Daytona says a sandbox was given (Machine.resources): its CPUs, its memory (GiB, as MB), its disk (GiB) and its
26
+ * GPUs (count and type), each where its answer says it; none where it says nothing. */
27
+ function resourcesOf(sb) {
28
+ const [cpus, memory, disk, gpus] = [given(sb.cpu), given(sb.memory), given(sb.disk), given(sb.gpu)];
29
+ const resources = {
30
+ ...(cpus === undefined ? {} : { cpus }),
31
+ ...(memory === undefined ? {} : { memoryMb: memory * 1024 }),
32
+ ...(disk === undefined ? {} : { diskGb: disk }),
33
+ ...(gpus !== undefined && typeof sb.gpuType === "string" && sb.gpuType !== "" ? { gpu: { type: sb.gpuType, count: gpus } } : {}),
34
+ };
35
+ return Object.keys(resources).length > 0 ? { resources } : {};
36
+ }
23
37
  /**
24
38
  * A DaytonaProvider from its options alone; it reads no environment, so the key, the API URL (default Daytona's own) and
25
39
  * the target are the caller's: serve passes its DAYTONA_API_KEY, DAYTONA_API_URL and DAYTONA_TARGET, the conformance
@@ -188,6 +202,7 @@ class DaytonaHost {
188
202
  state: stateOf(sb),
189
203
  ...(made ? { createdAt: made } : {}),
190
204
  ...(endsAt ? { endsAt } : {}),
205
+ ...resourcesOf(sb),
191
206
  // A failed sandbox always carries a why, Daytona's or ours, so create stops on it as vendor, never as gone.
192
207
  ...(typeof sb.errorReason === "string" && sb.errorReason !== "" ? { why: sb.errorReason } : FAILED.has(sb.state ?? "") ? { why: `Daytona reads the sandbox ${sb.state}, with no reason given` } : {}),
193
208
  };
@@ -1,6 +1,11 @@
1
1
  import type { GpuCapability } from "../provider.js";
2
2
  /** The key that turns on a Daytona computer's Archil mount: the operator's Archil egress relay (archilEgress). */
3
3
  export declare const DAYTONA_ARCHIL_EGRESS = "DAYTONA_ARCHIL_EGRESS";
4
+ /**
5
+ * The key that sends a Daytona machine that dials through the operator's relay, `<IPv4 relay>:<port>` (attachEgress):
6
+ * for a self-hosted target whose sandboxes reach only the addresses its runners allow.
7
+ */
8
+ export declare const DAYTONA_ATTACH_EGRESS = "DAYTONA_ATTACH_EGRESS";
4
9
  /** Why a Daytona computer made with no Archil egress takes no Archil mount: check() refuses one in these words. */
5
10
  export declare const DAYTONA_NO_ARCHIL = "Archil mounts don't work on Daytona's hosted cloud, where Archil's client hangs on its sandboxes; a self-hosted Daytona target takes one once its operator sets DAYTONA_ARCHIL_EGRESS";
6
11
  /** The image a Daytona computer starts from when its spec names "default": Daytona's own default snapshot. */
@@ -64,6 +69,10 @@ export declare const DAYTONA: {
64
69
  readonly name: "DAYTONA_ARCHIL_EGRESS";
65
70
  readonly option: "archilEgress";
66
71
  readonly required: false;
72
+ }, {
73
+ readonly name: "DAYTONA_ATTACH_EGRESS";
74
+ readonly option: "attachEgress";
75
+ readonly required: false;
67
76
  }];
68
77
  readonly settings: readonly [{
69
78
  readonly name: "daytonaConnect";
@@ -4,6 +4,11 @@ import { defineProvider } from "../descriptor.js";
4
4
  import { LINUX_DESKTOP, SANDBOX } from "./shared.js";
5
5
  /** The key that turns on a Daytona computer's Archil mount: the operator's Archil egress relay (archilEgress). */
6
6
  export const DAYTONA_ARCHIL_EGRESS = "DAYTONA_ARCHIL_EGRESS";
7
+ /**
8
+ * The key that sends a Daytona machine that dials through the operator's relay, `<IPv4 relay>:<port>` (attachEgress):
9
+ * for a self-hosted target whose sandboxes reach only the addresses its runners allow.
10
+ */
11
+ export const DAYTONA_ATTACH_EGRESS = "DAYTONA_ATTACH_EGRESS";
7
12
  /** Why a Daytona computer made with no Archil egress takes no Archil mount: check() refuses one in these words. */
8
13
  export const DAYTONA_NO_ARCHIL = `Archil mounts don't work on Daytona's hosted cloud, where Archil's client hangs on its sandboxes; a self-hosted Daytona target takes one once its operator sets ${DAYTONA_ARCHIL_EGRESS}`;
9
14
  /** The image a Daytona computer starts from when its spec names "default": Daytona's own default snapshot. */
@@ -71,6 +76,7 @@ export const DAYTONA = defineProvider({
71
76
  { name: "DAYTONA_API_URL", option: "apiUrl", required: false },
72
77
  { name: "DAYTONA_TARGET", option: "target", required: false },
73
78
  { name: DAYTONA_ARCHIL_EGRESS, option: "archilEgress", required: false },
79
+ { name: DAYTONA_ATTACH_EGRESS, option: "attachEgress", required: false },
74
80
  ],
75
81
  // How the server reaches its machines: exec (the provider's default, when the server's settings name none), a session
76
82
  // command through the toolbox per connection, or dial, the machine dials the server (a snapshot of box/Dockerfile).
@@ -55,6 +55,10 @@ export declare const DESCRIPTORS: readonly [{
55
55
  readonly name: "DAYTONA_ARCHIL_EGRESS";
56
56
  readonly option: "archilEgress";
57
57
  readonly required: false;
58
+ }, {
59
+ readonly name: "DAYTONA_ATTACH_EGRESS";
60
+ readonly option: "attachEgress";
61
+ readonly required: false;
58
62
  }];
59
63
  readonly settings: readonly [{
60
64
  readonly name: "daytonaConnect";
package/dist/e2b.js CHANGED
@@ -127,8 +127,13 @@ function machineOf(info) {
127
127
  }
128
128
  const started = dateOf(info.startedAt);
129
129
  const state = info.state === "running" ? "running" : info.state === "paused" ? "stopped" : "gone";
130
- return { id: info.sandboxId, labels, state, ...(started ? { createdAt: started } : {}), ...(end ? { endsAt: end } : {}) };
130
+ // What E2B says the sandbox was given (SandboxInfo's cpuCount and memoryMB), where it says it; E2B's answer has no disk.
131
+ const [cpus, memoryMb] = [positive(info.cpuCount), positive(info.memoryMB)];
132
+ const resources = { ...(cpus === undefined ? {} : { cpus }), ...(memoryMb === undefined ? {} : { memoryMb }) };
133
+ return { id: info.sandboxId, labels, state, ...(started ? { createdAt: started } : {}), ...(end ? { endsAt: end } : {}), ...(Object.keys(resources).length > 0 ? { resources } : {}) };
131
134
  }
135
+ /** A positive finite figure of a vendor's answer, else undefined: never guessed. */
136
+ const positive = (value) => (typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined);
132
137
  /** One chunk of the SDK's output into a stream, unless the stream has ended. */
133
138
  const push = (stream, data) => void (stream.writableEnded || stream.write(data));
134
139
  /** E2B's sandboxes as a MachineHost (../host.ts). */
@@ -463,13 +463,18 @@ export class FakeUiDriver {
463
463
  this.#apply(state, win, element.press);
464
464
  }
465
465
  /**
466
- * A press's effect, from the window it landed in: go to a screen in that window, open another window, or close that
467
- * one. A delayed effect is that window's pending effect: it never lands once the window closed.
466
+ * A press's effect, from the window it landed in: go to a screen in that window, open another window, close that
467
+ * one, or bring another app in front (on a phone, the app it left is then out of reach). A delayed effect is that
468
+ * window's pending effect: it never lands once the window closed.
468
469
  */
469
470
  #apply(state, win, effect) {
470
471
  const go = () => {
471
472
  if (effect.close === true)
472
473
  return this.#closeWindow(state, win);
474
+ if (effect.launch !== undefined) {
475
+ this.#launch({ id: effect.launch });
476
+ return;
477
+ }
473
478
  if (effect.open !== undefined) {
474
479
  state.opened += 1;
475
480
  const [x, y, w, h] = state.origin;
package/dist/fly.d.ts CHANGED
@@ -7,12 +7,20 @@ export interface FlyMachine {
7
7
  created_at?: string;
8
8
  config?: {
9
9
  metadata?: Record<string, string> | null;
10
+ guest?: FlyGuest | null;
10
11
  } | null;
11
12
  /** fly-go: the config rebuilt in part while host_status isn't "ok". */
12
13
  incomplete_config?: {
13
14
  metadata?: Record<string, string> | null;
15
+ guest?: FlyGuest | null;
14
16
  } | null;
15
17
  }
18
+ /** A machine's guest as Fly answers it (M, MachineGuest): its CPUs and memory, which Fly bills by. */
19
+ export interface FlyGuest {
20
+ cpu_kind?: string;
21
+ cpus?: number;
22
+ memory_mb?: number;
23
+ }
16
24
  /** The Fly provider's options: the token and the app, then the shared adapter's (HostedOptions), kind among them. */
17
25
  export interface FlyProviderOptions extends Omit<HostedOptions, "desktop" | "maxLifetimeMs"> {
18
26
  /** A Fly API token that may make machines in the app. The caller passes it; this provider reads no environment. */
package/dist/fly.js CHANGED
@@ -76,8 +76,17 @@ function machineOf(found) {
76
76
  state: state ?? "gone",
77
77
  ...(created ? { createdAt: created } : {}),
78
78
  ...(why ? { why } : {}),
79
+ ...guestResources(config.guest),
79
80
  };
80
81
  }
82
+ /** What Fly says a machine was given (its guest's cpus and memory_mb), where its answer says it; none else. */
83
+ function guestResources(guest) {
84
+ const figure = (value) => (typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined);
85
+ const [cpus, memoryMb] = [figure(guest?.cpus), figure(guest?.memory_mb)];
86
+ if (cpus === undefined && memoryMb === undefined)
87
+ return {};
88
+ return { resources: { ...(cpus === undefined ? {} : { cpus }), ...(memoryMb === undefined ? {} : { memoryMb }) } };
89
+ }
81
90
  /** An id held to Fly's form before it reaches a path: not_found else. */
82
91
  function machineId(id) {
83
92
  if (!MACHINE_ID.test(id))
package/dist/host.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ProviderDescriptor } from "./descriptor.js";
2
- import type { ComputerCapabilities, ComputerSpec, GpuSpec, Refusal } from "./provider.js";
2
+ import type { ComputerCapabilities, ComputerResources, ComputerSpec, GpuSpec, Refusal } from "./provider.js";
3
3
  import type { ComputerErrorCode } from "./result.js";
4
4
  /**
5
5
  * One vendor's machines. Every call answers its value or throws: a failure whose code the host knows throws a
@@ -185,6 +185,9 @@ export interface Machine {
185
185
  createdAt?: Date;
186
186
  /** The vendor's words for a machine that is gone because it failed: a create stops in them. */
187
187
  why?: string;
188
+ /** What the vendor's answer says the machine was given (its CPUs, memory, disk, GPUs), where it says it: a create
189
+ * returns these as its computer's resources. Absent where the answer says none. */
190
+ resources?: ComputerResources;
188
191
  }
189
192
  /** A process exec started: its output as it comes, its stdin, and its end. */
190
193
  export interface MachineProcess {
@@ -66,6 +66,13 @@ export interface HostedOptions {
66
66
  * Given to the helper's mount and revoke. Unset or empty, the client reaches Archil as the machine's network allows.
67
67
  */
68
68
  archilEgress?: string;
69
+ /**
70
+ * The relay a dial machine reaches this server through, `<IPv4 relay>:<port>` such as 192.0.2.40:18443
71
+ * (attachEgressOf): for a vendor whose machines reach only addresses the operator allows. A dial machine is booted with
72
+ * it as AGENTRUN_ATTACH_EGRESS, and its daemon fetch and attach socket both open TCP to it, speaking TLS and HTTP to
73
+ * the public host through it. Unset or empty, they go to the public host; a host whose machines don't dial ignores it.
74
+ */
75
+ attachEgress?: string;
69
76
  /** What a host whose facts.connect is "dial" needs: create refuses without it, before any call to the vendor, in words
70
77
  * that name serve's one-process start (a runner apart from the server has none). */
71
78
  dial?: HostedDial;
@@ -11,7 +11,7 @@ import { readFileSync } from "node:fs";
11
11
  import { resolve } from "node:path";
12
12
  import { fileURLToPath } from "node:url";
13
13
  import { isDeepStrictEqual } from "node:util";
14
- import { ATTACH_PATH, DAEMON_PATH } from "../attach.js";
14
+ import { ATTACH_EGRESS_ENV, ATTACH_PATH, attachEgressOf, DAEMON_PATH } from "../attach.js";
15
15
  import { CreateRequests, endedWords, otherSpecWords, readBackDiffer } from "../create-requests.js";
16
16
  import { mountsOf, syncs } from "../descriptor.js";
17
17
  import { desktopOf, startDisplay } from "../desktop.js";
@@ -172,17 +172,21 @@ export class HostedProvider {
172
172
  #probeTargets;
173
173
  #onNote;
174
174
  #archilEgress;
175
+ #attachEgress;
175
176
  /** Each create in flight, and the names of the computers this provider ended (create-requests.ts). In memory alone:
176
177
  * past it, and past this process, the vendor's listing is what holds. */
177
178
  #requests = new CreateRequests();
178
179
  /** Each computer's last extend, by machine id, while one runs: the next waits for it. */
179
180
  #extending = new Map();
181
+ /** What the vendor said a machine this create made was given (Machine.resources), by machine id, from its read once it
182
+ * ran (#prepare) until the create answers with it (#createOnce). */
183
+ #given = new Map();
180
184
  /** A dial host's server: what its machines reach, and what holds their tokens and sockets. */
181
185
  #dial;
182
186
  /** The host's descriptor's mounts as its machines reach this server (mountsOf): a dial host's take no Archil mount. */
183
187
  #mounts;
184
188
  constructor(host, options) {
185
- const { kind = "linux", desktop = {}, maxLifetimeMs = host.facts.maxLifetimeMs, daemonPath = hostedDaemonPath(host.facts.arch), daemonUser = TOOL_USER, timeouts = {}, probeTargets = DEFAULT_PROBE_TARGETS, onNote, archilEgress, } = options;
189
+ const { kind = "linux", desktop = {}, maxLifetimeMs = host.facts.maxLifetimeMs, daemonPath = hostedDaemonPath(host.facts.arch), daemonUser = TOOL_USER, timeouts = {}, probeTargets = DEFAULT_PROBE_TARGETS, onNote, archilEgress, attachEgress, } = options;
186
190
  const { id, label, capabilities } = host.descriptor;
187
191
  if (kind !== "desktop" && kind !== "linux")
188
192
  throw new Error(`kind is desktop or linux, not ${String(kind)}`);
@@ -196,6 +200,7 @@ export class HostedProvider {
196
200
  this.#fail = failFor(id);
197
201
  this.#onNote = onNote;
198
202
  this.#archilEgress = archilEgress === undefined || archilEgress === "" ? undefined : archilEgressOf(archilEgress);
203
+ this.#attachEgress = attachEgress === undefined || attachEgress === "" ? undefined : attachEgressOf(attachEgress);
199
204
  if (!isWhole(maxLifetimeMs) || maxLifetimeMs <= 0 || maxLifetimeMs > host.facts.maxLifetimeMs) {
200
205
  throw new Error(`maxLifetimeMs must be a whole number of ms above 0 and at most ${host.facts.maxLifetimeMs} ms, the longest ${label} keeps a computer`);
201
206
  }
@@ -543,6 +548,8 @@ export class HostedProvider {
543
548
  if (first.ok && first.value !== undefined && first.value.id !== ref.id)
544
549
  return this.#again(spec, name, first.value, signal);
545
550
  const prepared = await this.#prepare(spec, ref, made, signal);
551
+ const given = this.#given.get(ref.id);
552
+ this.#given.delete(ref.id);
546
553
  if (signal?.aborted)
547
554
  return this.#abandon(ref, { code: "aborted", message: "create was aborted" }, signal);
548
555
  if (!prepared.ok) {
@@ -561,7 +568,7 @@ export class HostedProvider {
561
568
  return this.#abandon(ref, last.error, signal, true);
562
569
  if (last.value !== undefined && last.value.id !== ref.id)
563
570
  return this.#again(spec, name, last.value, signal);
564
- return ok(prepared.value.length > 0 ? { ...ref, notes: prepared.value } : ref);
571
+ return ok({ ...ref, ...(prepared.value.length > 0 ? { notes: prepared.value } : {}), ...(given === undefined ? {} : { resources: given }) });
565
572
  }
566
573
  /**
567
574
  * The one machine a request keeps. Two creates of one request on two provider instances can both find no machine by
@@ -620,8 +627,10 @@ export class HostedProvider {
620
627
  const drift = attached.ok ? readBackDiffer({ ...spec, network: networkOfForm(formOf(spec.network)), user: this.#userOf(spec) }, attached.value.spec, ["user", "network", "gpu"]) : [];
621
628
  if (drift.length > 0)
622
629
  return this.#fail("exists", otherSpecWords(name, "was made", drift));
630
+ // What the vendor gave it, from this read of it running, as a fresh create answers it (#prepare): a retry, or
631
+ // another instance's computer adopted, is priced by the same figures.
623
632
  if (attached.ok)
624
- return ok({ id: attached.value.id, name: attached.value.name, ...(attached.value.notes ? { notes: attached.value.notes } : {}) });
633
+ return ok({ id: attached.value.id, name: attached.value.name, ...(attached.value.notes ? { notes: attached.value.notes } : {}), ...(machine.resources ? { resources: machine.resources } : {}) });
625
634
  if (attached.error.code === "aborted")
626
635
  return attached;
627
636
  // Its daemon is not up yet, or not yet as declared (a desktop whose display the first create is still
@@ -772,6 +781,8 @@ export class HostedProvider {
772
781
  AGENTRUN_INIT_ARGS: initFlags(init).join(" "),
773
782
  // A desktop's init gets its display as the exec path's start gives it: DISPLAY, which agentrun-dial passes on.
774
783
  ...(this.#desktop === undefined ? {} : { DISPLAY: this.#desktop.display }),
784
+ // The relay the machine reaches this server through: agentrun-dial's fetch and computerd attach both dial it.
785
+ ...(this.#attachEgress === undefined ? {} : { [ATTACH_EGRESS_ENV]: this.#attachEgress }),
775
786
  });
776
787
  }
777
788
  /** Deletes a machine create gives up on, then waits, under the caller's signal, until get answers none for it. */
@@ -876,6 +887,8 @@ export class HostedProvider {
876
887
  const running = await this.#running(ref, signal);
877
888
  if (!running.ok)
878
889
  return running;
890
+ if (running.value.resources !== undefined)
891
+ this.#given.set(ref.id, running.value.resources);
879
892
  const drift = this.#machineDrift(running.value, labels);
880
893
  if (drift.length > 0)
881
894
  return this.#fail("refused", `it did not match its spec: ${drift.join("; ")}`);
@@ -1107,7 +1120,8 @@ export class HostedProvider {
1107
1120
  if (left <= 0) {
1108
1121
  const dialed = this.#dialed();
1109
1122
  const to = "problem" in dialed ? "this server" : dialed.attach;
1110
- return this.#fail("timeout", `${ref.name} did not dial ${to} within ${seconds(createMs)}: the machine must reach that address, and run agentrun-dial (the box image's entrypoint while AGENTRUN_ATTACH_URL is set)`);
1123
+ const through = this.#attachEgress === undefined ? "" : ` through ${this.#attachEgress}`;
1124
+ return this.#fail("timeout", `${ref.name} did not dial ${to}${through} within ${seconds(createMs)}: the machine must reach that address, and run agentrun-dial (the box image's entrypoint while AGENTRUN_ATTACH_URL is set)`);
1111
1125
  }
1112
1126
  const polled = pause(Math.min(this.#startPollMs(), left), signal).then(() => false);
1113
1127
  reading ??= this.#dialRefused(ref.name, Math.min(requestMs, left), signal);
@@ -298,9 +298,24 @@ export interface ReadBackSpec {
298
298
  * back): 1.1.1.1:443, ..."). Recorded, never refused and never hidden. Absent when there is nothing to record.
299
299
  */
300
300
  export type ReadBackNotes = string[];
301
- /** What create returns: the computer's ref, and what its read-back recorded that does not refuse it. */
301
+ /**
302
+ * What a computer was given, as its vendor's own answer for it says (its get or create answer): the figures the vendor
303
+ * bills by. Each field is absent where the vendor's answer does not say it, never guessed from what was asked.
304
+ */
305
+ export interface ComputerResources {
306
+ cpus?: number;
307
+ memoryMb?: number;
308
+ /** Its disk, in GB as the vendor counts it. */
309
+ diskGb?: number;
310
+ gpu?: GpuSpec;
311
+ }
312
+ /**
313
+ * What create returns: the computer's ref, what its read-back recorded that does not refuse it, and what the vendor says
314
+ * it was given (`resources`), where the vendor's answer says it.
315
+ */
302
316
  export interface CreatedComputer extends ComputerRef {
303
317
  notes?: ReadBackNotes;
318
+ resources?: ComputerResources;
304
319
  }
305
320
  /** A computer attach found: its ref, and the spec read back from it, so a caller sees what it attached to (root, open). */
306
321
  export interface AttachedComputer extends ComputerRef {
@@ -309,12 +309,27 @@ export function createSurface(client, hello, { cwd } = {}) {
309
309
  // The default state of a later point step stays the last observation's (stateOf): a state this act returned was never seen.
310
310
  // A script may ask observe as options ({ image: true }); the tool's schema offers only true.
311
311
  const again = args.observe;
312
- // The window the act finished on: its app, else the app of the state it named, never the one in front.
313
- const target = app ?? (args.state ? appOfState.get(args.state) : undefined);
314
312
  if (again)
315
- done.after = await observe({ ...(typeof again === "object" ? again : {}), ...(target ? { app: target } : {}) }, signal);
313
+ done.after = await observeAfter(typeof again === "object" ? again : {}, app ?? (args.state ? appOfState.get(args.state) : undefined), signal);
316
314
  return done;
317
315
  }
316
+ /**
317
+ * The window an act finished on, by the daemons' rule for it (phoned's UiDriver.after): its app's (the act's app, else
318
+ * the app of the state it named), never the one in front while that app shows one; else, once the steps took it away
319
+ * (a press that opened another package's page), the window in front.
320
+ */
321
+ async function observeAfter(options, app, signal) {
322
+ if (!app)
323
+ return observe(options, signal);
324
+ try {
325
+ return await observe({ ...options, app }, signal);
326
+ }
327
+ catch (error) {
328
+ if (!(error instanceof SurfaceError) || error.kind !== "not_found")
329
+ throw error;
330
+ return observe(options, signal);
331
+ }
332
+ }
318
333
  async function readFile(path, encoding, signal) {
319
334
  const parts = [];
320
335
  let offset = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-computer",
3
- "version": "0.1.0-beta.49",
3
+ "version": "0.1.0-beta.50",
4
4
  "description": "The open platform's computer protocol: a daemon in every computer, and one provisioner per vendor, starting with Docker.",
5
5
  "keywords": [
6
6
  "agentrun",