@mnaimfaizy/agent-kit 1.0.0-beta.13 → 1.0.0-beta.15
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 +24 -5
- package/custom-harness.schema.json +243 -0
- package/harnesses.json +286 -0
- package/package.json +4 -2
- package/src/checks/ci-workflow.mjs +105 -0
- package/src/checks/claude-app.mjs +11 -2
- package/src/checks/custom-harness.mjs +157 -0
- package/src/checks/github-app.mjs +214 -0
- package/src/checks/review-response.mjs +54 -27
- package/src/checks/rulesets.mjs +9 -8
- package/src/checks/secrets-and-variables.mjs +220 -43
- package/src/checks/stages.mjs +705 -0
- package/src/cli.mjs +277 -31
- package/src/deep-scan/agent.mjs +145 -117
- package/src/deep-scan/credential.mjs +88 -42
- package/src/deep-scan/docker-driver.mjs +131 -49
- package/src/deep-scan/harness-text.mjs +99 -0
- package/src/deep-scan/lifecycle.mjs +92 -199
- package/src/deep-scan/limits.mjs +13 -7
- package/src/deep-scan/model-proxy.mjs +47 -602
- package/src/deep-scan/preflight.mjs +81 -1
- package/src/deep-scan/recipe.mjs +7 -7
- package/src/deep-scan/runtime.mjs +54 -6
- package/src/deep-scan/sandbox-run.mjs +232 -0
- package/src/deep-scan/sbx-driver.mjs +242 -50
- package/src/deep-scan/tar.mjs +69 -22
- package/src/deep-scan/verify.mjs +6 -1
- package/src/deep-scan.mjs +98 -14
- package/src/doctor.mjs +113 -4
- package/src/harness/adapters.mjs +30 -0
- package/src/harness/antigravity.mjs +187 -0
- package/src/harness/claude-code.mjs +236 -0
- package/src/harness/codex.mjs +219 -0
- package/src/harness/cursor.mjs +199 -0
- package/src/harness/custom/registry.mjs +21 -0
- package/src/harness/custom/schema.mjs +90 -0
- package/src/harness/custom.mjs +299 -0
- package/src/harness/facts.mjs +157 -0
- package/src/harness/gemini.mjs +164 -0
- package/src/harness/install-layer.mjs +141 -0
- package/src/harness/opencode.mjs +289 -0
- package/src/harness/resolve.mjs +156 -0
- package/src/harness/support-levels.mjs +197 -0
- package/src/harness-live/assess.mjs +291 -0
- package/src/harness-live/cursor-real.mjs +146 -0
- package/src/harness-live/cursor-version.mjs +70 -0
- package/src/harness-live/cursor.mjs +80 -0
- package/src/harness-live/custom.mjs +91 -0
- package/src/harness-live/fixture-harness.mjs +45 -0
- package/src/harness-live/harnesses.mjs +263 -0
- package/src/harness-live/host.mjs +414 -0
- package/src/harness-live/opencode.mjs +289 -0
- package/src/harness-live/probes.mjs +239 -0
- package/src/harness-live/run.mjs +214 -0
- package/src/harness-live/setup.mjs +126 -0
- package/src/harness-live/stage.mjs +161 -0
- package/src/harness-live/suite.mjs +481 -0
- package/src/harness-test.mjs +116 -0
- package/src/init.mjs +339 -23
- package/src/model-proxy/core.mjs +657 -0
- package/src/model-proxy/profiles/anthropic.mjs +241 -0
- package/src/model-proxy/profiles/gemini-api.mjs +311 -0
- package/src/model-proxy/profiles/openai.mjs +327 -0
- package/src/model-proxy/stub-dialects/anthropic.mjs +110 -0
- package/src/model-proxy/stub-dialects/gemini-api.mjs +178 -0
- package/src/model-proxy/stub-dialects/openai.mjs +173 -0
- package/src/model-proxy/stub.mjs +182 -0
- package/src/stage/audit.mjs +79 -0
- package/src/stage/egress-route.mjs +207 -0
- package/src/stage/implement/carry.mjs +308 -0
- package/src/stage/implement/sandbox.mjs +271 -0
- package/src/stage/implement/verify.mjs +70 -0
- package/src/stage/implement.mjs +218 -0
- package/src/stage/plan.mjs +115 -0
- package/src/stage/review-response.mjs +172 -0
- package/src/stage/review.mjs +185 -0
- package/src/stage/workspace.mjs +274 -0
- package/src/stage.mjs +1068 -0
- package/src/deep-scan/claude-code.mjs +0 -25
|
@@ -14,14 +14,19 @@
|
|
|
14
14
|
// starts, and a plain image has no /home/agent, so `-t <plain image>` never
|
|
15
15
|
// starts (#375's diagnosis, run evidence d375-sbx-diag.txt). The human chose
|
|
16
16
|
// (#375, option 1): Docker on the host pulls the recipe's image and layers
|
|
17
|
-
// on it the Docker driver's pinned
|
|
18
|
-
//
|
|
17
|
+
// on it the Docker driver's pinned harness (copied from the Harness
|
|
18
|
+
// image, ADR 0029; a recipe with no image gets the Harness image itself as
|
|
19
|
+
// the base) and what Docker's docs require of a template image (TEMPLATE_LAYER: a non-root `agent`, uid
|
|
19
20
|
// 1000, home /home/agent, as its USER; curl, git, CA certificates and
|
|
20
21
|
// bash, checked); `docker save` writes it to a private folder, `sbx template load`
|
|
21
22
|
// loads it, and `sbx create --pull never -t <it>` uses it. Teardown removes
|
|
22
23
|
// the template and the layered image. Only the pull and that fixed layer run
|
|
23
24
|
// on the host's Docker (Docker Desktop, the WSL 2 boundary a scan refuses),
|
|
24
25
|
// never a Consumer's own build steps, so a `dockerfile` recipe is refused.
|
|
26
|
+
// A Custom harness (#472) has no Harness image: its template is the recipe's
|
|
27
|
+
// image, or the full Node image, with its path alone added, and its npm
|
|
28
|
+
// package is installed with `sbx exec` once the sandbox starts, before
|
|
29
|
+
// anything is copied in, with a rule for the npm registry alone.
|
|
25
30
|
// - Setup egress: `sbx policy allow network --sandbox` for each registry
|
|
26
31
|
// (986-987), removed with `sbx policy rm network --sandbox --resource` for
|
|
27
32
|
// the cut (1148, 1179-1180); `sbx policy ls <sandbox> --json` (812, 822)
|
|
@@ -42,9 +47,17 @@ import { lstatSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSyn
|
|
|
42
47
|
import { tmpdir } from "node:os";
|
|
43
48
|
import { join } from "node:path";
|
|
44
49
|
import { firstLine } from "../exec.mjs";
|
|
45
|
-
import {
|
|
46
|
-
|
|
50
|
+
import {
|
|
51
|
+
CUSTOM_SANDBOX_BASE,
|
|
52
|
+
layerDockerfile,
|
|
53
|
+
NPM_REGISTRY,
|
|
54
|
+
pinnedHarnessImage,
|
|
55
|
+
sandboxNpmInstall,
|
|
56
|
+
sandboxNpmLayer,
|
|
57
|
+
} from "../harness/install-layer.mjs";
|
|
58
|
+
import { envArgs, LABEL } from "./docker-driver.mjs";
|
|
47
59
|
import { allowlistOf } from "./egress.mjs";
|
|
60
|
+
import { refuseMusl } from "./preflight.mjs";
|
|
48
61
|
import { imageDigestNote } from "./recipe.mjs";
|
|
49
62
|
import { ENDS_HERE, must, StepFailed } from "./steps.mjs";
|
|
50
63
|
|
|
@@ -103,6 +116,87 @@ export function globalPolicyProblem(r) {
|
|
|
103
116
|
];
|
|
104
117
|
}
|
|
105
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Why the Consumer's global sbx secrets stop a scan, as refusal lines, or null
|
|
121
|
+
* when there are none. From `sbx secret ls --global --json`: passes only when
|
|
122
|
+
* `secrets`, `custom_secrets` and `shadowed_services` are all empty lists and
|
|
123
|
+
* `env_only_count` is 0. Any other value is refused, all kinds found in one
|
|
124
|
+
* refusal; so is a missing field or one of the wrong type. sbx's host proxy injects a global secret
|
|
125
|
+
* into any sandbox's requests to the matching service's domains, so a scan's
|
|
126
|
+
* setup could send the Consumer's real key to a registry it is allowed to
|
|
127
|
+
* reach (CVE-2026-136998 is the same class). Only service names are read:
|
|
128
|
+
* never a value. Output that cannot be read is a refusal.
|
|
129
|
+
* @param {import("../exec.mjs").StartResult} r
|
|
130
|
+
* @returns {string[] | null}
|
|
131
|
+
*/
|
|
132
|
+
export function globalSecretsProblem(r) {
|
|
133
|
+
const fix = [
|
|
134
|
+
"deep-scan never changes your sbx secrets. Move each to one sandbox with `sbx secret set <service> --sandbox <name>`, or remove it with `sbx secret rm <service>`.",
|
|
135
|
+
];
|
|
136
|
+
if (r.status !== 0) {
|
|
137
|
+
return [
|
|
138
|
+
`REFUSED Could not read the Docker Sandboxes global secrets: ${firstLine(r.stderr) || `exit ${r.status}`}`,
|
|
139
|
+
];
|
|
140
|
+
}
|
|
141
|
+
let parsed;
|
|
142
|
+
try {
|
|
143
|
+
parsed = JSON.parse(r.stdout.toString("utf8"));
|
|
144
|
+
} catch {
|
|
145
|
+
parsed = null;
|
|
146
|
+
}
|
|
147
|
+
if (
|
|
148
|
+
!parsed ||
|
|
149
|
+
typeof parsed !== "object" ||
|
|
150
|
+
!Array.isArray(parsed.secrets) ||
|
|
151
|
+
!Array.isArray(parsed.custom_secrets) ||
|
|
152
|
+
!Array.isArray(parsed.shadowed_services) ||
|
|
153
|
+
!Number.isInteger(parsed.env_only_count) ||
|
|
154
|
+
parsed.env_only_count < 0
|
|
155
|
+
) {
|
|
156
|
+
return [
|
|
157
|
+
"REFUSED Could not read the Docker Sandboxes global secrets: `sbx secret ls --global --json` did not give secrets, custom_secrets, shadowed_services and env_only_count.",
|
|
158
|
+
];
|
|
159
|
+
}
|
|
160
|
+
const entries = [...parsed.secrets, ...parsed.custom_secrets];
|
|
161
|
+
const safe = (v) => (typeof v === "string" && /^[\w.:*@/-]{1,100}$/.test(v) ? v : "(unnamed)");
|
|
162
|
+
const shadowed = [...new Set(parsed.shadowed_services.map(safe))];
|
|
163
|
+
const envOnly = parsed.env_only_count;
|
|
164
|
+
if (entries.length === 0 && shadowed.length === 0 && envOnly === 0) return null;
|
|
165
|
+
// What shadowed_services and env_only_count mean is not documented by sbx,
|
|
166
|
+
// so a non-empty one fails closed. Every kind found is reported at once, each
|
|
167
|
+
// with its own fix, so fixing one does not meet a different refusal next.
|
|
168
|
+
const names = [
|
|
169
|
+
...new Set(
|
|
170
|
+
entries.map((e) => {
|
|
171
|
+
const o = e && typeof e === "object" ? e : {};
|
|
172
|
+
for (const k of ["service", "name", "registry", "host", "env_name"]) {
|
|
173
|
+
if (safe(o[k]) !== "(unnamed)") return o[k];
|
|
174
|
+
}
|
|
175
|
+
return "(unnamed)";
|
|
176
|
+
}),
|
|
177
|
+
),
|
|
178
|
+
];
|
|
179
|
+
return [
|
|
180
|
+
"REFUSED Docker Sandboxes holds credentials its proxy may inject into any sandbox's requests to their services' domains, so a scan's setup could send your real key to a registry it may reach (CVE-2026-136998 is the same class).",
|
|
181
|
+
...(entries.length
|
|
182
|
+
? [`Global secrets: ${names.join(", ")} (values are never read or printed).`, ...fix]
|
|
183
|
+
: []),
|
|
184
|
+
...(shadowed.length
|
|
185
|
+
? [
|
|
186
|
+
`Shadowed services: ${shadowed.join(", ")}.`,
|
|
187
|
+
"Fix: run `sbx secret ls --global` to see them and remove each with `sbx secret rm <service>`.",
|
|
188
|
+
]
|
|
189
|
+
: []),
|
|
190
|
+
...(envOnly > 0
|
|
191
|
+
? [
|
|
192
|
+
`Credentials taken from the host environment: ${envOnly} (values are never read or printed).`,
|
|
193
|
+
"Fix: unset the API key variables (such as GITHUB_TOKEN or OPENAI_API_KEY) that sbx reads from the environment you run deep-scan in. deep-scan never changes your environment.",
|
|
194
|
+
]
|
|
195
|
+
: []),
|
|
196
|
+
"Then run deep-scan again.",
|
|
197
|
+
];
|
|
198
|
+
}
|
|
199
|
+
|
|
106
200
|
/** The rules list of `sbx policy ls --json`, or null. */
|
|
107
201
|
function rulesOf(r) {
|
|
108
202
|
try {
|
|
@@ -126,10 +220,12 @@ export function sbxResources(registries) {
|
|
|
126
220
|
}
|
|
127
221
|
|
|
128
222
|
/**
|
|
129
|
-
* @param {{ id: string, call: import("./docker-driver.mjs").Call }} opts
|
|
223
|
+
* @param {{ id: string, call: import("./docker-driver.mjs").Call, plan: import("../harness/claude-code.mjs").LaunchPlan }} opts
|
|
224
|
+
* `plan` is the harness's launch plan: its install layer goes on the template.
|
|
130
225
|
* @returns {import("./lifecycle.mjs").Driver}
|
|
131
226
|
*/
|
|
132
|
-
export function sbxDriver({ id, call }) {
|
|
227
|
+
export function sbxDriver({ id, call, plan }) {
|
|
228
|
+
const { displayName } = plan.identity;
|
|
133
229
|
const name = `agent-kit-deep-${id}`;
|
|
134
230
|
/** The layered image, and the sbx template loaded from it. */
|
|
135
231
|
const template = `${name}:sbx`;
|
|
@@ -161,37 +257,73 @@ export function sbxDriver({ id, call }) {
|
|
|
161
257
|
);
|
|
162
258
|
allowed.splice(allowed.indexOf(list), 1);
|
|
163
259
|
};
|
|
164
|
-
const exec = (script, { env = [], workdir = "/workspace", user } = {}) =>
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
260
|
+
const exec = (script, { env = [], workdir = "/workspace", user } = {}) => {
|
|
261
|
+
const { args, childEnv } = envArgs(env, plan.launch?.secretEnv ?? [], "-e");
|
|
262
|
+
return sbx(
|
|
263
|
+
[
|
|
264
|
+
"exec",
|
|
265
|
+
...(user ? ["-u", user] : []),
|
|
266
|
+
...args,
|
|
267
|
+
...(workdir ? ["-w", workdir] : []),
|
|
268
|
+
name,
|
|
269
|
+
"sh",
|
|
270
|
+
"-c",
|
|
271
|
+
script,
|
|
272
|
+
],
|
|
273
|
+
{ env: childEnv },
|
|
274
|
+
);
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* A Custom harness's package, installed while the sandbox holds nothing of
|
|
279
|
+
* the target's: its install scripts have only the npm registry to reach, and
|
|
280
|
+
* the rule is gone before anything is copied in.
|
|
281
|
+
*/
|
|
282
|
+
const installPackage = async (installLayer) => {
|
|
283
|
+
const rule = `${NPM_REGISTRY}:443`;
|
|
284
|
+
await allow([rule], `allowing ${NPM_REGISTRY} for the harness's install`);
|
|
285
|
+
must(
|
|
286
|
+
await exec(sandboxNpmInstall(installLayer), { user: "root", workdir: null }),
|
|
287
|
+
`installing ${installLayer.npm} in the sandbox`,
|
|
288
|
+
{ showOutput: true },
|
|
289
|
+
);
|
|
290
|
+
await disallow(rule, `removing the ${NPM_REGISTRY} rule`);
|
|
291
|
+
};
|
|
175
292
|
|
|
176
293
|
return {
|
|
177
294
|
container: name,
|
|
178
295
|
|
|
179
|
-
async prepare(steps, { out }) {
|
|
296
|
+
async prepare(steps, { out, why = "the recipe names no image" }) {
|
|
297
|
+
// A Custom harness has no Harness image: its npm package is installed
|
|
298
|
+
// inside the sandbox once it starts, never in a build on this machine.
|
|
299
|
+
const { npm } = plan.installLayer;
|
|
300
|
+
const harness = npm === undefined ? pinnedHarnessImage(plan.installLayer) : null;
|
|
180
301
|
if (steps.dockerfile !== undefined) {
|
|
181
302
|
throw new StepFailed([
|
|
182
303
|
`REFUSED The recipe builds ${steps.dockerfile}, and on Docker Sandboxes its build steps would run on this machine's Docker (Docker Desktop's WSL 2 VM on Windows), outside the sandbox.`,
|
|
183
|
-
"On Docker Sandboxes, name a base image with `image:` instead
|
|
304
|
+
"On Docker Sandboxes, name a glibc base image with `image:` instead, or none to run on the Harness image, or run on another accepted runtime.",
|
|
184
305
|
]);
|
|
185
306
|
}
|
|
186
307
|
const problem = globalPolicyProblem(await sbx(["policy", "ls", "--json"]));
|
|
187
308
|
if (problem) throw new StepFailed(problem);
|
|
188
309
|
out("Network policy: Docker Sandboxes' global policy is deny-all (checked read-only).");
|
|
310
|
+
const secrets = globalSecretsProblem(await sbx(["secret", "ls", "--global", "--json"]));
|
|
311
|
+
if (secrets) throw new StepFailed(secrets);
|
|
312
|
+
out(
|
|
313
|
+
"Secrets: Docker Sandboxes holds no global secrets, shadowed services or credentials from the host environment (checked read-only).",
|
|
314
|
+
);
|
|
315
|
+
const own = steps.image !== undefined;
|
|
316
|
+
const base = own ? steps.image : (harness ?? CUSTOM_SANDBOX_BASE);
|
|
189
317
|
out(
|
|
190
|
-
|
|
318
|
+
npm !== undefined
|
|
319
|
+
? `Image: ${own ? base : `the kit's base image ${base}; ${why}`}, as the sandbox's template, built with Docker on this machine; ${npm} is installed from npm for ${displayName} inside the sandbox, with only ${NPM_REGISTRY} reachable, before anything is copied in.`
|
|
320
|
+
: own
|
|
321
|
+
? `Image: layering the pinned ${displayName} on ${base} with Docker on this machine, auto-updater off, as the sandbox's template; ${displayName} comes from the Harness image ${harness}.`
|
|
322
|
+
: `Image: the Harness image ${harness}, which holds the pinned ${displayName}, as the sandbox's template, built with Docker on this machine; ${why}.`,
|
|
191
323
|
);
|
|
192
|
-
const note = imageDigestNote(
|
|
324
|
+
const note = own ? imageDigestNote(base) : null;
|
|
193
325
|
if (note) out(note);
|
|
194
|
-
const pulled = await docker(["pull",
|
|
326
|
+
const pulled = await docker(["pull", base]);
|
|
195
327
|
if (pulled.status === null) {
|
|
196
328
|
throw new StepFailed([
|
|
197
329
|
"FAILED Docker Sandboxes' template is built with Docker on this machine, and docker could not run: " +
|
|
@@ -200,15 +332,19 @@ export function sbxDriver({ id, call }) {
|
|
|
200
332
|
ENDS_HERE,
|
|
201
333
|
]);
|
|
202
334
|
}
|
|
203
|
-
must(pulled, `pulling ${
|
|
335
|
+
must(pulled, `pulling ${base}`, { showOutput: true });
|
|
204
336
|
imageBuilt = true;
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
337
|
+
const layer =
|
|
338
|
+
npm !== undefined
|
|
339
|
+
? sandboxNpmLayer(base)
|
|
340
|
+
: own
|
|
341
|
+
? layerDockerfile(base, plan.installLayer)
|
|
342
|
+
: `FROM ${base}\n`;
|
|
343
|
+
const built = await docker(["build", "--label", `${LABEL}=${id}`, "--tag", template, "-"], {
|
|
344
|
+
stdin: `${layer}${TEMPLATE_LAYER}`,
|
|
345
|
+
});
|
|
346
|
+
if (own) refuseMusl(built, steps);
|
|
347
|
+
must(built, `layering ${displayName} on ${base}`, { showOutput: true });
|
|
212
348
|
// A private host file, by a name relative to its folder, so a Windows
|
|
213
349
|
// drive letter is never read as anything else; gone once it is loaded.
|
|
214
350
|
const tar = "template.tar";
|
|
@@ -234,24 +370,7 @@ export function sbxDriver({ id, call }) {
|
|
|
234
370
|
},
|
|
235
371
|
|
|
236
372
|
async start() {
|
|
237
|
-
|
|
238
|
-
must(
|
|
239
|
-
await sbx([
|
|
240
|
-
"create",
|
|
241
|
-
"--name",
|
|
242
|
-
name,
|
|
243
|
-
"--no-progress",
|
|
244
|
-
"--pull",
|
|
245
|
-
"never",
|
|
246
|
-
"-t",
|
|
247
|
-
template,
|
|
248
|
-
"-e",
|
|
249
|
-
AUTO_UPDATER_OFF,
|
|
250
|
-
"shell",
|
|
251
|
-
]),
|
|
252
|
-
"creating the sandbox",
|
|
253
|
-
{ showOutput: true },
|
|
254
|
-
);
|
|
373
|
+
await create("creating the sandbox");
|
|
255
374
|
},
|
|
256
375
|
|
|
257
376
|
async copyIn(tar, what) {
|
|
@@ -276,9 +395,57 @@ export function sbxDriver({ id, call }) {
|
|
|
276
395
|
);
|
|
277
396
|
},
|
|
278
397
|
|
|
279
|
-
/**
|
|
398
|
+
/** The harness is in the sandbox already: nothing to install. */
|
|
280
399
|
async installAgent() {},
|
|
281
400
|
|
|
401
|
+
/**
|
|
402
|
+
* The archive `script` writes, run as root in the sandbox into a file
|
|
403
|
+
* there, checked for size, then copied to a private host folder with
|
|
404
|
+
* `sbx cp` and read (ADR 0047).
|
|
405
|
+
*/
|
|
406
|
+
async carryOut(script, { maxBytes }) {
|
|
407
|
+
const inside = "/tmp/agent-kit-carry.tar";
|
|
408
|
+
const made = await exec(
|
|
409
|
+
`( ${script} ) > ${inside} || exit 3; [ "$(wc -c < ${inside})" -le ${maxBytes} ] || exit 5`,
|
|
410
|
+
{ user: "root", workdir: null },
|
|
411
|
+
);
|
|
412
|
+
if (made.status === 5) return { error: `it is larger than ${maxBytes / 1024 ** 3} GiB` };
|
|
413
|
+
if (made.status !== 0) {
|
|
414
|
+
return {
|
|
415
|
+
error: `tar exited ${made.status ?? "abnormally"}: ${firstLine(made.stderr) || "no output"}`,
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
const into = mkdtempSync(join(hostDir(), "carry-"));
|
|
419
|
+
try {
|
|
420
|
+
const r = await sbx(["cp", `${name}:${inside}`, "."], { cwd: into });
|
|
421
|
+
if (r.status !== 0)
|
|
422
|
+
return { error: `sbx cp failed: ${firstLine(r.stderr) || `exit ${r.status}`}` };
|
|
423
|
+
const entries = readdirSync(into);
|
|
424
|
+
const file = entries.length === 1 ? join(into, entries[0]) : null;
|
|
425
|
+
if (file === null || !lstatSync(file).isFile()) return { error: "sbx cp gave no one file" };
|
|
426
|
+
if (lstatSync(file).size > maxBytes) {
|
|
427
|
+
return { error: `it is larger than ${maxBytes / 1024 ** 3} GiB` };
|
|
428
|
+
}
|
|
429
|
+
return { data: readFileSync(file) };
|
|
430
|
+
} finally {
|
|
431
|
+
rmSync(into, { recursive: true, force: true });
|
|
432
|
+
}
|
|
433
|
+
},
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Remove the sandbox, and every process in it, and create a fresh one
|
|
437
|
+
* from the same template, by the same name, then check from the host that
|
|
438
|
+
* it has no network rule (ADR 0047). The cut removed every rule first.
|
|
439
|
+
*/
|
|
440
|
+
async renew() {
|
|
441
|
+
must(await sbx(["rm", "--force", name]), "removing the setup sandbox");
|
|
442
|
+
await create("creating the agent's sandbox");
|
|
443
|
+
const left = await this.egressLeft();
|
|
444
|
+
if (left !== null) {
|
|
445
|
+
throw new StepFailed([`FAILED the agent's sandbox has a network: ${left}.`, ENDS_HERE]);
|
|
446
|
+
}
|
|
447
|
+
},
|
|
448
|
+
|
|
282
449
|
async openSetupEgress(registries) {
|
|
283
450
|
const resources = sbxResources(registries);
|
|
284
451
|
if (!resources.length) return { env: [], note: "no registries, so no network" };
|
|
@@ -420,6 +587,31 @@ export function sbxDriver({ id, call }) {
|
|
|
420
587
|
},
|
|
421
588
|
};
|
|
422
589
|
|
|
590
|
+
/**
|
|
591
|
+
* `sbx create` of the sandbox from the template; a Custom harness's package
|
|
592
|
+
* is installed in it before anything is copied in.
|
|
593
|
+
*/
|
|
594
|
+
async function create(what) {
|
|
595
|
+
created = true;
|
|
596
|
+
must(
|
|
597
|
+
await sbx([
|
|
598
|
+
"create",
|
|
599
|
+
"--name",
|
|
600
|
+
name,
|
|
601
|
+
"--no-progress",
|
|
602
|
+
"--pull",
|
|
603
|
+
"never",
|
|
604
|
+
"-t",
|
|
605
|
+
template,
|
|
606
|
+
...plan.installLayer.env.flatMap((v) => ["-e", v]),
|
|
607
|
+
"shell",
|
|
608
|
+
]),
|
|
609
|
+
what,
|
|
610
|
+
{ showOutput: true },
|
|
611
|
+
);
|
|
612
|
+
if (plan.installLayer.npm !== undefined) await installPackage(plan.installLayer);
|
|
613
|
+
}
|
|
614
|
+
|
|
423
615
|
function sandboxTeardown() {
|
|
424
616
|
return [
|
|
425
617
|
...allowed.map((list) => ({
|
|
@@ -475,7 +667,7 @@ function idOf(r, repository, tag) {
|
|
|
475
667
|
* image's package mirror from the host, which no recipe field names. An
|
|
476
668
|
* existing uid 1000 account (`node`, in the Node.js images) is renamed to
|
|
477
669
|
* `agent`, its home moved, rather than given a second name for one uid.
|
|
478
|
-
* It runs as root, after the
|
|
670
|
+
* It runs as root, after the harness's install layer, and ends on USER agent.
|
|
479
671
|
*/
|
|
480
672
|
const TEMPLATE_LAYER = [
|
|
481
673
|
"USER root",
|
package/src/deep-scan/tar.mjs
CHANGED
|
@@ -1,44 +1,91 @@
|
|
|
1
|
-
// The tar streams the
|
|
2
|
-
// in Node core (ADR 0001). In: a ustar archive
|
|
3
|
-
//
|
|
1
|
+
// The tar streams the Launcher moves across the sandbox boundary,
|
|
2
|
+
// in Node core (ADR 0001). In: a ustar archive the launcher builds itself
|
|
3
|
+
// (the grounding it fetched, a brief, a CI Stage's copy of the checkout). Out: the one report file, read from the
|
|
4
4
|
// archive `tar -c` writes from the sandbox through `docker exec`, refusing anything that is
|
|
5
5
|
// not exactly one regular file.
|
|
6
6
|
|
|
7
7
|
const BLOCK = 512;
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* A ustar archive of `entries`, each a folder (`dir: true`)
|
|
11
|
-
* its bytes. Paths are relative
|
|
12
|
-
*
|
|
10
|
+
* A ustar archive of `entries`, each a folder (`dir: true`), a symbolic link
|
|
11
|
+
* (`link`, its target) or a file with its bytes. Paths are relative and use
|
|
12
|
+
* `/`; a path or link target past ustar's 100 bytes goes in a PAX header.
|
|
13
|
+
* @param {Array<{ path: string, dir?: boolean, link?: string, executable?: boolean, data?: Buffer }>} entries
|
|
13
14
|
* @returns {Buffer}
|
|
14
15
|
*/
|
|
15
16
|
export function tarOf(entries) {
|
|
16
17
|
const parts = [];
|
|
17
18
|
for (const entry of entries) {
|
|
18
19
|
const name = entry.dir ? `${entry.path.replace(/\/$/, "")}/` : entry.path;
|
|
19
|
-
if (
|
|
20
|
+
if (name.startsWith("/") || name.split("/").includes("..") || name.includes("\0")) {
|
|
20
21
|
throw new Error(`tar entry name not allowed: ${JSON.stringify(name)}`);
|
|
21
22
|
}
|
|
22
|
-
const data =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
23
|
+
const data =
|
|
24
|
+
entry.dir || entry.link !== undefined ? Buffer.alloc(0) : (entry.data ?? Buffer.alloc(0));
|
|
25
|
+
const long = [
|
|
26
|
+
...(Buffer.byteLength(name) > NAME_BYTES ? [["path", name]] : []),
|
|
27
|
+
...(Buffer.byteLength(entry.link ?? "") > NAME_BYTES ? [["linkpath", entry.link]] : []),
|
|
28
|
+
];
|
|
29
|
+
if (long.length) {
|
|
30
|
+
const records = Buffer.from(
|
|
31
|
+
long.map(([key, value]) => paxRecord(key, value)).join(""),
|
|
32
|
+
"utf8",
|
|
33
|
+
);
|
|
34
|
+
parts.push(
|
|
35
|
+
headerOf({ name: "PaxHeader", type: "x", mode: 0o644, size: records.length }),
|
|
36
|
+
records,
|
|
37
|
+
Buffer.alloc(padding(records.length)),
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
parts.push(
|
|
41
|
+
headerOf({
|
|
42
|
+
name,
|
|
43
|
+
type: entry.dir ? "5" : entry.link !== undefined ? "2" : "0",
|
|
44
|
+
mode: entry.dir || entry.executable ? 0o755 : 0o644,
|
|
45
|
+
size: data.length,
|
|
46
|
+
link: entry.link,
|
|
47
|
+
}),
|
|
48
|
+
data,
|
|
49
|
+
Buffer.alloc(padding(data.length)),
|
|
50
|
+
);
|
|
37
51
|
}
|
|
38
52
|
parts.push(Buffer.alloc(BLOCK * 2));
|
|
39
53
|
return Buffer.concat(parts);
|
|
40
54
|
}
|
|
41
55
|
|
|
56
|
+
/** The longest name or link target a ustar header holds. */
|
|
57
|
+
const NAME_BYTES = 100;
|
|
58
|
+
|
|
59
|
+
/** One 512-byte ustar header. A name too long for it is cut: its PAX header holds it. */
|
|
60
|
+
function headerOf({ name, type, mode, size, link }) {
|
|
61
|
+
const header = Buffer.alloc(BLOCK);
|
|
62
|
+
header.write(name, 0, NAME_BYTES, "utf8");
|
|
63
|
+
header.write(octal(mode, 8), 100, "ascii");
|
|
64
|
+
header.write(octal(0, 8), 108, "ascii");
|
|
65
|
+
header.write(octal(0, 8), 116, "ascii");
|
|
66
|
+
header.write(octal(size, 12), 124, "ascii");
|
|
67
|
+
header.write(octal(0, 12), 136, "ascii");
|
|
68
|
+
header.write(" ", 148, "ascii");
|
|
69
|
+
header.write(type, 156, "ascii");
|
|
70
|
+
if (link !== undefined) header.write(link, 157, NAME_BYTES, "utf8");
|
|
71
|
+
header.write("ustar\u000000", 257, "binary");
|
|
72
|
+
let sum = 0;
|
|
73
|
+
for (const byte of header) sum += byte;
|
|
74
|
+
header.write(`${sum.toString(8).padStart(6, "0")}\0 `, 148, "binary");
|
|
75
|
+
return header;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** A PAX record, `<length> <key>=<value>
|
|
79
|
+
`, its length counting itself. */
|
|
80
|
+
function paxRecord(key, value) {
|
|
81
|
+
const body = ` ${key}=${value}
|
|
82
|
+
`;
|
|
83
|
+
const bytes = Buffer.byteLength(body);
|
|
84
|
+
let length = bytes + String(bytes).length;
|
|
85
|
+
if (String(length).length !== String(bytes).length) length = bytes + String(length).length;
|
|
86
|
+
return `${length}${body}`;
|
|
87
|
+
}
|
|
88
|
+
|
|
42
89
|
/**
|
|
43
90
|
* The one regular file in a tar archive, or why there is not exactly one.
|
|
44
91
|
* PAX extended headers are skipped; a folder, a link or a second file is
|
package/src/deep-scan/verify.mjs
CHANGED
|
@@ -16,10 +16,12 @@ import {
|
|
|
16
16
|
DISCOVERED,
|
|
17
17
|
fence,
|
|
18
18
|
groundingLines,
|
|
19
|
+
removedLines,
|
|
19
20
|
SETUP_DONE,
|
|
20
21
|
SKILL_DIR,
|
|
21
22
|
threatPackAndRecipe,
|
|
22
23
|
} from "./agent.mjs";
|
|
24
|
+
import { textFor } from "./harness-text.mjs";
|
|
23
25
|
|
|
24
26
|
export const VERIFY_DOCS_URL = `https://github.com/mnaimfaizy/agent-kit/blob/v${CLI_VERSION}/docs/security-audit.md#verification-run`;
|
|
25
27
|
|
|
@@ -197,10 +199,12 @@ const lfOf = (text) => text.replace(/\r\n?/g, "\n");
|
|
|
197
199
|
* grounding: Array<{ source: string, at: string }>,
|
|
198
200
|
* paths: { workspace: string, grounding: string, report: string },
|
|
199
201
|
* discovers?: boolean,
|
|
202
|
+
* harness?: string,
|
|
200
203
|
* }} opts `discovers`: Claude Code runs without `--bare` (the
|
|
201
204
|
* subscription path), so the brief says what it discovers.
|
|
202
205
|
*/
|
|
203
206
|
export function verificationBrief({
|
|
207
|
+
harness = "claude-code",
|
|
204
208
|
ref,
|
|
205
209
|
short,
|
|
206
210
|
findings,
|
|
@@ -215,7 +219,7 @@ export function verificationBrief({
|
|
|
215
219
|
return [
|
|
216
220
|
"# Verification run brief, from the agent-kit deep-scan launcher",
|
|
217
221
|
"",
|
|
218
|
-
|
|
222
|
+
`This is the launcher's brief. You are running inside the closed, disposable sandbox that \`agent-kit deep-scan --verify\` started for a Verification run: re-attempt the Reproduction of each finding in the finding file, by the Verification-run procedure below, and nothing more. Your only network route is the launcher's model proxy, and ${textFor(harness).webOff}.`,
|
|
219
223
|
"",
|
|
220
224
|
"## Where things are",
|
|
221
225
|
"",
|
|
@@ -224,6 +228,7 @@ export function verificationBrief({
|
|
|
224
228
|
...findings.map((f) => ` - \`${f.conceptId}\` at ${f.location}`),
|
|
225
229
|
...groundingLines(grounding, paths),
|
|
226
230
|
`- The report: write it to \`${paths.report}\`, in the Verification-run variant of the report format below, early, and update it as each answer lands. It is the only file that leaves the sandbox.`,
|
|
231
|
+
...removedLines(harness, paths),
|
|
227
232
|
SETUP_DONE,
|
|
228
233
|
...(discovers ? [DISCOVERED] : []),
|
|
229
234
|
"",
|