ai-sdk-sandbox-gce 0.4.0 → 0.4.1
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,11 @@
|
|
|
1
1
|
# ai-sdk-sandbox-gce
|
|
2
2
|
|
|
3
|
+
## 0.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- cb9b124: A process that outlives a template no longer fails every creation from it with a 404 until it restarts: the template is forgotten, built again, and the sandbox created. A template goes with a new version of the service, a new base image on Compute Engine, or a deletion.
|
|
8
|
+
|
|
3
9
|
## 0.4.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -135,7 +135,7 @@ gcloud compute instances create sandbox-proxy --zone=$ZONE --machine-type=e2-sma
|
|
|
135
135
|
#!/bin/sh
|
|
136
136
|
set -e
|
|
137
137
|
# The version of the proxy: the one your application depends on.
|
|
138
|
-
VERSION=0.4.
|
|
138
|
+
VERSION=0.4.1
|
|
139
139
|
# Writes $2 to the file $1 when it differs, and says whether it did.
|
|
140
140
|
changed() {
|
|
141
141
|
mkdir -p "$(dirname "$1")"
|
|
@@ -282,7 +282,7 @@ echo "deb [signed-by=/etc/apt/keyrings/nodesource.asc] https://deb.nodesource.co
|
|
|
282
282
|
> /etc/apt/sources.list.d/nodesource.list
|
|
283
283
|
apt-get update
|
|
284
284
|
apt-get install -y nodejs
|
|
285
|
-
npm install --global ai-sdk-sandbox-gce@0.4.
|
|
285
|
+
npm install --global ai-sdk-sandbox-gce@0.4.1 pnpm@10
|
|
286
286
|
|
|
287
287
|
# The sandbox's user: sudo without a password, and Docker.
|
|
288
288
|
useradd --create-home --shell /bin/bash agent
|
|
@@ -310,7 +310,7 @@ The agent runs as root and starts the commands as `agent`, in its own service: `
|
|
|
310
310
|
|
|
311
311
|
### 4. The service
|
|
312
312
|
|
|
313
|
-
The service's image is published on Docker Hub with each release, `docker.io/fpasquet/ai-sdk-sandbox-gce:<version>`: Node.js and the package, built by the release workflow from the version on npm. Deploy the version your application depends on. Each image carries a provenance attestation, which `gh attestation verify oci://docker.io/fpasquet/ai-sdk-sandbox-gce:0.4.
|
|
313
|
+
The service's image is published on Docker Hub with each release, `docker.io/fpasquet/ai-sdk-sandbox-gce:<version>`: Node.js and the package, built by the release workflow from the version on npm. Deploy the version your application depends on. Each image carries a provenance attestation, which `gh attestation verify oci://docker.io/fpasquet/ai-sdk-sandbox-gce:0.4.1 --owner fpasquet` checks; its [`Dockerfile`](https://github.com/fpasquet/ai-sdk-harness/blob/main/packages/sandbox-gce/Dockerfile) builds the same image from your own registry.
|
|
314
314
|
|
|
315
315
|
Its service account gets a role of its own, with what the service calls and nothing else, limited by a condition to the names it uses: the sandboxes' machines and disks (`sbx-`), the proxy's machine, the sandbox images and templates (`ai-sdk-`).
|
|
316
316
|
|
|
@@ -348,7 +348,7 @@ for secret in sandbox-agent-secret sandbox-proxy-token sandbox-service-token; do
|
|
|
348
348
|
--member=serviceAccount:sandboxes@$PROJECT.iam.gserviceaccount.com --role=roles/secretmanager.secretAccessor
|
|
349
349
|
done
|
|
350
350
|
|
|
351
|
-
gcloud run deploy sandboxes --region=$REGION --image=docker.io/fpasquet/ai-sdk-sandbox-gce:0.4.
|
|
351
|
+
gcloud run deploy sandboxes --region=$REGION --image=docker.io/fpasquet/ai-sdk-sandbox-gce:0.4.1 \
|
|
352
352
|
--service-account=sandboxes@$PROJECT.iam.gserviceaccount.com \
|
|
353
353
|
--network=sandboxes --subnet=service --vpc-egress=private-ranges-only \
|
|
354
354
|
--no-allow-unauthenticated --min-instances=0 --timeout=3600 --concurrency=1000 \
|
|
@@ -5,7 +5,7 @@ import { identityToken } from '../transport/identity-token.js';
|
|
|
5
5
|
import { SandboxServiceClient } from '../transport/sandbox-service-client.js';
|
|
6
6
|
import { abortReason } from '../utils/abort.js';
|
|
7
7
|
import { assertRequiredCommands, DEFAULT_REQUIRED_COMMANDS } from './required-commands.js';
|
|
8
|
-
import {
|
|
8
|
+
import { runSetup, templateId, withTemplate } from './sandbox-template.js';
|
|
9
9
|
/**
|
|
10
10
|
* What a Compute Engine instance name takes once the service's prefix is put before it, and a URL
|
|
11
11
|
* path as it is: the instance name is at most 63 characters and never ends with a dash.
|
|
@@ -55,15 +55,10 @@ export async function createGceNetworkSandboxSession(options) {
|
|
|
55
55
|
assertSandboxName(name);
|
|
56
56
|
const client = clientOf(options);
|
|
57
57
|
const network = { allowedHosts, baseUrls };
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
...network,
|
|
63
|
-
image,
|
|
64
|
-
template: ready,
|
|
65
|
-
abortSignal,
|
|
66
|
-
});
|
|
58
|
+
const create = (ready) => createFrom(client, name, { ...network, image, template: ready, abortSignal });
|
|
59
|
+
const description = await (template
|
|
60
|
+
? withTemplate(client, { template, setup, network, image, requiredCommands, abortSignal }, create)
|
|
61
|
+
: create());
|
|
67
62
|
const session = sessionOf(client, description, options);
|
|
68
63
|
try {
|
|
69
64
|
// A template was checked and set up before it was saved.
|
|
@@ -41,4 +41,12 @@ export declare function runSetup(session: GceNetworkSandboxSession, setup: reado
|
|
|
41
41
|
* already installed.
|
|
42
42
|
*/
|
|
43
43
|
export declare function ensureTemplate(client: SandboxServiceClient, source: BuildSettings & TemplateSource, abortSignal?: AbortSignal): Promise<ReadyTemplate>;
|
|
44
|
+
/**
|
|
45
|
+
* Calls `create` with the template ready. This process remembers a template for as long as it runs,
|
|
46
|
+
* and the service can lose it meanwhile, to a new version or a new base image: on
|
|
47
|
+
* its 404, the template is forgotten, built again if need be, and `create` called once more.
|
|
48
|
+
*/
|
|
49
|
+
export declare function withTemplate<T>(client: SandboxServiceClient, { abortSignal, ...source }: BuildSettings & TemplateSource & {
|
|
50
|
+
abortSignal?: AbortSignal;
|
|
51
|
+
}, create: (template: ReadyTemplate) => Promise<T>): Promise<T>;
|
|
44
52
|
export {};
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
+
import { GceSandboxServiceError } from '../errors/gce-sandbox-service-error.js';
|
|
2
3
|
import { GceNetworkSandboxSession } from '../session/gce-network-sandbox-session.js';
|
|
3
4
|
import { assertRequiredCommands } from './required-commands.js';
|
|
4
5
|
/** The prefix of the templates' ids, and of the sandboxes that build them. */
|
|
5
6
|
export const TEMPLATE_PREFIX = 'ai-sdk-harness-template';
|
|
6
7
|
/** Templates being built by this process, by service and id: one build at a time. */
|
|
7
8
|
const building = new Map();
|
|
9
|
+
function keyOf(client, source) {
|
|
10
|
+
return `${client.baseUrl} ${source.image ?? ''} ${templateId(source)}`;
|
|
11
|
+
}
|
|
8
12
|
/**
|
|
9
13
|
* The template's id: `ai-sdk-harness-template-<digest>`, the digest covering the harness's recipe
|
|
10
14
|
* and the setup commands, so that a new harness version gets a template of its own.
|
|
@@ -33,7 +37,7 @@ export async function runSetup(session, setup, abortSignal) {
|
|
|
33
37
|
*/
|
|
34
38
|
export function ensureTemplate(client, source, abortSignal) {
|
|
35
39
|
const id = templateId(source);
|
|
36
|
-
const key =
|
|
40
|
+
const key = keyOf(client, source);
|
|
37
41
|
let ready = building.get(key);
|
|
38
42
|
if (ready === undefined) {
|
|
39
43
|
ready = client.templateExists(id, source.image, abortSignal).then(async (exists) => {
|
|
@@ -54,6 +58,28 @@ export function ensureTemplate(client, source, abortSignal) {
|
|
|
54
58
|
}
|
|
55
59
|
return ready;
|
|
56
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Calls `create` with the template ready. This process remembers a template for as long as it runs,
|
|
63
|
+
* and the service can lose it meanwhile, to a new version or a new base image: on
|
|
64
|
+
* its 404, the template is forgotten, built again if need be, and `create` called once more.
|
|
65
|
+
*/
|
|
66
|
+
export async function withTemplate(client, { abortSignal, ...source }, create) {
|
|
67
|
+
const remembered = ensureTemplate(client, source, abortSignal);
|
|
68
|
+
const template = await remembered;
|
|
69
|
+
try {
|
|
70
|
+
return await create(template);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
if (!(error instanceof GceSandboxServiceError) || error.status !== 404)
|
|
74
|
+
throw error;
|
|
75
|
+
// Sandboxes that failed alongside this one share the build that comes after.
|
|
76
|
+
const key = keyOf(client, source);
|
|
77
|
+
if (building.get(key) === remembered)
|
|
78
|
+
building.delete(key);
|
|
79
|
+
const rebuilt = await ensureTemplate(client, source, abortSignal);
|
|
80
|
+
return create(rebuilt);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
57
83
|
async function build(client, { template, setup, network, image, requiredCommands, id, }, abortSignal) {
|
|
58
84
|
const builder = `${TEMPLATE_PREFIX}-${id.slice(-8)}-${randomBytes(3).toString('hex')}`;
|
|
59
85
|
const { workingDirectory } = await client.create(builder, { ...network, image, abortSignal });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-sdk-sandbox-gce",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Compute Engine sandboxes for AI SDK harness agents: Claude Code, Codex and friends in a virtual machine of their own on Google Cloud, Docker included, stopped between turns.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -57,10 +57,10 @@
|
|
|
57
57
|
"typescript": "^6.0.3",
|
|
58
58
|
"vitest": "^5.0.5",
|
|
59
59
|
"zod": "^4.6.7",
|
|
60
|
-
"@repo/
|
|
60
|
+
"@repo/build": "0.0.0",
|
|
61
61
|
"@repo/prettier-config": "0.0.0",
|
|
62
|
+
"@repo/eslint-config": "0.0.0",
|
|
62
63
|
"@repo/typescript-config": "0.0.0",
|
|
63
|
-
"@repo/build": "0.0.0",
|
|
64
64
|
"@repo/vitest-config": "0.0.0"
|
|
65
65
|
},
|
|
66
66
|
"author": {
|