@raytrace-cli/cli 0.22.4 → 0.22.5
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/bin/raytrace.mjs +14 -2
- package/package.json +1 -1
- package/src/master.mjs +116 -0
- package/src/mcp.mjs +4 -2
- package/src/sandbox.mjs +48 -19
- package/worker/sandbox/CORE_API.md +7 -6
- package/worker/sandbox/Dockerfile +22 -3
- package/worker/sandbox/core/mechanics.py +49 -17
package/bin/raytrace.mjs
CHANGED
|
@@ -30,9 +30,12 @@ Get started in the cloud (preview):
|
|
|
30
30
|
|
|
31
31
|
Cloud sandboxes:
|
|
32
32
|
raytrace auth login|status|logout your RayTrace sign-in
|
|
33
|
-
raytrace sandbox create [--name <name>] [--size small|medium|large] [--env-profile <name>]
|
|
33
|
+
raytrace sandbox create [--name <name>] [--size small|medium|large] [--from-master <name>] [--env-profile <name>]
|
|
34
34
|
upload this Git repository to a new sandbox
|
|
35
|
-
(up to 200 MiB, 25 MiB a file, 20,000 files; default: small
|
|
35
|
+
(up to 200 MiB, 25 MiB a file, 20,000 files; default: small;
|
|
36
|
+
or --master --name <name> for an org master sandbox)
|
|
37
|
+
raytrace sandbox masters | publish <master> | delete-master <master> [--yes]
|
|
38
|
+
list, publish, or delete org master sandboxes (/opt/env)
|
|
36
39
|
raytrace sandbox env-profile [id] [<name> | --detach]
|
|
37
40
|
view, attach, or detach a cloud sandbox's env profile
|
|
38
41
|
raytrace env-profile list | create <name> | delete <id-or-name>
|
|
@@ -239,6 +242,12 @@ if (command === 'sandbox') {
|
|
|
239
242
|
remove: { type: 'string', multiple: true },
|
|
240
243
|
'env-profile': { type: 'string' },
|
|
241
244
|
detach: { type: 'boolean' },
|
|
245
|
+
master: { type: 'boolean' },
|
|
246
|
+
'from-master': { type: 'string' },
|
|
247
|
+
'default-env-profile': { type: 'string' },
|
|
248
|
+
description: { type: 'string' },
|
|
249
|
+
empty: { type: 'boolean' },
|
|
250
|
+
'no-wait': { type: 'boolean' },
|
|
242
251
|
} });
|
|
243
252
|
} catch (error) { console.error(`${error.message}\n\nRun \`raytrace help\` for usage.`); process.exit(2); }
|
|
244
253
|
const [sub, id, extraArg] = parsed.positionals;
|
|
@@ -256,6 +265,9 @@ if (command === 'sandbox') {
|
|
|
256
265
|
files: () => sandbox.files(id, parsed.values),
|
|
257
266
|
repos: () => sandbox.repos(id, parsed.values),
|
|
258
267
|
'env-profile': () => sandbox.envProfile(id, extraArg, parsed.values),
|
|
268
|
+
masters: async () => (await import('../src/master.mjs')).listMasters(),
|
|
269
|
+
publish: async () => (await import('../src/master.mjs')).publishMaster(id, parsed.values),
|
|
270
|
+
'delete-master': async () => (await import('../src/master.mjs')).deleteMaster(id, parsed.values),
|
|
259
271
|
};
|
|
260
272
|
const action = actions[sub];
|
|
261
273
|
if (!sub) { console.error(SANDBOX_HELP); process.exit(2); }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raytrace-cli/cli",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.5",
|
|
4
4
|
"mcpName": "io.github.Godcreatebugs/raytrace",
|
|
5
5
|
"description": "See what your coding agent did: traces, tool calls, cost and step-by-step evidence for Claude Code and Codex.",
|
|
6
6
|
"license": "MIT",
|
package/src/master.mjs
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// `raytrace sandbox masters | publish | create --master`: manage org Master Sandboxes.
|
|
2
|
+
// Master Sandboxes hold reusable dependencies in /opt/env (no personal credentials or
|
|
3
|
+
// project code) so employees can create sandboxes with pre-installed packages in <1s.
|
|
4
|
+
import { call } from './api.mjs';
|
|
5
|
+
import { confirm, interactive } from './prompt.mjs';
|
|
6
|
+
|
|
7
|
+
const say = (line = '') => console.log(line);
|
|
8
|
+
const JSON_HEADERS = { 'content-type': 'application/json' };
|
|
9
|
+
const MASTER_ID = /^mst-[a-f0-9]{32}$/;
|
|
10
|
+
const sleep = (ms) => new Promise((done) => setTimeout(done, ms));
|
|
11
|
+
|
|
12
|
+
const formatBytes = (bytes) => {
|
|
13
|
+
if (bytes == null) return '—';
|
|
14
|
+
const mib = bytes / (1024 * 1024);
|
|
15
|
+
return mib >= 1024 ? `${(mib / 1024).toFixed(1)} GiB` : `${mib.toFixed(mib < 10 ? 1 : 0)} MiB`;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
function depSummary(deps) {
|
|
19
|
+
if (!deps || typeof deps !== 'object') return '';
|
|
20
|
+
const parts = [];
|
|
21
|
+
if (Array.isArray(deps.pypi) && deps.pypi.length) parts.push(`${deps.pypi.length} PyPI`);
|
|
22
|
+
if (Array.isArray(deps.npm) && deps.npm.length) parts.push(`${deps.npm.length} npm`);
|
|
23
|
+
if (Array.isArray(deps.binaries) && deps.binaries.length) parts.push(`${deps.binaries.length} CLI`);
|
|
24
|
+
return parts.length ? ` [${parts.join(' · ')}]` : '';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function listMasters() {
|
|
28
|
+
const res = await call('GET', '/v1/masters');
|
|
29
|
+
const masters = res.masters || [];
|
|
30
|
+
if (!masters.length) {
|
|
31
|
+
say('No master sandboxes yet. Admins can create one: raytrace sandbox create --master --name <name>');
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
for (const m of masters) {
|
|
35
|
+
const snap = m.latest_snapshot || null;
|
|
36
|
+
const ver = m.active_version ? `v${m.active_version}` : 'draft';
|
|
37
|
+
const status = snap?.status || (m.active_version ? 'ready' : 'draft');
|
|
38
|
+
const size = formatBytes(snap?.size_bytes);
|
|
39
|
+
const deps = depSummary(snap?.dependencies);
|
|
40
|
+
say(`${m.id} ${m.name.padEnd(20)} ${ver.padEnd(6)} ${status.padEnd(10)} ${size.padEnd(9)}${deps}`);
|
|
41
|
+
if (m.setup_sandbox_id) say(` setup sandbox: ${m.setup_sandbox_id} (edit: raytrace connect ${m.setup_sandbox_id})`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function createMaster(flags = {}) {
|
|
46
|
+
if (flags.local) throw new Error('Master sandboxes require a hosted RayTrace account and apply to cloud sandboxes only; omit --local.');
|
|
47
|
+
const name = flags.name;
|
|
48
|
+
if (!name) throw new Error('Master sandboxes require a name: raytrace sandbox create --master --name <name>');
|
|
49
|
+
const body = {
|
|
50
|
+
name,
|
|
51
|
+
description: flags.description || '',
|
|
52
|
+
...(flags.size ? { size: flags.size } : {}),
|
|
53
|
+
...(flags['default-env-profile'] ? { default_env_profile: flags['default-env-profile'] } : {}),
|
|
54
|
+
};
|
|
55
|
+
say(`Creating master sandbox "${name}"...`);
|
|
56
|
+
const created = await call('POST', '/v1/masters', { headers: JSON_HEADERS, body: JSON.stringify(body) });
|
|
57
|
+
say(`\nMaster sandbox "${created.name}" (${created.id}) created.`);
|
|
58
|
+
if (created.setup_sandbox_id) {
|
|
59
|
+
say(`Setup sandbox: ${created.setup_sandbox_id} (running)`);
|
|
60
|
+
say(`1. Open it and install dependencies into /opt/env (pip, npm -g, CLIs):`);
|
|
61
|
+
say(` raytrace connect ${created.setup_sandbox_id}`);
|
|
62
|
+
say(`2. When ready, publish an immutable snapshot for your organization:`);
|
|
63
|
+
say(` raytrace sandbox publish ${created.name}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function resolveMasterId(ref) {
|
|
68
|
+
if (MASTER_ID.test(ref)) return ref;
|
|
69
|
+
const res = await call('GET', '/v1/masters');
|
|
70
|
+
const match = (res.masters || []).find((m) => m.name.toLowerCase() === ref.toLowerCase());
|
|
71
|
+
if (!match) throw new Error(`Master sandbox "${ref}" was not found. List available masters: raytrace sandbox masters`);
|
|
72
|
+
return match.id;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export async function publishMaster(ref, flags = {}) {
|
|
76
|
+
if (flags.local) throw new Error('Master sandboxes apply to cloud sandboxes only; omit --local.');
|
|
77
|
+
if (!ref) throw new Error('Usage: raytrace sandbox publish <master-id-or-name>');
|
|
78
|
+
const id = await resolveMasterId(ref);
|
|
79
|
+
say(`Publishing snapshot for master sandbox "${ref}" (${id})...`);
|
|
80
|
+
const job = await call('POST', `/v1/masters/${id}/publish`, { headers: JSON_HEADERS, body: '{}' });
|
|
81
|
+
const version = job.version;
|
|
82
|
+
if (flags['no-wait']) {
|
|
83
|
+
say(`Publish job queued: ${id} v${version} (status: ${job.status}).`);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const pollMs = Math.max(50, Number(process.env.RAYTRACE_PUBLISH_POLL_MS) || 1500);
|
|
87
|
+
const deadline = Date.now() + 10 * 60_000;
|
|
88
|
+
let current = job;
|
|
89
|
+
while (['queued', 'publishing'].includes(current.status) && Date.now() < deadline) {
|
|
90
|
+
await sleep(pollMs);
|
|
91
|
+
current = await call('GET', `/v1/masters/${id}/versions/${version}`);
|
|
92
|
+
}
|
|
93
|
+
if (current.status === 'failed') {
|
|
94
|
+
throw new Error(`Master publish failed: ${current.error || 'unknown error'}`);
|
|
95
|
+
}
|
|
96
|
+
if (current.status !== 'ready') {
|
|
97
|
+
throw new Error(`Timed out waiting for ${id} v${version} to publish (last status: ${current.status}).`);
|
|
98
|
+
}
|
|
99
|
+
say(`\nPublished master "${ref}" v${version} (${formatBytes(current.size_bytes)})${depSummary(current.dependencies)}.`);
|
|
100
|
+
say(`Create a sandbox from it: raytrace sandbox create --from-master ${ref}`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export async function deleteMaster(ref, flags = {}) {
|
|
104
|
+
if (flags.local) throw new Error('Master sandboxes apply to cloud sandboxes only; omit --local.');
|
|
105
|
+
if (!ref) throw new Error('Usage: raytrace sandbox delete-master <master-id-or-name> [--yes]');
|
|
106
|
+
const id = await resolveMasterId(ref);
|
|
107
|
+
if (!flags.yes) {
|
|
108
|
+
if (!interactive()) throw new Error('Pass --yes to delete a master sandbox without a prompt.');
|
|
109
|
+
if (!(await confirm(`Delete master sandbox "${ref}" (${id}) and its setup sandbox? Existing sandboxes created from it keep working.`, false))) {
|
|
110
|
+
say('Not deleted.');
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
await call('DELETE', `/v1/masters/${id}`);
|
|
115
|
+
say(`Deleted master sandbox "${ref}" (${id}).`);
|
|
116
|
+
}
|
package/src/mcp.mjs
CHANGED
|
@@ -87,6 +87,7 @@ const TOOLS = [
|
|
|
87
87
|
agent: agentSchema,
|
|
88
88
|
github: { type: 'boolean', description: "Cloud only: also make the sandbox a clone of the project's GitHub repository (its origin), on a branch its agent may push to. Needs the RayTrace GitHub App connected for the user's organization." },
|
|
89
89
|
github_repo: { type: 'string', description: 'With github: the GitHub repository to connect to instead of the origin, as owner/name.' },
|
|
90
|
+
master: { type: 'string', description: 'Cloud only: initialize /opt/env dependencies from a published organization master sandbox (by ID or name).' },
|
|
90
91
|
env_profile: { type: 'string', description: 'Cloud only: attach an encrypted organization env profile (by ID or name). Values are injected only at command/shell exec time and scrubbed from recorded traces.' },
|
|
91
92
|
without_beta_credit: { type: 'boolean', description: "Create a regular sandbox, not the user's free beta sandbox. Only after the user agrees, when create_sandbox reported their free beta sandbox expired or already created." },
|
|
92
93
|
},
|
|
@@ -345,9 +346,10 @@ function githubTarget(root, wanted, named) {
|
|
|
345
346
|
}
|
|
346
347
|
|
|
347
348
|
async function createSandbox({ path, name, local = false, install_lima: installLima = false, connect = true, agent = 'claude',
|
|
348
|
-
github: wantGithub = false, github_repo: namedRepo, env_profile: envProfile, without_beta_credit: plain = false }, step) {
|
|
349
|
+
github: wantGithub = false, github_repo: namedRepo, master, env_profile: envProfile, without_beta_credit: plain = false }, step) {
|
|
349
350
|
if (!AGENTS[agent]) throw new ToolError(`agent must be one of: ${Object.keys(AGENTS).join(', ')}.`);
|
|
350
351
|
if (local && (wantGithub || namedRepo !== undefined)) throw new ToolError('GitHub repositories connect to cloud sandboxes only; leave out github for a local sandbox.');
|
|
352
|
+
if (local && master !== undefined && master !== '') throw new ToolError('Master sandboxes apply to cloud sandboxes only; leave out master for a local sandbox.');
|
|
351
353
|
if (local && envProfile !== undefined && envProfile !== '') throw new ToolError('Env profiles apply to cloud sandboxes only; leave out env_profile for a local sandbox.');
|
|
352
354
|
const root = await projectRoot(path);
|
|
353
355
|
if (local) return createLocal(root, name, installLima, connect && agent, step);
|
|
@@ -367,7 +369,7 @@ async function createSandbox({ path, name, local = false, install_lima: installL
|
|
|
367
369
|
step('Creating the sandbox');
|
|
368
370
|
let box;
|
|
369
371
|
try {
|
|
370
|
-
box = await upload(archive, name || basename(root), useCredit, null, envProfile || null);
|
|
372
|
+
box = await upload(archive, name || basename(root), useCredit, null, envProfile || null, master || null);
|
|
371
373
|
} catch (error) {
|
|
372
374
|
if (!useCredit || !isCreditRefusal(error)) throw error;
|
|
373
375
|
throw new ToolError(`No sandbox was created: the user's free beta sandbox ${error.status === 410 ? 'expired before it was created' : 'was already created'}. `
|
package/src/sandbox.mjs
CHANGED
|
@@ -195,12 +195,28 @@ export function buildMultipartUpload(metadata, archive) {
|
|
|
195
195
|
};
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
/** Create a cloud sandbox from a packed project
|
|
199
|
-
*
|
|
200
|
-
export function upload(archive, name, useCredit, size = null, envProfile = null) {
|
|
198
|
+
/** Create a cloud sandbox from a packed project (or empty JSON body when `archive` is null
|
|
199
|
+
* and `master` is provided). A credit refusal comes back as an ApiError. */
|
|
200
|
+
export function upload(archive, name, useCredit, size = null, envProfile = null, master = null) {
|
|
201
201
|
const cleanName = name.replace(/[^A-Za-z0-9._ -]/g, '-').slice(0, 100);
|
|
202
|
-
if (
|
|
203
|
-
const metadata = {
|
|
202
|
+
if (!archive) {
|
|
203
|
+
const metadata = {
|
|
204
|
+
name: cleanName,
|
|
205
|
+
...(size ? { size } : {}),
|
|
206
|
+
...(master ? { master } : {}),
|
|
207
|
+
...(envProfile ? { env_profile: envProfile } : {}),
|
|
208
|
+
...(useCredit ? { beta_credit: true } : {}),
|
|
209
|
+
};
|
|
210
|
+
return call('POST', '/v1/sandboxes', { body: JSON.stringify(metadata), headers: JSON_HEADERS });
|
|
211
|
+
}
|
|
212
|
+
if (envProfile || master) {
|
|
213
|
+
const metadata = {
|
|
214
|
+
name: cleanName,
|
|
215
|
+
...(size ? { size } : {}),
|
|
216
|
+
...(master ? { master } : {}),
|
|
217
|
+
...(envProfile ? { env_profile: envProfile } : {}),
|
|
218
|
+
...(useCredit ? { beta_credit: true } : {}),
|
|
219
|
+
};
|
|
204
220
|
const { contentType, body } = buildMultipartUpload(metadata, archive);
|
|
205
221
|
return call('POST', '/v1/sandboxes', { body, headers: { 'content-type': contentType } });
|
|
206
222
|
}
|
|
@@ -333,29 +349,35 @@ export async function envProfile(id, profileRef, flags = {}) {
|
|
|
333
349
|
}
|
|
334
350
|
|
|
335
351
|
export async function create(flags) {
|
|
352
|
+
if (flags.master) {
|
|
353
|
+
const masterMod = await import('./master.mjs');
|
|
354
|
+
return masterMod.createMaster(flags);
|
|
355
|
+
}
|
|
356
|
+
const masterRef = flags['from-master'] || null;
|
|
336
357
|
if (flags.repo && !flags.connect) throw new Error('--repo names the GitHub repository to connect to: use it with --connect.');
|
|
337
358
|
if (flags.connect && flags.local) throw new Error('GitHub repositories connect to cloud sandboxes only.');
|
|
338
359
|
if (flags['env-profile'] && flags.local) throw new Error('Env profiles require a hosted RayTrace account and apply to cloud sandboxes only; omit --local.');
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
360
|
+
if (masterRef && flags.local) throw new Error('Master sandboxes require a hosted RayTrace account and apply to cloud sandboxes only; omit --local.');
|
|
361
|
+
const root = flags.empty ? null : repoRoot();
|
|
362
|
+
if (!root && !masterRef) throw new Error('Run this from inside a Git repository (or pass --from-master <name> to start with an empty workspace).');
|
|
363
|
+
const name = flags.name || (root ? basename(root) : `${masterRef}-sandbox`);
|
|
342
364
|
// Which GitHub repository to connect to, worked out before anything is uploaded.
|
|
343
365
|
let connecting = null;
|
|
344
366
|
if (flags.connect) {
|
|
345
|
-
const repo = flags.repo ? githubRepo(flags.repo) : localRepo(root).repo;
|
|
367
|
+
const repo = flags.repo ? githubRepo(flags.repo) : (root ? localRepo(root).repo : null);
|
|
346
368
|
if (!repo) {
|
|
347
369
|
throw new Error(flags.repo ? `Not a GitHub repository: ${flags.repo} (use owner/name)`
|
|
348
370
|
: "This repository's origin is not on GitHub. Name the one to connect to: --repo owner/name");
|
|
349
371
|
}
|
|
350
|
-
connecting = { repo, ...hereFor(repo) };
|
|
372
|
+
connecting = { repo, ...(root ? hereFor(repo) : {}) };
|
|
351
373
|
}
|
|
352
374
|
const requestedSize = flags.local ? null : validateSize(flags.size);
|
|
353
375
|
// What the machine lacks is said before the project is read, and Lima fetched if agreed.
|
|
354
376
|
const localName = flags.local ? local.sandboxName(flags, root) : null;
|
|
355
377
|
if (flags.local) await local.preflight(flags, { confirm, interactive });
|
|
356
|
-
const
|
|
378
|
+
const project = root ? listProject(root) : null;
|
|
357
379
|
// The same files, packed the same way, as a cloud sandbox gets: only the copy stays here.
|
|
358
|
-
if (flags.local) return local.create(localName, { root,
|
|
380
|
+
if (flags.local) return local.create(localName, { root, ...project, archive: await pack(root, project.files) });
|
|
359
381
|
|
|
360
382
|
// A local sandbox never uses the beta grant.
|
|
361
383
|
const { plan, beta } = await creditPlan();
|
|
@@ -367,14 +389,17 @@ export async function create(flags) {
|
|
|
367
389
|
say(`This is your free beta sandbox${betaEnds(beta) ? `, until ${formatCreditDeadline(betaEnds(beta))}` : ''}.`);
|
|
368
390
|
}
|
|
369
391
|
const useCredit = plan === 'use';
|
|
370
|
-
|
|
371
|
-
if (
|
|
372
|
-
|
|
373
|
-
|
|
392
|
+
let archive = null;
|
|
393
|
+
if (project) {
|
|
394
|
+
say(`Packing ${project.files.length} files (${(project.total / 1048576).toFixed(1)} MiB) from ${root}`);
|
|
395
|
+
if (project.skipped.length) say(`Not uploaded (${project.skipped.length}): ${project.skipped.slice(0, 8).join(', ')}${project.skipped.length > 8 ? ', ...' : ''}`);
|
|
396
|
+
archive = await packArchive(root, project.files);
|
|
397
|
+
}
|
|
398
|
+
say(`Creating the ${requestedSize || 'small'} sandbox${masterRef ? ` from master "${masterRef}"` : ''} (the first one on a host takes a little longer)...`);
|
|
374
399
|
const envProfileName = flags['env-profile'] || null;
|
|
375
400
|
let box;
|
|
376
401
|
try {
|
|
377
|
-
box = await upload(archive, name, useCredit, requestedSize, envProfileName);
|
|
402
|
+
box = await upload(archive, name, useCredit, requestedSize, envProfileName, masterRef);
|
|
378
403
|
} catch (error) {
|
|
379
404
|
if (!useCredit || !isCreditRefusal(error)) throw formatActionError(error);
|
|
380
405
|
say(error.status === 410 ? 'Your free beta sandbox expired before it was created.'
|
|
@@ -383,13 +408,16 @@ export async function create(flags) {
|
|
|
383
408
|
throw new Error('Not created as your free beta sandbox; no sandbox was created.');
|
|
384
409
|
}
|
|
385
410
|
try {
|
|
386
|
-
box = await upload(archive, name, false, requestedSize, envProfileName);
|
|
411
|
+
box = await upload(archive, name, false, requestedSize, envProfileName, masterRef);
|
|
387
412
|
} catch (retryError) {
|
|
388
413
|
throw formatActionError(retryError);
|
|
389
414
|
}
|
|
390
415
|
}
|
|
391
416
|
const actualSize = box.size || requestedSize;
|
|
392
417
|
say(`\nSandbox ${box.id}${actualSize ? ` (${actualSize})` : ''} is running.`);
|
|
418
|
+
if (box.master_name) {
|
|
419
|
+
say(`Master environment: ${box.master_name}${box.master_version ? ` v${box.master_version}` : ''} (/opt/env pre-loaded).`);
|
|
420
|
+
}
|
|
393
421
|
if (box.env_profile_name) {
|
|
394
422
|
say(`Env profile attached: ${box.env_profile_name} (injected at command/shell exec time; values scrubbed from traces).`);
|
|
395
423
|
}
|
|
@@ -425,9 +453,10 @@ export async function list(flags = {}) {
|
|
|
425
453
|
const age = Math.round((Date.now() - created) / 60000);
|
|
426
454
|
const status = box.restoring ? 'restoring' : String(box.status);
|
|
427
455
|
const size = box.size ? ` ${String(box.size).padEnd(6)}` : '';
|
|
456
|
+
const masterTag = box.master_name ? ` master:${box.master_name}${box.master_version ? `@v${box.master_version}` : ''}` : '';
|
|
428
457
|
const envTag = box.env_profile_name ? ` env:${box.env_profile_name}` : '';
|
|
429
458
|
const beta = box.beta ? ` Beta${betaEnds(box) ? ` (until ${formatCreditDeadline(betaEnds(box))})` : ''}` : '';
|
|
430
|
-
say(`${box.id} ${status.padEnd(9)}${size} ${box.name}${envTag}${beta} (${age < 120 ? `${age} min` : `${Math.round(age / 60)} h`} old)`);
|
|
459
|
+
say(`${box.id} ${status.padEnd(9)}${size} ${box.name}${masterTag}${envTag}${beta} (${age < 120 ? `${age} min` : `${Math.round(age / 60)} h`} old)`);
|
|
431
460
|
}
|
|
432
461
|
}
|
|
433
462
|
|
|
@@ -36,20 +36,21 @@ Unless noted, a function raises `ValueError` on bad input and
|
|
|
36
36
|
2. `/etc/raytace/image`;
|
|
37
37
|
3. `raytace-gvisor-agent`.
|
|
38
38
|
- `bridge()`: the bridge URL sandboxes are given, as `RAYTRACE_BROKER`.
|
|
39
|
-
- `container_args(name, labels, limits=None, image_name=None)`: the one container
|
|
39
|
+
- `container_args(name, labels, limits=None, image_name=None, env_volume=False)`: the one container
|
|
40
40
|
configuration used for projects and forks. It sets:
|
|
41
41
|
- the `raytace-gvisor` runtime and the `raytace-egress` network;
|
|
42
42
|
- no capabilities, `no-new-privileges`, and user 1000;
|
|
43
|
-
- the
|
|
43
|
+
- the workspace and home volumes (plus `<name>-env` at `/opt/env` when `env_volume=True`) and the host resolver;
|
|
44
44
|
- the session environment.
|
|
45
|
-
- `
|
|
46
|
-
|
|
45
|
+
- `seed_volume(volume_name, source_dir)`: populates a Docker volume from a host directory using `cp -a --reflink=auto`.
|
|
46
|
+
- `create_container(name, labels, limits=None, image_name=None, env_volume=False, seed_env_dir=None)`: makes the
|
|
47
|
+
volumes (seeding `<name>-env` when `seed_env_dir` is given) and the container, without starting it. Returns the container id.
|
|
47
48
|
|
|
48
49
|
### Lifecycle
|
|
49
50
|
- `preflight()`: the collector and resolver must be running, otherwise
|
|
50
51
|
`SystemExit`. It then runs `network.py`.
|
|
51
|
-
- `create(sid, archive, limits=None, expect_release=None)`: creates a project
|
|
52
|
-
sandbox
|
|
52
|
+
- `create(sid, archive=None, limits=None, expect_release=None, env_volume=False, seed_env_dir=None)`: creates a project
|
|
53
|
+
sandbox, optionally importing a staged `/tmp/<sid>.tar.gz` and/or seeding `/opt/env`, and returns its container id.
|
|
53
54
|
- With `expect_release`, it holds `core.release.lock(shared=True)` from the
|
|
54
55
|
check until the container exists.
|
|
55
56
|
- It raises `SystemExit` if the active release is a different one, before
|
|
@@ -5,10 +5,29 @@ ARG CLAUDE_CODE_VERSION
|
|
|
5
5
|
ARG CODEX_VERSION
|
|
6
6
|
RUN test -n "$CLAUDE_CODE_VERSION" && test -n "$CODEX_VERSION" \
|
|
7
7
|
|| { echo "CLAUDE_CODE_VERSION and CODEX_VERSION are required" >&2; exit 1; }
|
|
8
|
-
RUN apt-get update && apt-get install -y --no-install-recommends git ca-certificates python3 curl ripgrep \
|
|
8
|
+
RUN apt-get update && apt-get install -y --no-install-recommends git ca-certificates python3 python3-venv python3-pip curl ripgrep \
|
|
9
9
|
&& rm -rf /var/lib/apt/lists/*
|
|
10
10
|
RUN npm install -g "@openai/codex@${CODEX_VERSION}" "@anthropic-ai/claude-code@${CLAUDE_CODE_VERSION}"
|
|
11
|
-
RUN mkdir /workspace
|
|
11
|
+
RUN mkdir -p /workspace /opt/env/bin /opt/env/npm /opt/env/pnpm /opt/env/cargo /opt/env/rustup /opt/env/go /opt/env/playwright /opt/env/cache/uv /opt/env/cache/pip \
|
|
12
|
+
&& python3 -m venv /opt/env/venv \
|
|
13
|
+
&& chown -R node:node /workspace /opt/env
|
|
12
14
|
USER node
|
|
13
15
|
WORKDIR /workspace
|
|
14
|
-
|
|
16
|
+
# Keep user-installed runtimes/packages in /opt/env (mounted as a volume when
|
|
17
|
+
# persisted across sandboxes) while pinning credential config files to /home/node.
|
|
18
|
+
ENV HOME=/home/node \
|
|
19
|
+
CODEX_HOME=/home/node/.codex \
|
|
20
|
+
VIRTUAL_ENV=/opt/env/venv \
|
|
21
|
+
NPM_CONFIG_PREFIX=/opt/env/npm \
|
|
22
|
+
PNPM_HOME=/opt/env/pnpm \
|
|
23
|
+
CARGO_HOME=/opt/env/cargo \
|
|
24
|
+
RUSTUP_HOME=/opt/env/rustup \
|
|
25
|
+
GOPATH=/opt/env/go \
|
|
26
|
+
PLAYWRIGHT_BROWSERS_PATH=/opt/env/playwright \
|
|
27
|
+
UV_CACHE_DIR=/opt/env/cache/uv \
|
|
28
|
+
PIP_CACHE_DIR=/opt/env/cache/pip \
|
|
29
|
+
NPM_CONFIG_USERCONFIG=/home/node/.npmrc \
|
|
30
|
+
PIP_CONFIG_FILE=/home/node/.config/pip/pip.conf \
|
|
31
|
+
NETRC=/home/node/.netrc \
|
|
32
|
+
DOCKER_CONFIG=/home/node/.docker \
|
|
33
|
+
PATH=/opt/env/venv/bin:/opt/env/npm/bin:/opt/env/pnpm:/opt/env/bin:/opt/env/cargo/bin:/opt/env/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
|
@@ -296,17 +296,22 @@ def start_container(name):
|
|
|
296
296
|
below; starting one that already runs is a no-op."""
|
|
297
297
|
run('docker', 'start', name, stdout=subprocess.DEVNULL)
|
|
298
298
|
|
|
299
|
-
def container_args(name, labels, limits=None, image_name=None):
|
|
299
|
+
def container_args(name, labels, limits=None, image_name=None, env_volume=False):
|
|
300
300
|
"""`docker create` arguments for one sandbox: gVisor, the sandbox network,
|
|
301
|
-
no capabilities, the agent user, the given limits, its
|
|
301
|
+
no capabilities, the agent user, the given limits, its volumes and the
|
|
302
302
|
host's resolver. Projects and forks are made the same way."""
|
|
303
303
|
limits = limits or DEFAULT_LIMITS
|
|
304
|
+
mounts = [
|
|
305
|
+
'--mount=type=volume,src='+name+'-workspace,dst=/workspace',
|
|
306
|
+
'--mount=type=volume,src='+name+'-home,dst=/home/node',
|
|
307
|
+
]
|
|
308
|
+
if env_volume:
|
|
309
|
+
mounts.append('--mount=type=volume,src='+name+'-env,dst=/opt/env')
|
|
304
310
|
return ['docker', 'create', '--name', name, *labels, '--runtime=raytace-gvisor',
|
|
305
311
|
'--label', 'io.raytace.storage=volumes-v1',
|
|
306
312
|
'--network=raytace-egress', '--cap-drop=ALL', '--security-opt=no-new-privileges',
|
|
307
313
|
'--user=1000:1000', *limits.args(),
|
|
308
|
-
|
|
309
|
-
'--mount=type=volume,src='+name+'-home,dst=/home/node',
|
|
314
|
+
*mounts,
|
|
310
315
|
'--mount=type=bind,src=/etc/raytace/resolv.conf,dst=/etc/resolv.conf,readonly',
|
|
311
316
|
# Session marker on PID 1: env is inherited across fork/exec, so
|
|
312
317
|
# every process in this sandbox carries it without the collector
|
|
@@ -318,11 +323,33 @@ def container_args(name, labels, limits=None, image_name=None):
|
|
|
318
323
|
'--workdir=/workspace', '--entrypoint=/bin/sleep',
|
|
319
324
|
image_name or image(), 'infinity']
|
|
320
325
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
326
|
+
|
|
327
|
+
def seed_volume(volume_name, source_dir):
|
|
328
|
+
"""Populates a freshly created Docker volume from a host directory using
|
|
329
|
+
reflink Copy-on-Write when the filesystem supports it (`cp -a --reflink=auto`)."""
|
|
330
|
+
src = Path(source_dir)
|
|
331
|
+
if not src.is_dir():
|
|
332
|
+
raise ValueError(f'Seed directory does not exist: {source_dir}')
|
|
333
|
+
mountpoint = subprocess.check_output(
|
|
334
|
+
['docker', 'volume', 'inspect', '-f', '{{.Mountpoint}}', volume_name],
|
|
335
|
+
text=True, timeout=20,
|
|
336
|
+
).strip()
|
|
337
|
+
if not mountpoint or not Path(mountpoint).is_dir():
|
|
338
|
+
raise ValueError(f'Volume mountpoint missing for {volume_name}')
|
|
339
|
+
run('cp', '-a', '--reflink=auto', f'{src}/.', mountpoint)
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
def create_container(name, labels, limits=None, image_name=None, env_volume=False, seed_env_dir=None):
|
|
343
|
+
"""The sandbox's volumes (workspace, home, and optionally env) and its container
|
|
344
|
+
(not started); returns its container id."""
|
|
345
|
+
if seed_env_dir is not None:
|
|
346
|
+
env_volume = True
|
|
347
|
+
suffixes = ('workspace', 'home', 'env') if env_volume else ('workspace', 'home')
|
|
348
|
+
for suffix in suffixes:
|
|
324
349
|
run('docker', 'volume', 'create', *labels, name+'-'+suffix, stdout=subprocess.DEVNULL)
|
|
325
|
-
|
|
350
|
+
if seed_env_dir is not None:
|
|
351
|
+
seed_volume(name+'-env', seed_env_dir)
|
|
352
|
+
return subprocess.check_output(container_args(name, labels, limits, image_name, env_volume=env_volume), text=True).strip()
|
|
326
353
|
|
|
327
354
|
def fork_container(fork, parent, limits=None, image_name=None):
|
|
328
355
|
"""A sandbox like the project's own, for one Playground fork: same image,
|
|
@@ -529,8 +556,10 @@ def read_snapshot(project, running):
|
|
|
529
556
|
except subprocess.CalledProcessError:
|
|
530
557
|
raise SystemExit("RayTrace: this sandbox's snapshot history could not be read.") from None
|
|
531
558
|
|
|
532
|
-
def create(sid, archive, limits=None, expect_release=None):
|
|
533
|
-
"""A new project sandbox
|
|
559
|
+
def create(sid, archive=None, limits=None, expect_release=None, env_volume=False, seed_env_dir=None):
|
|
560
|
+
"""A new project sandbox, optionally importing a staged import archive into
|
|
561
|
+
/workspace. When `env_volume=True` (or `seed_env_dir` is given), mounts a
|
|
562
|
+
third `<sid>-env` volume at `/opt/env` and seeds it via reflink when given.
|
|
534
563
|
|
|
535
564
|
With `expect_release`, the sandbox is made only from that active release
|
|
536
565
|
(core/release.py): the release lock is held, shared, from the check until
|
|
@@ -538,23 +567,26 @@ def create(sid, archive, limits=None, expect_release=None):
|
|
|
538
567
|
and the container is made from that release's image."""
|
|
539
568
|
if not re.fullmatch(PROJECT_ID, sid):
|
|
540
569
|
raise ValueError('Invalid sandbox ID')
|
|
541
|
-
if
|
|
542
|
-
|
|
543
|
-
|
|
570
|
+
if archive is not None:
|
|
571
|
+
if not archive or not re.fullmatch(r'/tmp/rtp-[a-f0-9]{32}\.tar\.gz', archive):
|
|
572
|
+
raise ValueError('Expected staged import archive')
|
|
573
|
+
validate_archive(archive)
|
|
544
574
|
preflight()
|
|
545
575
|
if expect_release is None:
|
|
546
|
-
|
|
576
|
+
cid = create_container(sid, ['--label', LABEL+'='+sid], limits, env_volume=env_volume, seed_env_dir=seed_env_dir)
|
|
577
|
+
return finish_create(sid, archive, cid)
|
|
547
578
|
with release.lock(shared=True):
|
|
548
579
|
active = release.active()
|
|
549
580
|
if not active or active.get('id') != expect_release:
|
|
550
581
|
raise SystemExit(f'RayTrace: this host runs release {(active or {}).get("id") or "none"}, '
|
|
551
582
|
f'not {expect_release}; no sandbox was created.')
|
|
552
583
|
cid = create_container(sid, ['--label', LABEL+'='+sid, '--label', release.LABEL+'='+expect_release],
|
|
553
|
-
limits, active['image'])
|
|
584
|
+
limits, active['image'], env_volume=env_volume, seed_env_dir=seed_env_dir)
|
|
554
585
|
return finish_create(sid, archive, cid)
|
|
555
586
|
|
|
556
587
|
def finish_create(sid, archive, cid):
|
|
557
|
-
|
|
588
|
+
if archive is not None:
|
|
589
|
+
import_archive(cid, archive)
|
|
558
590
|
remember(sid)
|
|
559
591
|
return cid
|
|
560
592
|
|
|
@@ -760,7 +792,7 @@ def delete(sid, forget_evidence=False):
|
|
|
760
792
|
(GUARDRAILS / (sid+'.json')).unlink(missing_ok=True)
|
|
761
793
|
for cleanup in DELETE_CLEANUP:
|
|
762
794
|
cleanup(sid)
|
|
763
|
-
for suffix in ('workspace', 'home'):
|
|
795
|
+
for suffix in ('workspace', 'home', 'env'):
|
|
764
796
|
volume = sid+'-'+suffix
|
|
765
797
|
result = subprocess.run(['docker', 'volume', 'inspect', volume], capture_output=True, text=True)
|
|
766
798
|
if result.returncode == 0:
|