@raytrace-cli/cli 0.17.17 → 0.18.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/bin/raytrace.mjs +8 -1
- package/package.json +5 -1
- package/src/local-sandbox.mjs +21 -5
- package/src/update-check.mjs +113 -0
- package/worker/sandbox/CORE_API.md +167 -0
- package/worker/sandbox/Dockerfile +7 -1
- package/worker/sandbox/agents.json +4 -0
- package/worker/sandbox/catalog_numbers.py +144 -0
- package/worker/sandbox/core/__init__.py +36 -0
- package/worker/sandbox/core/mechanics.py +882 -0
- package/worker/sandbox/core/release.py +90 -0
- package/worker/sandbox/engine.py +20 -7
- package/worker/sandbox/network.py +36 -4
- package/worker/sandbox/projects.py +8 -726
- package/worker/sandbox/setup.py +149 -21
- package/worker/sandbox/test_capture.py +0 -439
- package/worker/sandbox/test_dns_asker.py +0 -102
- package/worker/sandbox/transcript-delivery.test.mjs +0 -153
package/bin/raytrace.mjs
CHANGED
|
@@ -19,7 +19,8 @@ On this machine:
|
|
|
19
19
|
raytrace doctor what this machine has and lacks
|
|
20
20
|
raytrace uninstall [--purge] [--yes] stop RayTrace and remove the Claude Code hook; --purge
|
|
21
21
|
also deletes the local sandbox VM and ~/.raytrace
|
|
22
|
-
raytrace --version | -v print the installed version
|
|
22
|
+
raytrace --version | -v print the installed version (a newer published one is
|
|
23
|
+
noted on each command; RAYTRACE_NO_UPDATE_CHECK=1: don't)
|
|
23
24
|
|
|
24
25
|
Get started in the cloud (preview):
|
|
25
26
|
1. raytrace auth login sign in, or create your account, in the browser
|
|
@@ -146,6 +147,12 @@ if (command === 'mcp') {
|
|
|
146
147
|
process.exit(0);
|
|
147
148
|
}
|
|
148
149
|
|
|
150
|
+
// A newer published version: one line on stderr, from what the registry last said (src/update-check.mjs).
|
|
151
|
+
{
|
|
152
|
+
const { checkForUpdate } = await import('../src/update-check.mjs');
|
|
153
|
+
checkForUpdate(command);
|
|
154
|
+
}
|
|
155
|
+
|
|
149
156
|
if (!command || command === 'help' || command === '--help' || command === '-h') { console.log(HELP); process.exit(0); }
|
|
150
157
|
|
|
151
158
|
// `raytrace --code <code>` (also `raytrace code <code>`): redeem a beta code.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raytrace-cli/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
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",
|
|
@@ -17,6 +17,10 @@
|
|
|
17
17
|
"src/",
|
|
18
18
|
"proxy/",
|
|
19
19
|
"worker/",
|
|
20
|
+
"!worker/**/test_*.py",
|
|
21
|
+
"!worker/**/*.test.mjs",
|
|
22
|
+
"!worker/**/__pycache__/",
|
|
23
|
+
"!worker/**/*.pyc",
|
|
20
24
|
"dist/dashboard/",
|
|
21
25
|
"THIRD_PARTY_NOTICES.md"
|
|
22
26
|
],
|
package/src/local-sandbox.mjs
CHANGED
|
@@ -106,12 +106,25 @@ export function vmStatus() {
|
|
|
106
106
|
return line ? line.split(' ')[1] : null;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
for (const entry of readdirSync(
|
|
113
|
-
|
|
109
|
+
/** Every file setup.py installs from (the core/ package too), by path from SOURCE, sorted. */
|
|
110
|
+
export function setupFiles(folder = SOURCE, prefix = '') {
|
|
111
|
+
const found = [];
|
|
112
|
+
for (const entry of readdirSync(join(folder, prefix), { withFileTypes: true })) {
|
|
113
|
+
// A __pycache__ or cache left by running the tests there is no part of what is installed.
|
|
114
|
+
if (entry.name.startsWith('.') || entry.name === '__pycache__') continue;
|
|
115
|
+
const path = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
116
|
+
if (entry.isDirectory()) found.push(...setupFiles(folder, path));
|
|
117
|
+
else if (entry.isFile()) found.push(path);
|
|
114
118
|
}
|
|
119
|
+
return found.sort();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** This CLI's package version, which is the sandbox core's. */
|
|
123
|
+
export const packageVersion = () => JSON.parse(readFileSync(join(paths.root, 'package.json'), 'utf8')).version;
|
|
124
|
+
|
|
125
|
+
export function setupVersion(folder = SOURCE) {
|
|
126
|
+
const hash = createHash('sha256');
|
|
127
|
+
for (const path of setupFiles(folder)) hash.update(path).update(readFileSync(join(folder, path)));
|
|
115
128
|
return hash.digest('hex').slice(0, 16);
|
|
116
129
|
}
|
|
117
130
|
|
|
@@ -138,6 +151,9 @@ function installInVm(version) {
|
|
|
138
151
|
inVm(['rm', '-rf', '/tmp/raytrace-sandbox-source']);
|
|
139
152
|
limactl(['shell', '--workdir', '/', VM, 'mkdir', '-p', '/tmp/raytrace-sandbox-source']);
|
|
140
153
|
limactl(['copy', '-r', `${SOURCE}/.`, `${VM}:/tmp/raytrace-sandbox-source/`]);
|
|
154
|
+
// Only worker/sandbox is copied, not package.json: the core learns its version from this
|
|
155
|
+
// (core.version()), which names the image it builds and what `projects.py version` reports.
|
|
156
|
+
inVm(['sh', '-c', 'cat > /tmp/raytrace-sandbox-source/VERSION'], { input: `${packageVersion()}\n` });
|
|
141
157
|
inVm(['python3', '/tmp/raytrace-sandbox-source/setup.py'], { log: true });
|
|
142
158
|
inVm(['sh', '-c', `echo ${version} > ${SETUP_MARK}`]);
|
|
143
159
|
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// A one-line notice, on every command run at a terminal, while a newer
|
|
2
|
+
// RayTrace is published than the one running:
|
|
3
|
+
//
|
|
4
|
+
// RayTrace 0.19.0 is available (you have 0.18.0). Update: npm install -g @raytrace-cli/cli@latest
|
|
5
|
+
//
|
|
6
|
+
// No command waits for it. What the registry last said is kept in the
|
|
7
|
+
// RayTrace home (update-check.json); when that is older than a day, a
|
|
8
|
+
// detached process asks the registry again for next time. The notice goes to
|
|
9
|
+
// stderr, so piped output is untouched, and never shows for the Claude Code
|
|
10
|
+
// hook, the MCP server, CI, a run that is not at a terminal, a checkout of the
|
|
11
|
+
// repository, or with RAYTRACE_NO_UPDATE_CHECK=1.
|
|
12
|
+
import { spawn } from 'node:child_process';
|
|
13
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
import { fileURLToPath } from 'node:url';
|
|
16
|
+
import { paths } from './paths.mjs';
|
|
17
|
+
|
|
18
|
+
export const PACKAGE = '@raytrace-cli/cli';
|
|
19
|
+
export const REGISTRY = `https://registry.npmjs.org/${PACKAGE}/latest`;
|
|
20
|
+
const CACHE = 'update-check.json';
|
|
21
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
22
|
+
|
|
23
|
+
const STABLE = /^(\d+)\.(\d+)\.(\d+)$/;
|
|
24
|
+
/** Whether stable version `a` is newer than `b`; false for anything that is not x.y.z. */
|
|
25
|
+
export function newer(a, b) {
|
|
26
|
+
const [x, y] = [STABLE.exec(String(a)), STABLE.exec(String(b))];
|
|
27
|
+
if (!x || !y) return false;
|
|
28
|
+
for (let i = 1; i <= 3; i++) if (Number(x[i]) !== Number(y[i])) return Number(x[i]) > Number(y[i]);
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** How this copy was installed, by where it runs from: npm, pip, npx, or a source checkout. */
|
|
33
|
+
export function installKind(root) {
|
|
34
|
+
const where = String(root).replace(/\\/g, '/');
|
|
35
|
+
if (existsSync(join(root, '.git'))) return 'checkout';
|
|
36
|
+
if (where.includes('/_npx/')) return 'npx';
|
|
37
|
+
if (/\/(site|dist)-packages\/raytrace\/app\/?$/.test(where)) return 'pip';
|
|
38
|
+
return 'npm';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const updateCommand = (kind) => ({
|
|
42
|
+
npm: `npm install -g ${PACKAGE}@latest`,
|
|
43
|
+
pip: 'pip install --upgrade raytrace-cli',
|
|
44
|
+
npx: `npx ${PACKAGE}@latest`,
|
|
45
|
+
})[kind];
|
|
46
|
+
|
|
47
|
+
export const notice = (latest, current, kind) =>
|
|
48
|
+
`RayTrace ${latest} is available (you have ${current}). Update: ${updateCommand(kind)}`;
|
|
49
|
+
|
|
50
|
+
function readCache(home) {
|
|
51
|
+
try { return JSON.parse(readFileSync(join(home, CACHE), 'utf8')); } catch { return {}; }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Whether this run should say anything at all. */
|
|
55
|
+
export function quiet(command, env, stderr) {
|
|
56
|
+
const off = (value) => value === '1' || value === 'true';
|
|
57
|
+
return ['hook', 'mcp'].includes(command) || off(env.RAYTRACE_NO_UPDATE_CHECK)
|
|
58
|
+
|| (typeof env.CI === 'string' && env.CI !== '') || !stderr?.isTTY;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Prints the notice when the cached latest version is newer than this one,
|
|
63
|
+
* and starts a background refresh when the cache is a day old. Returns the
|
|
64
|
+
* line printed, or null. Never throws. `deps` is for tests.
|
|
65
|
+
*/
|
|
66
|
+
export function checkForUpdate(command, deps = {}) {
|
|
67
|
+
try {
|
|
68
|
+
const env = deps.env ?? process.env;
|
|
69
|
+
const stderr = deps.stderr ?? process.stderr;
|
|
70
|
+
const root = deps.root ?? paths.root;
|
|
71
|
+
const home = deps.home ?? paths.home;
|
|
72
|
+
const now = deps.now ?? Date.now();
|
|
73
|
+
if (quiet(command, env, stderr)) return null;
|
|
74
|
+
const kind = installKind(root);
|
|
75
|
+
if (kind === 'checkout') return null;
|
|
76
|
+
const current = deps.current ?? JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')).version;
|
|
77
|
+
const cache = readCache(home);
|
|
78
|
+
if (!(cache.checked_at > now - DAY_MS)) (deps.refresh ?? refreshInBackground)(home);
|
|
79
|
+
if (!newer(cache.latest, current)) return null;
|
|
80
|
+
const line = notice(cache.latest, current, kind);
|
|
81
|
+
(deps.log ?? ((text) => stderr.write(`${text}\n`)))(line);
|
|
82
|
+
return line;
|
|
83
|
+
} catch {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Asks the registry in a detached process, which outlives this command and writes the cache. */
|
|
89
|
+
function refreshInBackground(home) {
|
|
90
|
+
const child = spawn(process.execPath, [fileURLToPath(import.meta.url), '--refresh', home], {
|
|
91
|
+
detached: true, stdio: 'ignore', env: { ...process.env, RAYTRACE_NO_UPDATE_CHECK: '1' },
|
|
92
|
+
});
|
|
93
|
+
child.unref();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The registry's latest version, written to the cache with the time asked; the time is written on failure too. */
|
|
97
|
+
export async function refresh(home, fetcher = fetch) {
|
|
98
|
+
let latest = readCache(home).latest ?? null;
|
|
99
|
+
try {
|
|
100
|
+
const response = await fetcher(REGISTRY, { signal: AbortSignal.timeout(5000), headers: { accept: 'application/json' } });
|
|
101
|
+
if (response.ok) {
|
|
102
|
+
const version = (await response.json())?.version;
|
|
103
|
+
if (STABLE.test(String(version))) latest = version;
|
|
104
|
+
}
|
|
105
|
+
} catch { /* offline: ask again tomorrow */ }
|
|
106
|
+
mkdirSync(home, { recursive: true });
|
|
107
|
+
writeFileSync(join(home, CACHE), `${JSON.stringify({ checked_at: Date.now(), latest })}\n`);
|
|
108
|
+
return latest;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (process.argv[2] === '--refresh' && process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
112
|
+
await refresh(process.argv[3]);
|
|
113
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# Sandbox core API
|
|
2
|
+
|
|
3
|
+
`worker/sandbox/` is the sandbox core: everything that runs on a sandbox host to
|
|
4
|
+
run gVisor sandboxes and record them. The local adapter (`projects.py`, driven by
|
|
5
|
+
`raytrace sandbox ... --local` in a Lima VM) is one user. Other host layers can
|
|
6
|
+
import it as a library and add their own actions.
|
|
7
|
+
|
|
8
|
+
The core **applies** what it is given: limits, an image, hooks, files. It never
|
|
9
|
+
**decides** them. It knows nothing about accounts, plans, quotas or how a host is
|
|
10
|
+
reached.
|
|
11
|
+
|
|
12
|
+
## Versions
|
|
13
|
+
|
|
14
|
+
| Constant | Where | Covers |
|
|
15
|
+
|---|---|---|
|
|
16
|
+
| `CORE_API` | `core/__init__.py` | The functions below: arguments, results, errors and side effects. |
|
|
17
|
+
| `EVIDENCE_SCHEMA` | `core/__init__.py` | What the recorder hands on: collector events, the fact engine's facts, `syscall_catalog.sql`. |
|
|
18
|
+
| `version()` | `core/__init__.py` | The package version: from `package.json`, or the `VERSION` file that `setup.py` writes beside an installed copy. |
|
|
19
|
+
|
|
20
|
+
Raise a constant when a consumer would notice the change. The two are separate:
|
|
21
|
+
compatible evidence does not mean compatible functions, and the reverse is also
|
|
22
|
+
true. **v1 is the behaviour as of this file's introduction, written down.**
|
|
23
|
+
|
|
24
|
+
## `core.mechanics` (`CORE_API` 1)
|
|
25
|
+
|
|
26
|
+
Sandbox ids are `rtp-<32 hex>` (project) and `rtf-<32 hex>` (Playground fork).
|
|
27
|
+
Unless noted, a function raises `ValueError` on bad input and
|
|
28
|
+
`subprocess.CalledProcessError` when Docker fails.
|
|
29
|
+
|
|
30
|
+
### Configuration
|
|
31
|
+
- `Limits(cpus='2', memory='2g', pids=256, tmp='512m')`: what a sandbox may use.
|
|
32
|
+
It validates strictly; `.args()` gives the `docker create` flags.
|
|
33
|
+
`DEFAULT_LIMITS` holds today's values.
|
|
34
|
+
- `image()`: the image used when the caller names none. In order:
|
|
35
|
+
1. the active release's `image`;
|
|
36
|
+
2. `/etc/raytace/image`;
|
|
37
|
+
3. `raytace-gvisor-agent`.
|
|
38
|
+
- `bridge()`: the bridge URL sandboxes are given, as `RAYTRACE_BROKER`.
|
|
39
|
+
- `container_args(name, labels, limits=None, image_name=None)`: the one container
|
|
40
|
+
configuration used for projects and forks. It sets:
|
|
41
|
+
- the `raytace-gvisor` runtime and the `raytace-egress` network;
|
|
42
|
+
- no capabilities, `no-new-privileges`, and user 1000;
|
|
43
|
+
- the two volumes and the host resolver;
|
|
44
|
+
- the session environment.
|
|
45
|
+
- `create_container(name, labels, limits=None, image_name=None)`: makes the
|
|
46
|
+
volumes and the container, without starting it. Returns the container id.
|
|
47
|
+
|
|
48
|
+
### Lifecycle
|
|
49
|
+
- `preflight()`: the collector and resolver must be running, otherwise
|
|
50
|
+
`SystemExit`. It then runs `network.py`.
|
|
51
|
+
- `create(sid, archive, limits=None, expect_release=None)`: creates a project
|
|
52
|
+
sandbox from a staged `/tmp/<sid>.tar.gz` and returns its container id.
|
|
53
|
+
- With `expect_release`, it holds `core.release.lock(shared=True)` from the
|
|
54
|
+
check until the container exists.
|
|
55
|
+
- It raises `SystemExit` if the active release is a different one, before
|
|
56
|
+
creating anything.
|
|
57
|
+
- The container is made from the release's image and labelled
|
|
58
|
+
`io.raytace.release=<id>`.
|
|
59
|
+
- `stage_archive(sid)`: writes the archive from stdin to `/tmp/<sid>.tar.gz`
|
|
60
|
+
(up to 300 MiB).
|
|
61
|
+
- `validate_archive(path)`: accepts only regular files with relative paths,
|
|
62
|
+
256 MiB in total.
|
|
63
|
+
- `start(sid)`: starts the sandbox so it is recorded, and is safe on a running
|
|
64
|
+
sandbox. In order:
|
|
65
|
+
1. `preflight()`.
|
|
66
|
+
2. If the sandbox started before the collector did, restart it.
|
|
67
|
+
3. Lock its restricted files while it is stopped.
|
|
68
|
+
4. Put back its hook and lists from the host's copies.
|
|
69
|
+
5. Call `remember()`.
|
|
70
|
+
- `shell(sid, agent=None)`: an interactive bash in a started sandbox, optionally
|
|
71
|
+
starting `claude` or `codex` first. Returns its exit code.
|
|
72
|
+
- `stop(sid)`.
|
|
73
|
+
- `delete(sid, forget_evidence=False)`: the sandbox must be stopped. Removes:
|
|
74
|
+
- the container;
|
|
75
|
+
- its two volumes, but only ones labelled as its own;
|
|
76
|
+
- the host's copies of its hook and guardrails;
|
|
77
|
+
- with `forget_evidence`, the collector's records of it.
|
|
78
|
+
|
|
79
|
+
It then calls every function registered with `register_delete_cleanup(fn)`,
|
|
80
|
+
as `fn(sid)`.
|
|
81
|
+
- `listing()`: every managed container, as
|
|
82
|
+
`{id, container_id, status, created, persistent_volumes, size_bytes, fork_of, release, image}`.
|
|
83
|
+
- `remember(name)`: tells the fact engine which container is which sandbox.
|
|
84
|
+
- `predates_collector(state)`.
|
|
85
|
+
|
|
86
|
+
### Inside the sandbox
|
|
87
|
+
- `install_claude_hooks(container, hook)`: installs, owned by root:
|
|
88
|
+
- the hook script;
|
|
89
|
+
- Claude Code's managed settings;
|
|
90
|
+
- Codex's managed config.
|
|
91
|
+
- `enable_claude(sid, hook)`: does the same, and keeps the host's copy that
|
|
92
|
+
`start()` puts back.
|
|
93
|
+
- `set_token(sid, token)`: writes `~/.raytace/sandbox-token`, the credential the
|
|
94
|
+
hook (`claude-hook.mjs`) sends transcripts with.
|
|
95
|
+
- `write_home_files(sid, [(folder, name, bytes)])`: writes files into
|
|
96
|
+
`/home/node/<folder>/<name>`, owned by the agent user (folders 0700, files 0600).
|
|
97
|
+
- `write_as_root(container, path, bytes)`, `as_node(container, *command, data=None, check=True)`.
|
|
98
|
+
|
|
99
|
+
### Files, forks, snapshots, evidence
|
|
100
|
+
- `guardrails(sid, state, restricted=None, watched=None, blocked=None)` and
|
|
101
|
+
`set_guardrails(sid, state, request)`: restricted, watched and blocked lists.
|
|
102
|
+
Returns `{hook, read_only, restricted, watched, missing}`.
|
|
103
|
+
- `fork_action(action, fork, forget=False, credentials=None)`: handles
|
|
104
|
+
`fork-create | fork-run | fork-check | fork-collect | fork-stop | fork-delete`.
|
|
105
|
+
- `credentials` is the caller's policy for copying the parent's sign-ins into
|
|
106
|
+
a fork: a function of the request.
|
|
107
|
+
- When it is `None`, sign-ins are copied unless the request says
|
|
108
|
+
`credentials: false`.
|
|
109
|
+
- `snapshot_read(project)` and `read_snapshot(project, running)`.
|
|
110
|
+
- `evidence(container, forget=False)` and
|
|
111
|
+
`activity(container, since_ms=0, until_ms=0)`.
|
|
112
|
+
|
|
113
|
+
### Command line
|
|
114
|
+
`main(extra_actions=None, fork_credentials=None, argv=None)` is
|
|
115
|
+
`projects.py <action> [id] [--archive] [--confirm] [--release] [--since] [--until] [--forget-evidence] [--agent]`.
|
|
116
|
+
|
|
117
|
+
- `extra_actions` maps a name to `fn(opts, state)`. `state` is the sandbox's
|
|
118
|
+
`docker inspect`, or `None` when the action has no id.
|
|
119
|
+
- `version` prints `{core, core_api, evidence_schema, release, image}`, read from
|
|
120
|
+
what is installed.
|
|
121
|
+
|
|
122
|
+
## `core.release` (`CORE_API` 1)
|
|
123
|
+
|
|
124
|
+
A release is the directory `/opt/raytace/releases/<id>/` holding an immutable
|
|
125
|
+
`release.json`, with at least `{"id": <id>, "image": <tag>}`. The symlink
|
|
126
|
+
`/opt/raytace/current` is the only record of which release is active. A host
|
|
127
|
+
without it, such as a local VM, has no releases.
|
|
128
|
+
|
|
129
|
+
- `lock(shared=False)`: an `flock` on `/run/raytace/release.lock`.
|
|
130
|
+
- `active()`: the active release's manifest, or `None`.
|
|
131
|
+
- `point(target)`: switches the symlink in one rename, and returns the release
|
|
132
|
+
that was active before.
|
|
133
|
+
- `activate(target, restart, check)`: holds the exclusive lock, switches, then
|
|
134
|
+
runs `restart()` and `check()`.
|
|
135
|
+
- If either fails, it switches back, runs `restart()` again and re-raises the
|
|
136
|
+
error.
|
|
137
|
+
- If there was no previous release, it removes the symlink instead.
|
|
138
|
+
|
|
139
|
+
## Host setup (`setup.py`)
|
|
140
|
+
|
|
141
|
+
The steps run in this order, and each can run on its own:
|
|
142
|
+
`install → network → services → image → activate`. Pass `--root` for where the
|
|
143
|
+
core runs from: `/opt/raytace` locally, `/opt/raytace/current` behind releases.
|
|
144
|
+
|
|
145
|
+
`image` builds with exact `CLAUDE_CODE_VERSION` and `CODEX_VERSION`. These are
|
|
146
|
+
either given, or the tested ones in `agents.json`. It then checks
|
|
147
|
+
`claude --version` and `codex --version` in the image.
|
|
148
|
+
|
|
149
|
+
`activate` restarts the services in this order: resolver, collector, viewer.
|
|
150
|
+
It then checks:
|
|
151
|
+
- the collector's socket exists;
|
|
152
|
+
- the resolver answers on the gateway.
|
|
153
|
+
|
|
154
|
+
## Files the core owns on a host
|
|
155
|
+
|
|
156
|
+
- **The core writes:**
|
|
157
|
+
- `/etc/raytace/gvisor.json`, `resolv.conf`, `upstream-dns`, `bridge`,
|
|
158
|
+
`bridge-upstream`, `image` and `viewer-token`;
|
|
159
|
+
- the `raytace-collector`, `raytace-viewer` and `raytace-dns` units;
|
|
160
|
+
- `/var/lib/raytace/*`;
|
|
161
|
+
- `--root`.
|
|
162
|
+
- **The core only reads** `/etc/raytace/bridge-front`. It holds the port of a
|
|
163
|
+
front before the bridge on the gateway, written by a host layer that runs
|
|
164
|
+
one. Sandboxes are then pointed at the front, and both addresses count as
|
|
165
|
+
RayTrace's own.
|
|
166
|
+
- **Anything else under `/etc/raytace/`** belongs to the layer that wrote it.
|
|
167
|
+
The core never overwrites it.
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
FROM node:22-bookworm-slim
|
|
2
|
+
# Exact agent versions, always given: setup.py passes this core's tested ones
|
|
3
|
+
# (agents.json) or a host layer's pinned ones, and checks the image has them.
|
|
4
|
+
ARG CLAUDE_CODE_VERSION
|
|
5
|
+
ARG CODEX_VERSION
|
|
6
|
+
RUN test -n "$CLAUDE_CODE_VERSION" && test -n "$CODEX_VERSION" \
|
|
7
|
+
|| { echo "CLAUDE_CODE_VERSION and CODEX_VERSION are required" >&2; exit 1; }
|
|
2
8
|
RUN apt-get update && apt-get install -y --no-install-recommends git ca-certificates python3 curl ripgrep \
|
|
3
9
|
&& rm -rf /var/lib/apt/lists/*
|
|
4
|
-
RUN npm install -g @openai/codex @anthropic-ai/claude-code
|
|
10
|
+
RUN npm install -g "@openai/codex@${CODEX_VERSION}" "@anthropic-ai/claude-code@${CLAUDE_CODE_VERSION}"
|
|
5
11
|
RUN mkdir /workspace && chown node:node /workspace
|
|
6
12
|
USER node
|
|
7
13
|
WORKDIR /workspace
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"""Regenerates the two generated tables of syscall_catalog.sql from gVisor's own
|
|
2
|
+
source for the runsc release setup.py installs. Run it when that release changes.
|
|
3
|
+
|
|
4
|
+
syscall_numbers every syscall number gVisor's table has, per architecture,
|
|
5
|
+
with whether gVisor implements it (pkg/sentry/syscalls/linux/linux64.go)
|
|
6
|
+
syscall_coverage which syscalls have a typed trace point, and its optional
|
|
7
|
+
fields (pkg/sentry/seccheck/metadata_{amd64,arm64}.go);
|
|
8
|
+
the rest are reported by number and six integers only
|
|
9
|
+
|
|
10
|
+
python3 worker/sandbox/catalog_numbers.py fetch the release and rewrite the file
|
|
11
|
+
python3 worker/sandbox/catalog_numbers.py --source DIR read the three files from DIR instead
|
|
12
|
+
python3 worker/sandbox/catalog_numbers.py --spike report.json
|
|
13
|
+
also record what spike_points.py saw arrive
|
|
14
|
+
python3 worker/sandbox/catalog_numbers.py --check change nothing; say what the catalog lacks
|
|
15
|
+
|
|
16
|
+
A name gVisor has and the catalog lacks is refused: write its row first, so
|
|
17
|
+
nothing the sandbox can be asked for is without a group. What a spike observed
|
|
18
|
+
is kept across runs for the same release and forgotten for a new one.
|
|
19
|
+
"""
|
|
20
|
+
import argparse
|
|
21
|
+
import json
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
import re
|
|
24
|
+
import sqlite3
|
|
25
|
+
import sys
|
|
26
|
+
import urllib.request
|
|
27
|
+
|
|
28
|
+
RELEASE = '20260817.0'
|
|
29
|
+
RAW = 'https://raw.githubusercontent.com/google/gvisor/release-{release}/{path}'
|
|
30
|
+
SOURCES = {'linux64.go': 'pkg/sentry/syscalls/linux/linux64.go',
|
|
31
|
+
'metadata_amd64.go': 'pkg/sentry/seccheck/metadata_amd64.go',
|
|
32
|
+
'metadata_arm64.go': 'pkg/sentry/seccheck/metadata_arm64.go'}
|
|
33
|
+
CATALOG = Path(__file__).with_name('syscall_catalog.sql')
|
|
34
|
+
SUPPORT = {'Supported': 'supported', 'SupportedPoint': 'supported',
|
|
35
|
+
'PartiallySupported': 'partial', 'PartiallySupportedPoint': 'partial',
|
|
36
|
+
'Error': 'unsupported', 'ErrorWithEvent': 'unsupported', 'CapError': 'unsupported'}
|
|
37
|
+
ROW = re.compile(r'^\s+(\d+):\s+syscalls\.(\w+)\("([a-z0-9_]+)"', re.M)
|
|
38
|
+
POINT = re.compile(r'addSyscallPoint\((\d+), "([a-z0-9_]+)", (nil|\[\]FieldDesc\{.*?\n\t\})\)', re.S)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def read(name, source):
|
|
42
|
+
if source:
|
|
43
|
+
return (Path(source) / name).read_text()
|
|
44
|
+
with urllib.request.urlopen(RAW.format(release=RELEASE, path=SOURCES[name]), timeout=60) as response:
|
|
45
|
+
return response.read().decode()
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def numbers(table):
|
|
49
|
+
"""{arch: [(sysno, name, support)]} from gVisor's two syscall tables."""
|
|
50
|
+
amd, arm, end = table.index('var AMD64'), table.index('var ARM64'), table.index('func init()')
|
|
51
|
+
found = {}
|
|
52
|
+
for arch, text in (('x86_64', table[amd:arm]), ('aarch64', table[arm:end])):
|
|
53
|
+
rows = [(int(number), name, SUPPORT[kind]) for number, kind, name in ROW.findall(text)]
|
|
54
|
+
if len(rows) < 250 or len({name for _, name, _ in rows}) != len(rows):
|
|
55
|
+
raise SystemExit(f'{arch}: gVisor\'s table did not parse as expected ({len(rows)} rows)')
|
|
56
|
+
found[arch] = sorted(rows)
|
|
57
|
+
return found
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def points(*metadata):
|
|
61
|
+
"""{name: [optional field]} for every syscall with a typed trace point."""
|
|
62
|
+
found = {}
|
|
63
|
+
for text in metadata:
|
|
64
|
+
for _, name, fields in POINT.findall(text):
|
|
65
|
+
found.setdefault(name, set()).update(re.findall(r'Name:\s+"([a-z0-9_]+)"', fields))
|
|
66
|
+
if len(found) < 40:
|
|
67
|
+
raise SystemExit(f'gVisor\'s trace point list did not parse as expected ({len(found)} points)')
|
|
68
|
+
return {name: sorted(fields) for name, fields in found.items()}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def catalog(sql):
|
|
72
|
+
"""(each name the catalog has with the engine rule that reads it, what an earlier spike observed for this release)."""
|
|
73
|
+
db = sqlite3.connect(':memory:')
|
|
74
|
+
try:
|
|
75
|
+
db.executescript(sql)
|
|
76
|
+
names = dict(db.execute('SELECT syscall_name, effect_rule FROM syscall_catalog').fetchall())
|
|
77
|
+
seen = {name: (observed, fields) for name, observed, fields in db.execute(
|
|
78
|
+
'SELECT syscall_name, observed, observed_fields FROM syscall_coverage WHERE gvisor_release = ?', (RELEASE,))}
|
|
79
|
+
finally:
|
|
80
|
+
db.close()
|
|
81
|
+
return names, seen
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def quote(value):
|
|
85
|
+
return 'NULL' if value is None else str(value) if isinstance(value, int) else "'" + str(value).replace("'", "''") + "'"
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def tuples(rows, per_line):
|
|
89
|
+
text = ['(' + ', '.join(quote(value) for value in row) + ')' for row in rows]
|
|
90
|
+
return ',\n'.join(', '.join(text[start:start + per_line]) for start in range(0, len(text), per_line))
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def section(sql, name, body):
|
|
94
|
+
begin, end = f'-- BEGIN GENERATED {name}', f'-- END GENERATED {name}'
|
|
95
|
+
if begin not in sql or end not in sql:
|
|
96
|
+
raise SystemExit(f'{CATALOG.name} has no generated section named {name}')
|
|
97
|
+
head, rest = sql.split(begin, 1)
|
|
98
|
+
return head + begin + ' (catalog_numbers.py, gVisor release ' + RELEASE + '; do not edit by hand)\n' + body + '\n' + end + rest.split(end, 1)[1]
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def main():
|
|
102
|
+
parser = argparse.ArgumentParser()
|
|
103
|
+
parser.add_argument('--source', help='a folder holding linux64.go, metadata_amd64.go and metadata_arm64.go')
|
|
104
|
+
parser.add_argument('--spike', help='the report spike_points.py wrote')
|
|
105
|
+
parser.add_argument('--check', action='store_true')
|
|
106
|
+
opts = parser.parse_args()
|
|
107
|
+
sql = CATALOG.read_text()
|
|
108
|
+
table = numbers(read('linux64.go', opts.source))
|
|
109
|
+
typed = points(read('metadata_amd64.go', opts.source), read('metadata_arm64.go', opts.source))
|
|
110
|
+
known, seen = catalog(sql)
|
|
111
|
+
names = sorted({name for rows in table.values() for _, name, _ in rows})
|
|
112
|
+
missing = [name for name in names if name not in known]
|
|
113
|
+
if missing:
|
|
114
|
+
raise SystemExit('The catalog has no row for: ' + ' '.join(missing))
|
|
115
|
+
if opts.spike:
|
|
116
|
+
report = json.loads(Path(opts.spike).read_text())
|
|
117
|
+
if report.get('release') != RELEASE:
|
|
118
|
+
raise SystemExit(f"That spike ran release {report.get('release')}, not {RELEASE}")
|
|
119
|
+
arrived = report.get('observed', {})
|
|
120
|
+
for name, call in arrived.items():
|
|
121
|
+
if name in known:
|
|
122
|
+
seen[name] = (1, json.dumps(sorted(call.get('fields', []))))
|
|
123
|
+
# Silence counts against a call only when the spike's work made that
|
|
124
|
+
# kind of call and none of its kind arrived: a program that deletes
|
|
125
|
+
# with unlinkat says nothing about unlink.
|
|
126
|
+
heard = {known[name] for name in arrived if name in known}
|
|
127
|
+
for name in report.get('subscribed', []):
|
|
128
|
+
if name not in arrived and known.get(name) in report.get('exercised_rules', []) and known[name] not in heard:
|
|
129
|
+
seen[name] = (0, '[]')
|
|
130
|
+
if opts.check:
|
|
131
|
+
print(f'{len(names)} syscall names in gVisor {RELEASE}, all in the catalog; {len(typed)} have a typed trace point.')
|
|
132
|
+
return
|
|
133
|
+
sql = section(sql, 'numbers', 'DELETE FROM syscall_numbers;\nINSERT INTO syscall_numbers (arch, sysno, syscall_name, support) VALUES\n'
|
|
134
|
+
+ tuples([(arch, number, name, support) for arch, rows in table.items() for number, name, support in rows], 3) + ';')
|
|
135
|
+
coverage = [(RELEASE, name, 'syscall/' + name if name in typed else None, json.dumps(typed.get(name, [])),
|
|
136
|
+
seen.get(name, (None, '[]'))[0], seen.get(name, (None, '[]'))[1]) for name in names]
|
|
137
|
+
sql = section(sql, 'coverage', 'DELETE FROM syscall_coverage;\nINSERT INTO syscall_coverage (gvisor_release, syscall_name, point, optional_fields, observed, observed_fields) VALUES\n'
|
|
138
|
+
+ tuples(coverage, 2) + ';')
|
|
139
|
+
CATALOG.write_text(sql)
|
|
140
|
+
print(f'{CATALOG.name}: {sum(len(rows) for rows in table.values())} numbers, {len(coverage)} coverage rows for gVisor {RELEASE}.', file=sys.stderr)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
if __name__ == '__main__':
|
|
144
|
+
main()
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""The RayTrace sandbox core: what runs on a sandbox host, as a library.
|
|
2
|
+
|
|
3
|
+
Two versions are kept, and checked separately by anything that runs on this core:
|
|
4
|
+
|
|
5
|
+
CORE_API the functions a host layer imports from core.mechanics and
|
|
6
|
+
core.release (arguments, results, errors, side effects),
|
|
7
|
+
written down in CORE_API.md
|
|
8
|
+
EVIDENCE_SCHEMA what the recorder hands on: the collector's event shapes,
|
|
9
|
+
the fact engine's facts and the syscall catalog
|
|
10
|
+
|
|
11
|
+
Raise one when what it covers changes in a way a consumer would notice.
|
|
12
|
+
"""
|
|
13
|
+
import json
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
|
|
16
|
+
CORE_API = 1
|
|
17
|
+
EVIDENCE_SCHEMA = 1
|
|
18
|
+
|
|
19
|
+
_HERE = Path(__file__).resolve().parent
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def version():
|
|
23
|
+
"""This core's package version: from the package it ships in, or the
|
|
24
|
+
VERSION file setup.py writes beside the installed copy; None if neither."""
|
|
25
|
+
for candidate in (_HERE.parent.parent.parent / 'package.json', _HERE.parent / 'VERSION'):
|
|
26
|
+
try:
|
|
27
|
+
text = candidate.read_text()
|
|
28
|
+
except OSError:
|
|
29
|
+
continue
|
|
30
|
+
if candidate.suffix == '.json':
|
|
31
|
+
data = json.loads(text)
|
|
32
|
+
if data.get('name') == '@raytrace-cli/cli':
|
|
33
|
+
return data.get('version')
|
|
34
|
+
elif text.strip():
|
|
35
|
+
return text.strip()
|
|
36
|
+
return None
|