ai-sdk-sandbox-gce 0.2.2 → 0.3.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # ai-sdk-sandbox-gce
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 4e7f6bc: The service makes the egress proxy forget the sandboxes whose machine no longer runs. A machine stopped or deleted outside the service, a Spot machine taken back, one stopped at `SANDBOX_MAX_RUN_HOURS` or from the console, left its credentials in the proxy's memory until the application stopped the sandbox or the proxy restarted. In the background of a creation or a resume, every `SANDBOX_RECONCILE_MINUTES` at most (10 by default, `0` for never), the service now compares what the proxy holds with the machines of the zone, and forgets each sandbox whose address no running machine holds, or another sandbox of the service holds now. A sandbox registered again meanwhile is kept, and so is one of another service sharing the proxy in the zone. The proxy lists its sandboxes at `GET /v1/sandboxes`, and `DELETE /v1/sandboxes/:name?serial=` only forgets the registration it listed; a proxy of an earlier version is left as it is: upgrade it with the service.
8
+ - 463a18e: BREAKING: on Cloud Run, the sandbox service refuses to start without `SANDBOX_SERVICE_TOKEN`. The token is the second lock beside Cloud Run's IAM: without it, a service deployed with `--allow-unauthenticated` by mistake would let anyone run commands in every sandbox. Set `SANDBOX_INSECURE_NO_TOKEN=true` to keep a service without a token; it then logs a warning at startup. Off Cloud Run, the token stays optional.
9
+
10
+ The service also logs a warning at startup when `SANDBOX_ALLOWED_HOSTS` holds `*`: every sandbox may then reach any host over HTTPS, and send its files there.
11
+
12
+ ### Patch Changes
13
+
14
+ - 6806a20: The client refuses a sandbox service URL in plain HTTP, but on the loopback (`localhost`, `127.0.0.1`, `[::1]`): every call carries the identity token and the service token, which a URL in `http://` would send in clear. A service on Cloud Run is always reached in HTTPS.
15
+ - ba16981: The agent of a sandbox gets a new token at each `stop()`. The token was derived from `SANDBOX_AGENT_SECRET` and the machine's name alone, so it stayed the same for the whole life of the sandbox, and for a sandbox deleted and made again under the same name. It now also covers a run drawn at random when the machine is made and each time the service stops it, kept beside the token in the instance metadata: a token read there once, by anyone allowed to read the project's machines, serves until the next stop. The agent reads its token as the machine boots, as before, so the sandbox image needs no rebuild. A machine made before keeps its token until its next stop. Stopping needs `compute.instances.setMetadata`, already in the service's role: without it, the machine keeps its token and the stop goes on, with a warning.
16
+ - d6c47a8: The egress proxy counts the bytes each sandbox sends out and receives, over every connection of its machine, refused ones included. It logs them when it forgets the sandbox (`box forgotten, having sent 12.3 MB out and received 450.0 MB`) and gives them, `sent` and `received`, for each sandbox at `GET /v1/sandboxes`. An allowed host is a way out for data: the count shows a sandbox that sent out far more than its task needs.
17
+ - e6503c5: The egress proxy only reaches global unicast IPv6 addresses (`2000::/3`), rather than every address outside a list of private ranges. IPv4-compatible addresses (`::169.254.169.254`), local-use NAT64 (`64:ff9b:1::/48`), Teredo (`2001::/32`), site-local (`fec0::/10`) and documentation addresses are refused, along with the private ranges refused already. None of them was reachable from a proxy on an IPv4-only network, as Google Cloud VPCs are by default. A dual-stack network could have reached them.
18
+ - 64cc3a4: The egress proxy caps the connections each sandbox holds open through it at once: 128 by default, `SANDBOX_PROXY_MAX_CONNECTIONS` to change it. One connection beyond the cap is cut, and the first one cut is logged. A single sandbox could otherwise take every socket of the proxy, and cut the network of all the others. The proxy's systemd unit in the README raises its open file limit to match (`LimitNOFILE=65536`): add the line to yours.
19
+ - ed2fe3d: The README spells out what the security model leaves to the deployment. An allowed host is a way out for the sandbox's files: keep `*` and wildcards on shared domains out of production. The agents' tokens sit in the machines' metadata, which `roles/viewer` and `roles/compute.viewer` read. A template is only ever made from a sandbox no agent ran in. Sandbox names must be random and checked against the user on the server. A machine stopped outside the service keeps its credentials in the proxy until the application stops it. Traffic inside the VPC is plain HTTP. The proxy's startup script and the sandbox image install Node.js and the Ops Agent from their signed apt repositories rather than by piping a script into a shell.
20
+
21
+ The proxy's startup script starts the proxy itself, once its package is the pinned one, and no longer lets systemd start it at boot. After a change of version, systemd started the previous one first: the service registered its sandboxes with it, and the proxy forgot them as the script restarted it on the new version.
22
+ - d6de560: The egress proxy reads the ClientHello of every `CONNECT` tunnel, and cuts the tunnel unless the TLS names the host it was opened to (SNI). A sandbox allowed one host behind a CDN, such as `registry.npmjs.org` behind Cloudflare, could open a tunnel to it and then name any other site served by the same CDN, a server of its own included. A tunnel to an IP address must name no server. A client that sends something other than TLS through a tunnel is cut too.
23
+
3
24
  ## 0.2.2
4
25
 
5
26
  ### Patch Changes
package/README.md CHANGED
@@ -105,6 +105,8 @@ gcloud dns response-policies rules create every-name --response-policy=sandboxes
105
105
  --dns-name="*." --local-data=name="*.",type=A,ttl=300,rrdatas=0.0.0.0
106
106
  ```
107
107
 
108
+ Keep the `service` subnetwork for the service alone: whatever else runs in it, a Cloud Run job or a machine, reaches the agents and the proxy's administration API like the service does.
109
+
108
110
  Every name then resolves to `0.0.0.0` in the sandboxes, which lose nothing by it: their commands reach hosts through the proxy, which resolves the names, and the metadata server is in their `/etc/hosts`. The proxy, on the same network, resolves names with public resolvers instead, which its startup script below sets up.
109
111
 
110
112
  ### 2. The egress proxy
@@ -141,8 +143,13 @@ for network in /run/systemd/network/*.network; do
141
143
  printf '[DHCPv4]\nUseDNS=false\n' > "/etc/systemd/network/$(basename "$network").d/no-dhcp-dns.conf"
142
144
  done
143
145
  systemctl restart systemd-networkd systemd-resolved
146
+ # Node.js and the Ops Agent from their signed apt repositories: no script piped into a shell.
147
+ install -m 0755 -d /etc/apt/keyrings
144
148
  if ! command -v npm >/dev/null; then
145
- curl -fsSL https://deb.nodesource.com/setup_24.x | bash -
149
+ curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key -o /etc/apt/keyrings/nodesource.asc
150
+ echo "deb [signed-by=/etc/apt/keyrings/nodesource.asc] https://deb.nodesource.com/node_24.x nodistro main" \
151
+ > /etc/apt/sources.list.d/nodesource.list
152
+ apt-get update
146
153
  apt-get install -y nodejs
147
154
  fi
148
155
  # Installed again whenever the pinned version changes: the proxy then restarts on it, below.
@@ -153,7 +160,11 @@ if ! npm ls --global ai-sdk-sandbox-gce@0.2.0 >/dev/null 2>&1; then
153
160
  fi
154
161
  # Its logs, the refusals among them, sent to Cloud Logging by the Ops Agent.
155
162
  if [ ! -d /opt/google-cloud-ops-agent ]; then
156
- curl -fsSL https://dl.google.com/cloudagents/add-google-cloud-ops-agent-repo.sh | bash -s -- --also-install
163
+ curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg -o /etc/apt/keyrings/google-cloud.asc
164
+ echo "deb [signed-by=/etc/apt/keyrings/google-cloud.asc] https://packages.cloud.google.com/apt google-cloud-ops-agent-bookworm-all main" \
165
+ > /etc/apt/sources.list.d/google-cloud-ops-agent.list
166
+ apt-get update
167
+ apt-get install -y google-cloud-ops-agent
157
168
  fi
158
169
  # Its token, read from Secret Manager as the machine's service account.
159
170
  cat > /usr/local/bin/ai-sdk-sandbox-proxy-token <<'SCRIPT'
@@ -178,6 +189,8 @@ Wants=network-online.target
178
189
  ExecStart=/bin/sh -c 'SANDBOX_PROXY_TOKEN=$(/usr/local/bin/ai-sdk-sandbox-proxy-token) exec ai-sdk-sandbox-gce proxy'
179
190
  Restart=always
180
191
  DynamicUser=yes
192
+ # Every sandbox holds up to SANDBOX_PROXY_MAX_CONNECTIONS (128) connections at once.
193
+ LimitNOFILE=65536
181
194
 
182
195
  [Install]
183
196
  WantedBy=multi-user.target
@@ -187,9 +200,9 @@ if ! cmp -s /tmp/ai-sdk-sandbox-proxy.service /etc/systemd/system/ai-sdk-sandbox
187
200
  systemctl daemon-reload
188
201
  restart=true
189
202
  fi
190
- systemctl enable ai-sdk-sandbox-proxy
191
- # Started by systemd at boot, before this script: restarted only when its package or its unit
192
- # changed, since a restart forgets the sandboxes registered meanwhile.
203
+ # Started here, once its package is the pinned one, and not by systemd at boot: the previous
204
+ # version would take the sandboxes the service registers meanwhile, and forget them as it restarts.
205
+ systemctl disable --quiet ai-sdk-sandbox-proxy
193
206
  if [ "$restart" = true ]; then
194
207
  systemctl restart ai-sdk-sandbox-proxy
195
208
  else
@@ -197,7 +210,7 @@ else
197
210
  fi
198
211
  ```
199
212
 
200
- Pin `ai-sdk-sandbox-gce` to the version your application depends on, here and in the two images below: every side checks that the others speak its protocol. To upgrade the proxy, change the version in the script, hand it to the machine again, and reboot it, or let the service start it with the next sandbox if it is stopped:
213
+ Pin `ai-sdk-sandbox-gce` to the version your application depends on, here and in the two images below: every side checks that the others speak its protocol. Every version published by the release workflow carries a [provenance attestation](https://docs.npmjs.com/generating-provenance-statements): `npm audit signatures` checks it, in a project that depends on the package. To upgrade the proxy, change the version in the script, hand it to the machine again, and reboot it, or let the service start it with the next sandbox if it is stopped:
201
214
 
202
215
  ```bash
203
216
  gcloud compute instances add-metadata sandbox-proxy --zone=$ZONE \
@@ -226,7 +239,10 @@ apt-get update
226
239
  apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
227
240
 
228
241
  # Node.js, the agent, and pnpm: the Claude Code and Codex bridges install their dependencies with it.
229
- curl -fsSL https://deb.nodesource.com/setup_24.x | bash -
242
+ curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key -o /etc/apt/keyrings/nodesource.asc
243
+ echo "deb [signed-by=/etc/apt/keyrings/nodesource.asc] https://deb.nodesource.com/node_24.x nodistro main" \
244
+ > /etc/apt/sources.list.d/nodesource.list
245
+ apt-get update
230
246
  apt-get install -y nodejs
231
247
  npm install --global ai-sdk-sandbox-gce@0.2.0 pnpm@10
232
248
 
@@ -317,7 +333,7 @@ What these settings are for:
317
333
  - `--network`, `--subnet`, `--vpc-egress`: Direct VPC egress, so that the service reaches the agents and the proxy on their internal addresses.
318
334
  - `sandboxService`: create, stop, start and delete the machines, save a template as an image, start and stop the proxy; nothing outside the names of the condition. A missing permission shows in `pnpm test:e2e`.
319
335
  - `SANDBOX_PROXY_INSTANCE`: the proxy only runs while a sandbox does. `SANDBOX_MAX_RUNNING`: the machines running at once, a cap on the bill. `SANDBOX_MAX_RUN_HOURS`: Compute Engine stops a machine after so long, whatever happens.
320
- - `SANDBOX_SERVICE_TOKEN`: a second lock beside Cloud Run's IAM; the client hands it over as `serviceToken`.
336
+ - `SANDBOX_SERVICE_TOKEN`: a second lock beside Cloud Run's IAM, should the service ever be deployed open; the client hands it over as `serviceToken`. The service refuses to start on Cloud Run without it, unless `SANDBOX_INSECURE_NO_TOKEN=true`.
321
337
  - `--min-instances=0`: no instance and no bill while no call comes; the sandboxes run on without the service.
322
338
  - `--timeout=3600`: the longest a request lasts, so the longest a bridge WebSocket lasts. The harness reconnects beyond it.
323
339
  - `--concurrency=1000`: every open bridge holds a request.
@@ -331,7 +347,9 @@ gcloud run services add-iam-policy-binding sandboxes --region=$REGION \
331
347
  --member=serviceAccount:my-app@$PROJECT.iam.gserviceaccount.com --role=roles/run.invoker
332
348
  ```
333
349
 
334
- Anyone with that role and the service token can run commands in every sandbox of the service: grant it to your application, not to people who only need to read logs, and hand the token to the client as `serviceToken` (`gcloud secrets versions access latest --secret=sandbox-service-token`). Read the service's URL with `gcloud run services describe sandboxes --region=$REGION --format='value(status.url)'`; the examples below read it from `GCE_SANDBOX_URL`.
350
+ Anyone with that role and the service token can run commands in every sandbox of the service: grant it to your application, not to people who only need to read logs, and hand the token to the client as `serviceToken` (`gcloud secrets versions access latest --secret=sandbox-service-token`). Each agent's token sits in its machine's metadata, which anyone allowed `compute.instances.get` on the project reads (`roles/viewer`, `roles/compute.viewer`): with a foothold in the `service` subnetwork as well, they run commands in that sandbox as root, until the sandbox is next stopped, which draws it a new token. Grant those roles sparingly, and keep the subnetwork to the service alone.
351
+
352
+ Read the service's URL with `gcloud run services describe sandboxes --region=$REGION --format='value(status.url)'`; the examples below read it from `GCE_SANDBOX_URL`.
335
353
 
336
354
  ## Installation
337
355
 
@@ -400,6 +418,8 @@ A harness bootstraps itself in the sandbox before its first turn: Claude Code in
400
418
 
401
419
  The image is named after the template's id and a digest of this package's version and the base image, a family resolved to its latest image: `ai-sdk-harness-template-<digest>-<base>`. After a new sandbox image, or a new version of the package, the first sandbox makes the template again. Delete the old images (label `ai-sdk-sandbox=template`) now and then: each costs its storage.
402
420
 
421
+ A template is made from a sandbox no agent ever ran in: the client's throwaway one, where only `setup` and the harness's own installation run. Never save a sandbox an agent worked in as a template, through the API or otherwise: whatever the agent left on its disk, the `agent` service of the machine included, would start in every later sandbox.
422
+
403
423
  Making a template takes a few minutes: the machine boots, the harness installs, Compute Engine saves the disk, and the first sandbox on a new image waits a minute more while Compute Engine spreads it. Make it when you deploy, rather than in the first user's session, with a script that creates a sandbox from the agent's template and deletes it:
404
424
 
405
425
  ```ts title="make-template.ts"
@@ -465,25 +485,25 @@ Git over HTTPS goes the same way: the agent hands every command a `url.<proxy>/h
465
485
 
466
486
  The service routes `ANTHROPIC_BASE_URL` (Claude Code) and `OPENAI_BASE_URL` (Codex) by default; add others with `baseUrls`. With a subscription, the refresh token never leaves your application: only the short-lived access token reaches the proxy.
467
487
 
468
- | Protection | What it prevents |
469
- | ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------- |
470
- | **Brokering is always on** | A harness falling back to forwarding the real credential into the sandbox |
471
- | **Commands carrying a credential refused** | A real credential entering the sandbox anyway: the service asks the proxy, which holds them, before running a command |
472
- | **One host per credential** | The credential reaching another host: it is only put in requests to the host it is for |
473
- | **HTTPS only** | The credential travelling in clear outside the VPC: a base URL in plain HTTP is refused |
474
- | **No private address** | The sandbox reaching the proxy's metadata server, the service or the rest of the VPC through the proxy: see [Network](#network) |
475
- | **No service account** | A Google credential in the machine: its metadata server has no token to give |
476
- | **Forgotten when done** | The credential outliving its use: `release()`, `stop()` and `destroy()` drop it from the proxy's memory, and a proxy restart drops all |
488
+ | Protection | What it prevents |
489
+ | ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
490
+ | **Brokering is always on** | A harness falling back to forwarding the real credential into the sandbox |
491
+ | **Commands carrying a credential refused** | A real credential entering the sandbox anyway, on a command line or in a variable: the service asks the proxy, which holds them, before running a command. The standard input, and so the files written, are not checked: a guard against a mistake, not a control |
492
+ | **One host per credential** | The credential reaching another host: it is only put in requests to the host it is for |
493
+ | **HTTPS only** | The credential travelling in clear outside the VPC: a base URL in plain HTTP is refused |
494
+ | **No private address** | The sandbox reaching the proxy's metadata server, the service or the rest of the VPC through the proxy: see [Network](#network) |
495
+ | **No service account** | A Google credential in the machine: its metadata server has no token to give |
496
+ | **Forgotten when done** | The credential outliving its use: `release()`, `stop()` and `destroy()` drop it from the proxy's memory, and a proxy restart drops all |
477
497
 
478
498
  ## Network
479
499
 
480
500
  The machine has no external address, and the VPC firewall, applied outside the guest, only lets it reach the proxy. Everything goes through it:
481
501
 
482
- - `HTTPS_PROXY` points at the proxy: it tunnels a `CONNECT` to port 443 of an allowed host, end to end encrypted, and refuses anything else.
502
+ - `HTTPS_PROXY` points at the proxy: it tunnels a `CONNECT` to port 443 of an allowed host, end to end encrypted, and refuses anything else. The tunnel only carries TLS that names that host (SNI): a client cannot open it to an allowed host behind a CDN, then name another site of the same CDN. The proxy reads nothing past the ClientHello, an HTTP `Host` header inside the TLS included.
483
503
  - The base URLs go to the proxy too, as above.
484
504
  - `HTTP_PROXY` points at the proxy as well: plain HTTP to an allowed host, as Debian's package mirrors serve, is passed on as it is, no credential put in. Anything else in plain HTTP is refused.
485
505
  - `NO_PROXY` covers the machine itself, the proxy and the private ranges Docker puts its containers in. A container reached by its Compose service name is not covered: add the names to `NO_PROXY` in the Compose file.
486
- - The proxy never connects to a private address, however it is named or allowed: loopback, link-local (its own metadata server), the private ranges of the VPC. It checks the address a name resolves to, at the moment it connects, an IPv6 address carrying a private IPv4 one included.
506
+ - The proxy never connects to a private address, however it is named or allowed: loopback, link-local (its own metadata server), the private ranges of the VPC. It checks the address a name resolves to, at the moment it connects. In IPv6, it only reaches global unicast addresses (`2000::/3`), never one carrying a private IPv4 address (NAT64, 6to4, IPv4-mapped) nor a Teredo one.
487
507
 
488
508
  `allowedHosts` adds hosts for one sandbox, on top of the service's `SANDBOX_ALLOWED_HOSTS`. `*.example.com` covers the subdomains of `example.com`. `setNetworkPolicy` replaces the sandbox's own hosts: `allow-all` lets it reach any host over HTTPS, `deny-all` none but the service's and the base URLs'. CIDR rules are not supported.
489
509
 
@@ -530,46 +550,49 @@ Docker pulls images from Docker Hub through the proxy: allow `registry-1.docker.
530
550
 
531
551
  ### The service (`serve`)
532
552
 
533
- | Variable | Default | Description |
534
- | ------------------------- | ---------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
535
- | `SANDBOX_ZONE` | required | The zone of the machines |
536
- | `SANDBOX_IMAGE` | required | The sandbox image: a name, `family/<family>`, or `projects/<project>/global/images/…` |
537
- | `SANDBOX_IMAGES` | none | Other images callers may pick by name, as `NAME=image` pairs: `python=family/ai-sdk-sandbox-python` |
538
- | `SANDBOX_AGENT_SECRET` | required | 32 characters at least: the agents' tokens are derived from it. Keep it in Secret Manager |
539
- | `SANDBOX_PROXY_URL` | required | The proxy, as the machines reach it: `http://10.8.16.2:3128` |
540
- | `SANDBOX_PROXY_ADMIN_URL` | required | Its administration API: `http://10.8.16.2:3129` |
541
- | `SANDBOX_PROXY_TOKEN` | required | The proxy's token |
542
- | `SANDBOX_PROJECT` | the service's project | The project of the machines |
543
- | `SANDBOX_NETWORK` | the default network | The machines' VPC network |
544
- | `SANDBOX_SUBNETWORK` | none | Their subnetwork: `regions/<region>/subnetworks/<name>` |
545
- | `SANDBOX_NETWORK_TAGS` | `ai-sdk-sandbox` | Their network tags, which the firewall rules apply to |
546
- | `SANDBOX_MACHINE_TYPE` | `e2-standard-4` | Their machine type, a custom one included: `e2-custom-4-8192` |
547
- | `SANDBOX_DISK_GB` | `20` | The size of their disk |
548
- | `SANDBOX_DISK_TYPE` | `pd-balanced` | Its type |
549
- | `SANDBOX_SPOT` | `false` | `true` for Spot machines: cheaper, stopped when Compute Engine takes them back, resumable after |
550
- | `SANDBOX_SPOT_FALLBACK` | `true` | With Spot, a machine the zone has no Spot capacity for is created or started as a standard one, billed as such; `false` fails instead |
551
- | `SANDBOX_INSTANCE_PREFIX` | `sbx-` | Put before a sandbox's name to make its machine's, 8 characters at most |
552
- | `SANDBOX_AGENT_PORT` | `8100` | The port of the agents |
553
- | `SANDBOX_START_TIMEOUT` | `300` | Seconds a machine has to boot and its agent to answer |
554
- | `SANDBOX_MAX_RUNNING` | none | The most sandboxes running at once: a creation or a resume beyond it is answered with a 429. Counted at each call, so two at the same instant may both pass |
555
- | `SANDBOX_MAX_RUN_HOURS` | none | The longest a machine runs at a time: Compute Engine stops it then (`maxRunDuration`), disk kept, whatever the service or the application do. 30 s at least |
556
- | `SANDBOX_PROXY_INSTANCE` | none | The egress proxy's machine, in the sandboxes' zone: started with the first sandbox that runs, stopped once none does. Always on without it |
557
- | `SANDBOX_ALLOWED_HOSTS` | none | Hosts every sandbox may reach over HTTPS, comma-separated; `*.domain` allowed |
558
- | `SANDBOX_BASE_URLS` | `ANTHROPIC_BASE_URL=https://api.anthropic.com,OPENAI_BASE_URL=https://api.openai.com/v1` | Base URL variables routed through the proxy, as `NAME=url` pairs |
559
- | `SANDBOX_SERVICE_TOKEN` | none | A secret every call must carry, beside Cloud Run's IAM |
560
- | `COMPUTE_AUTH` | `metadata` on Cloud Run, `gcloud` elsewhere | How the service gets its access tokens for the Compute Engine API |
561
- | `PORT`, `HOST` | `8080`, `0.0.0.0` on Cloud Run and `127.0.0.1` elsewhere | Where the service listens |
562
- | `LOG_FORMAT` | `json` on Cloud Run, `text` elsewhere | JSON lines for Cloud Logging, or plain text |
553
+ | Variable | Default | Description |
554
+ | --------------------------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
555
+ | `SANDBOX_ZONE` | required | The zone of the machines |
556
+ | `SANDBOX_IMAGE` | required | The sandbox image: a name, `family/<family>`, or `projects/<project>/global/images/…` |
557
+ | `SANDBOX_IMAGES` | none | Other images callers may pick by name, as `NAME=image` pairs: `python=family/ai-sdk-sandbox-python` |
558
+ | `SANDBOX_AGENT_SECRET` | required | 32 characters at least: the agents' tokens are derived from it. Keep it in Secret Manager |
559
+ | `SANDBOX_PROXY_URL` | required | The proxy, as the machines reach it: `http://10.8.16.2:3128` |
560
+ | `SANDBOX_PROXY_ADMIN_URL` | required | Its administration API: `http://10.8.16.2:3129` |
561
+ | `SANDBOX_PROXY_TOKEN` | required | The proxy's token |
562
+ | `SANDBOX_PROJECT` | the service's project | The project of the machines |
563
+ | `SANDBOX_NETWORK` | the default network | The machines' VPC network |
564
+ | `SANDBOX_SUBNETWORK` | none | Their subnetwork: `regions/<region>/subnetworks/<name>` |
565
+ | `SANDBOX_NETWORK_TAGS` | `ai-sdk-sandbox` | Their network tags, which the firewall rules apply to |
566
+ | `SANDBOX_MACHINE_TYPE` | `e2-standard-4` | Their machine type, a custom one included: `e2-custom-4-8192` |
567
+ | `SANDBOX_DISK_GB` | `20` | The size of their disk |
568
+ | `SANDBOX_DISK_TYPE` | `pd-balanced` | Its type |
569
+ | `SANDBOX_SPOT` | `false` | `true` for Spot machines: cheaper, stopped when Compute Engine takes them back, resumable after |
570
+ | `SANDBOX_SPOT_FALLBACK` | `true` | With Spot, a machine the zone has no Spot capacity for is created or started as a standard one, billed as such; `false` fails instead |
571
+ | `SANDBOX_INSTANCE_PREFIX` | `sbx-` | Put before a sandbox's name to make its machine's, 8 characters at most |
572
+ | `SANDBOX_AGENT_PORT` | `8100` | The port of the agents |
573
+ | `SANDBOX_START_TIMEOUT` | `300` | Seconds a machine has to boot and its agent to answer |
574
+ | `SANDBOX_MAX_RUNNING` | none | The most sandboxes running at once: a creation or a resume beyond it is answered with a 429. Counted at each call, so two at the same instant may both pass |
575
+ | `SANDBOX_MAX_RUN_HOURS` | none | The longest a machine runs at a time: Compute Engine stops it then (`maxRunDuration`), disk kept, whatever the service or the application do. 30 s at least |
576
+ | `SANDBOX_RECONCILE_MINUTES` | `10` | How often, at most, the service makes the proxy forget the sandboxes whose machine no longer runs, in the background of a creation or a resume. A sandbox of another service sharing the proxy in the zone is left alone, under another `SANDBOX_INSTANCE_PREFIX`. `0` for never: a proxy shared with a service of another zone or project |
577
+ | `SANDBOX_PROXY_INSTANCE` | none | The egress proxy's machine, in the sandboxes' zone: started with the first sandbox that runs, stopped once none does. Always on without it |
578
+ | `SANDBOX_ALLOWED_HOSTS` | none | Hosts every sandbox may reach over HTTPS, comma-separated; `*.domain` allowed. `*`, any host, is logged as a warning at startup |
579
+ | `SANDBOX_BASE_URLS` | `ANTHROPIC_BASE_URL=https://api.anthropic.com,OPENAI_BASE_URL=https://api.openai.com/v1` | Base URL variables routed through the proxy, as `NAME=url` pairs |
580
+ | `SANDBOX_SERVICE_TOKEN` | required on Cloud Run | A secret every call must carry, beside Cloud Run's IAM |
581
+ | `SANDBOX_INSECURE_NO_TOKEN` | `false` | `true` to run on Cloud Run without `SANDBOX_SERVICE_TOKEN`, its IAM the only lock |
582
+ | `COMPUTE_AUTH` | `metadata` on Cloud Run, `gcloud` elsewhere | How the service gets its access tokens for the Compute Engine API |
583
+ | `PORT`, `HOST` | `8080`, `0.0.0.0` on Cloud Run and `127.0.0.1` elsewhere | Where the service listens |
584
+ | `LOG_FORMAT` | `json` on Cloud Run, `text` elsewhere | JSON lines for Cloud Logging, or plain text |
563
585
 
564
586
  ### The proxy (`proxy`)
565
587
 
566
- | Variable | Default | Description |
567
- | ------------------------------- | --------- | ----------------------------------------------------------------------------------- |
568
- | `SANDBOX_PROXY_TOKEN` | required | The token the service proves itself with, 16 characters at least |
569
- | `SANDBOX_PROXY_PORT` | `3128` | The port the sandboxes reach |
570
- | `SANDBOX_PROXY_ADMIN_PORT` | `3129` | The port of the administration API |
571
- | `SANDBOX_ALLOW_PRIVATE_NETWORK` | `false` | For tests only: lets the sandboxes reach private addresses and plain HTTP base URLs |
572
- | `HOST`, `LOG_FORMAT` | `0.0.0.0` | Where it listens; `text` for plain logs |
588
+ | Variable | Default | Description |
589
+ | ------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------ |
590
+ | `SANDBOX_PROXY_TOKEN` | required | The token the service proves itself with, 16 characters at least |
591
+ | `SANDBOX_PROXY_PORT` | `3128` | The port the sandboxes reach |
592
+ | `SANDBOX_PROXY_ADMIN_PORT` | `3129` | The port of the administration API |
593
+ | `SANDBOX_ALLOW_PRIVATE_NETWORK` | `false` | For tests only: lets the sandboxes reach private addresses and plain HTTP base URLs |
594
+ | `SANDBOX_PROXY_MAX_CONNECTIONS` | `128` | The most connections a sandbox holds open through the proxy at once: one more is cut, and the first one cut logged |
595
+ | `HOST`, `LOG_FORMAT` | `0.0.0.0` | Where it listens; `text` for plain logs |
573
596
 
574
597
  ### The agent (`agent`)
575
598
 
@@ -605,10 +628,14 @@ To keep the bill down: stop idle sandboxes early, delete finished ones, delete o
605
628
  - **A virtual machine per sandbox**: its kernel is its own; the firewall rules apply outside it, and no rule written inside the guest weakens them.
606
629
  - **Nothing leaves the machine but through the proxy**, which only opens allowed hosts and the base URLs' APIs, and never a private address, once DNS is closed as [the network](#1-the-network) shows.
607
630
  - **No service account, no external address**: the machine holds no Google credential, and nothing on the internet reaches it.
608
- - **The agents answer the service alone**: the firewall lets only the service's subnetwork reach their port, and every call carries a token derived from `SANDBOX_AGENT_SECRET` for that machine. A machine only ever learns its own token, from its metadata.
609
- - **The sandbox's user has `sudo`, and Docker**: inside the machine, the agent's code can do anything. The machine is the boundary, not the user.
631
+ - **The agents answer the service alone**: the firewall lets only the service's subnetwork reach their port, and every call carries a token derived from `SANDBOX_AGENT_SECRET` for that machine and its run, drawn anew when the machine is made and at each `stop()`: a token read once serves until the next stop. A machine only ever learns its own token, from its metadata, which whoever may read the project's machines reads too: see [Who may call it](#5-who-may-call-it).
632
+ - **Inside the VPC, traffic is plain HTTP**: the service's calls to the agents and to the proxy's administration API, real credentials included, and the sandboxes' requests to the base URL routes. Google Cloud encrypts traffic between its hosts and lets no machine listen to another's; nothing of the package adds TLS on top.
633
+ - **The sandbox's user has `sudo`, and Docker**: inside the machine, the agent's code can do anything. The machine is the boundary, not the user. What the agent changes on the disk, the machine's own `agent` service included, survives a stop: never hand a sandbox to another user, and never save one an agent worked in as a template.
634
+ - **An allowed host is a way out for data**: the allow list says where the sandbox's requests may go, not what they carry. An agent led astray by a prompt injection may push the sandbox's files to `github.com`, or publish them to a registry, with credentials of its own. Allow only the hosts a task needs; keep `*` and wildcards on shared domains (`*.googleapis.com`, `*.amazonaws.com`, `*.githubusercontent.com`, `*.cloudfront.net`) out of production, since anyone can own a bucket or a site under them. The service logs a warning when `SANDBOX_ALLOWED_HOSTS` holds `*`. The proxy logs the bytes each sandbox sent out and received when it forgets it (`box forgotten, having sent 12.3 MB out and received 450.0 MB`), and gives them for every sandbox it holds at `GET /v1/sandboxes`: an alert on that log line catches a sandbox that sent out far more than its task needs.
635
+ - **A credential goes to every request its transformation matches**: the harnesses' own transformations match the placeholder the sandbox sends, so only a request carrying it gets the real value. A transformation of yours that names a host alone puts the credential in any request to that host. Cap the credential at the provider as well: a budget, the narrowest scope a token takes.
610
636
  - **The proxy holds the credentials of every running sandbox**, in memory. Keep it a machine of its own, with nothing else on it, a service account that may only read its token and write logs, and its administration port open to the service alone.
611
- - **The service trusts its callers**: anyone granted `roles/run.invoker` can run commands in any sandbox. Never deploy it with `--allow-unauthenticated`; add `SANDBOX_SERVICE_TOKEN` as a second lock.
637
+ - **The service trusts its callers**: anyone granted `roles/run.invoker` can run commands in any sandbox. It has no notion of a user: your application decides which sandbox a user reaches. Name sandboxes after a random id, kept beside the user's session on the server, never after anything a user can guess or send. Never deploy it with `--allow-unauthenticated`; `SANDBOX_SERVICE_TOKEN` is the second lock, required on Cloud Run.
638
+ - **A machine stopped outside the service keeps its credentials in the proxy for a while**: a Spot machine taken back, one stopped at `SANDBOX_MAX_RUN_HOURS` or from the console. The service makes the proxy forget them once it sees the machine no longer runs, in the background of a creation or a resume, every `SANDBOX_RECONCILE_MINUTES` at most; the application stopping or deleting the sandbox does so at once, and so does the proxy restarting. With `SANDBOX_PROXY_INSTANCE`, the proxy keeps running meanwhile. Stop idle sandboxes from the application even when their machine already stopped.
612
639
  - **Disks and template images hold the sandbox's files**: the agent's work and its transcript. They stay in your project; delete them with the sandbox.
613
640
  - **Metadata**: a machine reads its own metadata, project metadata included. Keep secrets out of the project's metadata, and SSH keys too (the service blocks project SSH keys on the machines).
614
641
 
@@ -616,22 +643,22 @@ To keep the bill down: stop idle sandboxes early, delete finished ones, delete o
616
643
 
617
644
  What the sandbox does, or does not, against the essential risks of running an agent's code: ✅ covered, ⚠️ partly or with care, ❌ not covered. The same table describes every sandbox package of this repository.
618
645
 
619
- | Control | Status | How |
620
- | ------------------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------------------- |
621
- | Isolation boundary | ✅ | A Compute Engine virtual machine per sandbox |
622
- | Nothing of the host by default | ✅ | The machine sees its image and its disk, nothing of the service or the proxy |
623
- | Writes to the host | ✅ | No host: files go through the agent |
624
- | Privileges | ⚠️ | The sandbox's user has `sudo` and Docker: root in the machine, and only in it |
625
- | Docker and Compose | ✅ | Docker Engine and Compose in the image, pulled through the proxy |
626
- | Outbound allow list | ✅ | `allowedHosts` and `setNetworkPolicy()`, applied by the proxy; the VPC firewall closes all else |
627
- | Private networks and metadata | ⚠️ | Refused by the proxy after DNS resolution; the machine's own metadata server stays readable, with no token in it |
628
- | Inbound ports | ✅ | Through the service only, behind Cloud Run's IAM, `SANDBOX_SERVICE_TOKEN` and the agent token |
629
- | Credentials out of the sandbox | ✅ | The real value only lives in the proxy's memory |
630
- | Credential scope | ⚠️ | Only to its API's host, in the headers its transformation names; echoed back in a body, not taken out |
631
- | Environment | ✅ | The commands never see the agent's environment |
632
- | Resource limits | ✅ | The machine type: vCPUs, memory and disk of its own |
633
- | Lifetime limits | ✅ | `SANDBOX_MAX_RUN_HOURS`: Compute Engine stops a machine after so long, whatever the service or the application do; `stop()` sooner |
634
- | Teardown | ✅ | `destroy()` deletes the machine and its disk; the proxy forgets its credentials |
646
+ | Control | Status | How |
647
+ | ------------------------------ | ------ | -------------------------------------------------------------------------------------------------------------------------------------- |
648
+ | Isolation boundary | ✅ | A Compute Engine virtual machine per sandbox |
649
+ | Nothing of the host by default | ✅ | The machine sees its image and its disk, nothing of the service or the proxy |
650
+ | Writes to the host | ✅ | No host: files go through the agent |
651
+ | Privileges | ⚠️ | The sandbox's user has `sudo` and Docker: root in the machine, and only in it |
652
+ | Docker and Compose | ✅ | Docker Engine and Compose in the image, pulled through the proxy |
653
+ | Outbound allow list | ⚠️ | `allowedHosts` and `setNetworkPolicy()`, applied by the proxy; the VPC firewall closes all else. An allowed host is a way out for data |
654
+ | Private networks and metadata | ⚠️ | Refused by the proxy after DNS resolution; the machine's own metadata server stays readable, with no token in it |
655
+ | Inbound ports | ✅ | Through the service only, behind Cloud Run's IAM, `SANDBOX_SERVICE_TOKEN` and the agent token |
656
+ | Credentials out of the sandbox | ✅ | The real value only lives in the proxy's memory |
657
+ | Credential scope | ⚠️ | Only to its API's host, in the headers its transformation names; echoed back in a body, not taken out |
658
+ | Environment | ✅ | The commands never see the agent's environment |
659
+ | Resource limits | ✅ | The machine type: vCPUs, memory and disk of its own |
660
+ | Lifetime limits | ✅ | `SANDBOX_MAX_RUN_HOURS`: Compute Engine stops a machine after so long, whatever the service or the application do; `stop()` sooner |
661
+ | Teardown | ✅ | `destroy()` deletes the machine and its disk; the proxy forgets its credentials |
635
662
 
636
663
  ## Before production
637
664
 
@@ -648,7 +675,9 @@ The steps above set up the network, the proxy and the service as they ran on Goo
648
675
 
649
676
  - [ ] **Set a budget alert** on the project, and keep the region's vCPU quota low: unlike an alert, a quota stops the spending.
650
677
  - [ ] **Restrict the service's ingress** when your application runs on Google Cloud: `gcloud run services update sandboxes --region=$REGION --ingress=internal`, the application then reaching it through the VPC (Direct VPC egress with `--vpc-egress=all-traffic`). Called from outside Google Cloud, the service stays public, guarded by IAM and its token.
651
- - [ ] **Authenticate your users** before anything reaches the service: whoever can call your application runs commands in its sandboxes. With Google accounts, a sign-in limited to your domain (Google OAuth, the `hd` claim checked on the server); on Google Cloud, [Identity-Aware Proxy](https://cloud.google.com/iap/docs/enabling-cloud-run) in front of the application. Either way, `roles/run.invoker` on the service goes to the application's service account alone.
678
+ - [ ] **Review the allowed hosts**: no `*`, no wildcard on a shared domain, a package registry only where the agent installs packages. Each is a way out for the sandbox's files.
679
+ - [ ] **Grant `roles/viewer` and `roles/compute.viewer` sparingly**: they read the agents' tokens in the machines' metadata.
680
+ - [ ] **Authenticate your users** before anything reaches the service: whoever can call your application runs commands in its sandboxes. With Google accounts, a sign-in limited to your domain (Google OAuth, the `hd` claim checked on the server); on Google Cloud, [Identity-Aware Proxy](https://cloud.google.com/iap/docs/enabling-cloud-run) in front of the application. Either way, `roles/run.invoker` on the service goes to the application's service account alone, and the application checks on the server, at every call, that the sandbox belongs to the user.
652
681
 
653
682
  ## Limitations
654
683
 
@@ -8,6 +8,8 @@ const encoder = new TextEncoder();
8
8
  const templatePath = (id, image) => image === undefined
9
9
  ? `v1/templates/${id}`
10
10
  : `v1/templates/${id}?image=${encodeURIComponent(image)}`;
11
+ /** A service reached in plain HTTP on this machine: a local run, nothing in clear on a network. */
12
+ const isLocal = ({ protocol, hostname }) => protocol === 'http:' && ['127.0.0.1', '[::1]', 'localhost'].includes(hostname);
11
13
  /** Statuses of a call worth sending again: Cloud Run's front end, or an instance starting. */
12
14
  const TRANSIENT_STATUSES = new Set([429, 500, 502, 503, 504]);
13
15
  /** How long to wait before each new attempt of a call that may be sent again. */
@@ -46,6 +48,9 @@ export class SandboxServiceClient {
46
48
  */
47
49
  constructor(url, { token, serviceToken } = {}) {
48
50
  this.base = new URL(url.endsWith('/') ? url : `${url}/`);
51
+ if (this.base.protocol !== 'https:' && !isLocal(this.base)) {
52
+ throw new Error(`The sandbox service's URL must be HTTPS, but on the loopback: ${this.base.origin} would carry the identity token and the service token in clear.`);
53
+ }
49
54
  this.token = token;
50
55
  this.serviceToken = serviceToken;
51
56
  }
@@ -9,7 +9,10 @@
9
9
  * - `POST` and `PUT /v1/sandboxes/:name/transformations`: `{ transformations }`, added or replaced;
10
10
  * - `POST /v1/sandboxes/:name/screen`: `{ texts }`, answered `{ refused }`, whether one of them holds
11
11
  * a credential the proxy keeps for the sandbox;
12
- * - `DELETE /v1/sandboxes/:name`: forgets the sandbox and its credentials.
12
+ * - `GET /v1/sandboxes`: `{ sandboxes }`, a {@link ProxySandbox} each, what the proxy holds and
13
+ * the bytes each moved;
14
+ * - `DELETE /v1/sandboxes/:name`: forgets the sandbox and its credentials; with `?serial=`, only
15
+ * when that registration is still the sandbox's, not one made since.
13
16
  */
14
17
  /** A sandbox, as the proxy knows it. */
15
18
  export interface ProxyRegistration {
@@ -20,6 +23,17 @@ export interface ProxyRegistration {
20
23
  /** Base URL variables and where they lead: their hosts are always reachable through a route. */
21
24
  baseUrls: Readonly<Record<string, string>>;
22
25
  }
26
+ /** A sandbox the proxy holds, as it lists them. */
27
+ export interface ProxySandbox {
28
+ name: string;
29
+ /** The address of its machine, normalized. */
30
+ address: string;
31
+ /** What tells its registration from the next one: another at each registration. */
32
+ serial: number;
33
+ /** The bytes it sent out through the proxy, and received back, since it was first registered. */
34
+ sent: number;
35
+ received: number;
36
+ }
23
37
  /** The port the proxy serves the sandboxes on. */
24
38
  export declare const DEFAULT_PROXY_PORT = 3128;
25
39
  /** The port of its administration API. */
@@ -9,7 +9,10 @@
9
9
  * - `POST` and `PUT /v1/sandboxes/:name/transformations`: `{ transformations }`, added or replaced;
10
10
  * - `POST /v1/sandboxes/:name/screen`: `{ texts }`, answered `{ refused }`, whether one of them holds
11
11
  * a credential the proxy keeps for the sandbox;
12
- * - `DELETE /v1/sandboxes/:name`: forgets the sandbox and its credentials.
12
+ * - `GET /v1/sandboxes`: `{ sandboxes }`, a {@link ProxySandbox} each, what the proxy holds and
13
+ * the bytes each moved;
14
+ * - `DELETE /v1/sandboxes/:name`: forgets the sandbox and its credentials; with `?serial=`, only
15
+ * when that registration is still the sandbox's, not one made since.
13
16
  */
14
17
  /** The port the proxy serves the sandboxes on. */
15
18
  export const DEFAULT_PROXY_PORT = 3128;
@@ -5,9 +5,19 @@ import { bearer, fail, NO_CONTENT, sameSecret, send } from '../common/http-reply
5
5
  import { PACKAGE_VERSION } from '../common/package-version.js';
6
6
  import { PROTOCOL_HEADER, PROTOCOL_VERSION } from '../protocol/version.js';
7
7
  const SANDBOX = /^\/v1\/sandboxes\/([a-z0-9-]+)(\/[a-z]+)?$/;
8
- /** What each route does to the registry, given the sandbox's name and the request's body. */
8
+ /** `?serial=`, the registration a removal is meant for. */
9
+ function serialOf(query) {
10
+ const raw = query.get('serial');
11
+ if (raw === null)
12
+ return undefined;
13
+ const serial = Number(raw);
14
+ if (!Number.isSafeInteger(serial))
15
+ throw new HttpError(400, '`serial` must be an integer.');
16
+ return serial;
17
+ }
18
+ /** What each route does to the registry. */
9
19
  const ROUTES = {
10
- 'PUT ': (registry, name, body) => {
20
+ 'PUT ': (registry, { name, body }) => {
11
21
  registry.register(name, {
12
22
  address: requiredString(body, 'address'),
13
23
  allowedHosts: stringList(body, 'allowedHosts') ?? [],
@@ -15,34 +25,38 @@ const ROUTES = {
15
25
  });
16
26
  return NO_CONTENT;
17
27
  },
18
- 'DELETE ': (registry, name) => {
19
- registry.remove(name);
28
+ 'DELETE ': (registry, { name, query }) => {
29
+ registry.remove(name, serialOf(query));
20
30
  return NO_CONTENT;
21
31
  },
22
- 'PUT /network': (registry, name, body) => {
32
+ 'PUT /network': (registry, { name, body }) => {
23
33
  registry.setAllowedHosts(name, stringList(body, 'allowedHosts') ?? []);
24
34
  return NO_CONTENT;
25
35
  },
26
- 'POST /transformations': (registry, name, body) => {
36
+ 'POST /transformations': (registry, { name, body }) => {
27
37
  registry.addTransformations(name, transformationList(body));
28
38
  return NO_CONTENT;
29
39
  },
30
- 'PUT /transformations': (registry, name, body) => {
40
+ 'PUT /transformations': (registry, { name, body }) => {
31
41
  registry.setTransformations(name, transformationList(body));
32
42
  return NO_CONTENT;
33
43
  },
34
- 'POST /screen': (registry, name, body) => ({
44
+ 'POST /screen': (registry, { name, body }) => ({
35
45
  status: 200,
36
46
  body: { refused: registry.holdsSecret(name, stringList(body, 'texts') ?? []) },
37
47
  }),
38
48
  };
39
- async function handle(registry, request, path) {
49
+ async function handle(registry, request, url) {
50
+ const path = url.pathname;
51
+ if (request.method === 'GET' && path === '/v1/sandboxes') {
52
+ return { status: 200, body: { sandboxes: registry.list() } };
53
+ }
40
54
  const [, name, action = ''] = SANDBOX.exec(path) ?? [];
41
55
  const route = ROUTES[`${request.method} ${action}`];
42
56
  if (name === undefined || route === undefined) {
43
57
  throw new HttpError(404, `No route for ${request.method} ${path}.`);
44
58
  }
45
- return route(registry, name, await readJson(request));
59
+ return route(registry, { name, body: await readJson(request), query: url.searchParams });
46
60
  }
47
61
  /**
48
62
  * The administration API of the egress proxy (`protocol/proxy.ts`): the sandbox service registers
@@ -53,7 +67,8 @@ export function createAdminServer({ registry, token, logger, }) {
53
67
  return createServer((request, response) => {
54
68
  response.setHeader(PROTOCOL_HEADER, String(PROTOCOL_VERSION));
55
69
  const method = request.method ?? 'GET';
56
- const path = new URL(request.url ?? '/', 'http://proxy').pathname;
70
+ const url = new URL(request.url ?? '/', 'http://proxy');
71
+ const path = url.pathname;
57
72
  if (path === '/health') {
58
73
  send(response, {
59
74
  status: 200,
@@ -66,6 +81,6 @@ export function createAdminServer({ registry, token, logger, }) {
66
81
  send(response, { status: 401, body: { error: 'The proxy token is missing or wrong.' } });
67
82
  return;
68
83
  }
69
- handle(registry, request, path).then((reply) => send(response, reply), (error) => fail(response, error, (message) => logger.error(`${method} ${path} failed: ${message}`)));
84
+ handle(registry, request, url).then((reply) => send(response, reply), (error) => fail(response, error, (message) => logger.error(`${method} ${path} failed: ${message}`)));
70
85
  });
71
86
  }
@@ -1,5 +1,6 @@
1
1
  import type { HarnessV1RequestTransformation } from '@ai-sdk/harness';
2
2
  import type { IncomingHttpHeaders } from 'node:http';
3
+ import type { Traffic } from './traffic.js';
3
4
  /** What one sandbox may reach, and the credentials its requests leave with. */
4
5
  export interface EgressPolicy {
5
6
  /** The sandbox's name, which the proxy's log lines name it by. */
@@ -12,6 +13,8 @@ export interface EgressPolicy {
12
13
  readonly transformations: readonly HarnessV1RequestTransformation[];
13
14
  /** Let it reach private addresses and plain HTTP base URLs: tests and local runs only. */
14
15
  readonly allowPrivateNetwork: boolean;
16
+ /** Where the bytes its connections move are counted. */
17
+ readonly traffic?: Traffic;
15
18
  }
16
19
  /** What the egress proxy knows of one request on its way out. */
17
20
  export interface OutgoingRequest {