@zenera/sandbox 1.4.2 → 1.4.4

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/dist/base.d.ts CHANGED
@@ -4,18 +4,36 @@ import type { Runner } from './process.ts';
4
4
  * The base's version, its tag. Bump it with every change to sandboxBaseDockerfile(): CI publishes
5
5
  * a tag once and never again, and projects move to the new one on `zen check --fix`.
6
6
  */
7
- export declare const SANDBOX_BASE_VERSION = "base-1";
7
+ export declare const SANDBOX_BASE_VERSION = "base-2";
8
8
  export declare const SANDBOX_BASE_REPO = "ghcr.io/zenera-ai/zenera-sandbox";
9
9
  /**
10
10
  * The Playwright whose browser the base carries, for `zen page`: the version @zenera/browser pins
11
11
  * (a test keeps them equal), since a Playwright drives only the browser build it was made for.
12
12
  */
13
13
  export declare const PLAYWRIGHT_VERSION = "1.65.1";
14
+ /**
15
+ * The uv the base carries: Python packages are installed with `uv pip install`, which fetches
16
+ * them in parallel (pip fetches one at a time, a few minutes for a data stack on a slow link).
17
+ */
18
+ export declare const UV_VERSION = "0.13.12";
14
19
  /** Where the base keeps that browser; an ENV of the image, so every command finds it. */
15
20
  export declare const PLAYWRIGHT_BROWSERS_PATH = "/opt/ms-playwright";
21
+ /** Where the base keeps the real uv; `uv` on PATH is UV_SHIM in front of it. */
22
+ export declare const UV_REAL = "/usr/local/libexec/uv/uv";
23
+ /**
24
+ * `uv` as the base runs it. uv has no `--user` and, unlike pip, does not fall back to the user's
25
+ * own site-packages when the system's is not writable, so a model writing `uv pip install pandas`
26
+ * (or the `pip install --user` habit, as `uv pip install --user`) as an unprivileged user would
27
+ * be refused. This puts such an install where pip would: under ~/.local, which the session's
28
+ * home keeps and python finds. A location asked for (`--prefix`, `--target`, `--python`,
29
+ * `--system`) and every other command go to uv unchanged; with a virtual environment active,
30
+ * uv installs into it (UV_SYSTEM_PYTHON, the base's default, would send it to the system's).
31
+ * No single quote anywhere: the Dockerfile writes it with printf '…'.
32
+ */
33
+ export declare const UV_SHIM = "#!/bin/sh\n# The zen sandbox base: uv pip install as pip would do it, into ~/.local when the system\n# site-packages is not writable or --user is given (uv has neither). The real uv: /usr/local/libexec/uv/uv.\nreal=/usr/local/libexec/uv/uv\n# An active virtual environment is where uv installs, as pip does: UV_SYSTEM_PYTHON would\n# otherwise send every install to the system Python.\nif [ -n \"${VIRTUAL_ENV:-}\" ]; then\n exec env -u UV_SYSTEM_PYTHON \"$real\" \"$@\"\nfi\nif [ \"$1\" = pip ] && [ \"$2\" = install ]; then\n user= located=\n for a do\n shift\n case \"$a\" in\n --user) user=1; continue ;;\n --prefix|--prefix=*|--target|--target=*|-t|--python|--python=*|-p|--system) located=1 ;;\n esac\n set -- \"$@\" \"$a\"\n done\n if [ -z \"$located\" ] && { [ -n \"$user\" ] || [ ! -w \"$(python3 -c \"import site; print(site.getsitepackages()[0])\")\" ]; }; then\n shift 2\n exec \"$real\" pip install --prefix \"${HOME:-/tmp}/.local\" \"$@\"\n fi\nfi\nexec \"$real\" \"$@\"\n";
16
34
  /**
17
35
  * Shell that fails unless `python` and `python3` are both on PATH and are one interpreter:
18
- * a script's `#!/usr/bin/env python` must run where `python3 -m pip install` put its packages.
36
+ * a script's `#!/usr/bin/env python` must run where `uv pip install` put its packages.
19
37
  * Every image zen builds passes it (the base, a project's sandbox image, an agent image).
20
38
  */
21
39
  export declare const SAME_PYTHON_CHECK: string;
package/dist/base.js CHANGED
@@ -26,7 +26,7 @@ import { join } from 'node:path';
26
26
  * The base's version, its tag. Bump it with every change to sandboxBaseDockerfile(): CI publishes
27
27
  * a tag once and never again, and projects move to the new one on `zen check --fix`.
28
28
  */
29
- export const SANDBOX_BASE_VERSION = 'base-1';
29
+ export const SANDBOX_BASE_VERSION = 'base-2';
30
30
  export const SANDBOX_BASE_REPO = 'ghcr.io/zenera-ai/zenera-sandbox';
31
31
  /** `FROM [--platform=…] ghcr.io/zenera-ai/zenera-sandbox:<version>`: the version is the tag. */
32
32
  const BASE_FROM = /^\s*FROM\s+(?:--platform=\S+\s+)?ghcr\.io\/zenera-ai\/zenera-sandbox:([^\s@]+)/gim;
@@ -35,12 +35,65 @@ const BASE_FROM = /^\s*FROM\s+(?:--platform=\S+\s+)?ghcr\.io\/zenera-ai\/zenera-
35
35
  * (a test keeps them equal), since a Playwright drives only the browser build it was made for.
36
36
  */
37
37
  export const PLAYWRIGHT_VERSION = '1.65.1';
38
+ /**
39
+ * The uv the base carries: Python packages are installed with `uv pip install`, which fetches
40
+ * them in parallel (pip fetches one at a time, a few minutes for a data stack on a slow link).
41
+ */
42
+ export const UV_VERSION = '0.13.12';
38
43
  /** Where the base keeps that browser; an ENV of the image, so every command finds it. */
39
44
  export const PLAYWRIGHT_BROWSERS_PATH = '/opt/ms-playwright';
45
+ /** Where the base keeps the real uv; `uv` on PATH is UV_SHIM in front of it. */
46
+ export const UV_REAL = '/usr/local/libexec/uv/uv';
47
+ /**
48
+ * `uv` as the base runs it. uv has no `--user` and, unlike pip, does not fall back to the user's
49
+ * own site-packages when the system's is not writable, so a model writing `uv pip install pandas`
50
+ * (or the `pip install --user` habit, as `uv pip install --user`) as an unprivileged user would
51
+ * be refused. This puts such an install where pip would: under ~/.local, which the session's
52
+ * home keeps and python finds. A location asked for (`--prefix`, `--target`, `--python`,
53
+ * `--system`) and every other command go to uv unchanged; with a virtual environment active,
54
+ * uv installs into it (UV_SYSTEM_PYTHON, the base's default, would send it to the system's).
55
+ * No single quote anywhere: the Dockerfile writes it with printf '…'.
56
+ */
57
+ export const UV_SHIM = `#!/bin/sh
58
+ # The zen sandbox base: uv pip install as pip would do it, into ~/.local when the system
59
+ # site-packages is not writable or --user is given (uv has neither). The real uv: ${UV_REAL}.
60
+ real=${UV_REAL}
61
+ # An active virtual environment is where uv installs, as pip does: UV_SYSTEM_PYTHON would
62
+ # otherwise send every install to the system Python.
63
+ if [ -n "\${VIRTUAL_ENV:-}" ]; then
64
+ exec env -u UV_SYSTEM_PYTHON "$real" "$@"
65
+ fi
66
+ if [ "$1" = pip ] && [ "$2" = install ]; then
67
+ user= located=
68
+ for a do
69
+ shift
70
+ case "$a" in
71
+ --user) user=1; continue ;;
72
+ --prefix|--prefix=*|--target|--target=*|-t|--python|--python=*|-p|--system) located=1 ;;
73
+ esac
74
+ set -- "$@" "$a"
75
+ done
76
+ if [ -z "$located" ] && { [ -n "$user" ] || [ ! -w "$(python3 -c "import site; print(site.getsitepackages()[0])")" ]; }; then
77
+ shift 2
78
+ exec "$real" pip install --prefix "\${HOME:-/tmp}/.local" "$@"
79
+ fi
80
+ fi
81
+ exec "$real" "$@"
82
+ `;
83
+ /** A text as the printf arguments of a Dockerfile RUN, one quoted line each. */
84
+ function printfLines(text) {
85
+ if (text.includes("'"))
86
+ throw new Error('a printf-written file cannot hold a single quote');
87
+ return text
88
+ .trimEnd()
89
+ .split('\n')
90
+ .map((line) => ` '${line}' \\\n`)
91
+ .join('');
92
+ }
40
93
  const REAL_EXECUTABLE = `-c 'import os, sys; print(os.path.realpath(sys.executable))'`;
41
94
  /**
42
95
  * Shell that fails unless `python` and `python3` are both on PATH and are one interpreter:
43
- * a script's `#!/usr/bin/env python` must run where `python3 -m pip install` put its packages.
96
+ * a script's `#!/usr/bin/env python` must run where `uv pip install` put its packages.
44
97
  * Every image zen builds passes it (the base, a project's sandbox image, an agent image).
45
98
  */
46
99
  export const SAME_PYTHON_CHECK = `p3="$(python3 ${REAL_EXECUTABLE})" && test -n "$p3" ` +
@@ -59,8 +112,20 @@ export function sandboxBaseDockerfile() {
59
112
  # get to choose which one it finds.
60
113
 
61
114
  FROM docker.io/library/node:24-bookworm-slim AS node
115
+ FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv
62
116
  FROM docker.io/library/python:3.14-slim-bookworm
63
117
 
118
+ # uv installs Python packages: \`uv pip install <pkg>\` into the system Python, or into ~/.local
119
+ # for a user who cannot write it (and for \`--user\`), as pip would: \`uv\` on PATH is a script
120
+ # that adds \`--prefix ~/.local\` then. It never downloads a Python of its own, and keeps no
121
+ # cache: installed files are copies, not links into one. pip stays, for Dockerfiles that call it.
122
+ COPY --from=uv /uv /uvx /usr/local/libexec/uv/
123
+ RUN printf '%s\\n' \\
124
+ ${printfLines(UV_SHIM)} > /usr/local/bin/uv \\
125
+ && chmod 755 /usr/local/bin/uv \\
126
+ && ln -s /usr/local/libexec/uv/uvx /usr/local/bin/uvx
127
+ ENV UV_SYSTEM_PYTHON=1 UV_PYTHON_DOWNLOADS=never UV_LINK_MODE=copy UV_NO_CACHE=1
128
+
64
129
  # Command-line tools agents reach for first: fetching, JSON, searching, archives.
65
130
  RUN apt-get update \\
66
131
  && apt-get install -y --no-install-recommends ca-certificates curl jq ripgrep unzip \\
@@ -124,10 +189,10 @@ RUN npx -y "playwright-core@${PLAYWRIGHT_VERSION}" install --with-deps --only-sh
124
189
  && rm -rf /var/lib/apt/lists/* /root/.npm
125
190
 
126
191
  # Libraries agents' scripts commonly reach for: HTTP clients, JSON Schema validation, YAML,
127
- # dates, HTML. \`python\` and \`python3\` must be one interpreter, the one pip installs into.
192
+ # dates, HTML. \`python\` and \`python3\` must be one interpreter, the one uv installs into.
128
193
  # Global npm packages resolve for require() through NODE_PATH; ESM import does not read it
129
194
  # (built-in fetch needs nothing).
130
- RUN pip install --no-cache-dir \\
195
+ RUN uv pip install \\
131
196
  "requests>=2.32,<3" \\
132
197
  "jsonschema>=4,<5" \\
133
198
  "pyyaml>=6,<7" \\
@@ -140,7 +205,7 @@ ENV NODE_PATH=/usr/local/lib/node_modules
140
205
 
141
206
  # The data stack agents install most (analysis, charts, images, HTML/XML). Installed at run time
142
207
  # it lands in the container's own filesystem, which is thrown away, so every turn fetched it again.
143
- RUN pip install --no-cache-dir \\
208
+ RUN uv pip install \\
144
209
  "numpy>=2,<3" \\
145
210
  "pandas>=3.1,<4" \\
146
211
  "scipy>=1.14,<2" \\
@@ -151,6 +216,7 @@ RUN pip install --no-cache-dir \\
151
216
 
152
217
  # Package caches go to /tmp, never HOME: a session's sandbox HOME is kept with the chat, and a
153
218
  # download cache there (hundreds of MB after one npm install) counts against the user's storage.
219
+ # uv keeps none (UV_NO_CACHE above).
154
220
  ENV npm_config_cache=/tmp/.npm PIP_NO_CACHE_DIR=1
155
221
 
156
222
  LABEL zenera.sandbox-base=${SANDBOX_BASE_VERSION} \\
@@ -193,6 +259,7 @@ export async function ensureSandboxBases(engine, run, dockerfilePath, opts = {})
193
259
  signal: opts.signal,
194
260
  });
195
261
  if (pulled.code === 0) {
262
+ say(` pulled ${image}`);
196
263
  continue;
197
264
  }
198
265
  const why = (pulled.stderr.trim() || `exit ${pulled.code}`).split('\n').at(-1);
package/dist/image.d.ts CHANGED
@@ -59,4 +59,9 @@ export declare function ensurePodmanImage(target: {
59
59
  engine?: string;
60
60
  exec?: Runner;
61
61
  }, opts?: PrepareOptions): Promise<void>;
62
+ /**
63
+ * An engine build line worth showing as progress — podman's `STEP 3/5: RUN pip install …` — cut
64
+ * to one short line; '' for everything else (the steps' own output).
65
+ */
66
+ export declare function buildStep(line: string): string;
62
67
  //# sourceMappingURL=image.d.ts.map
package/dist/image.js CHANGED
@@ -188,7 +188,18 @@ async function obtain(engine, run, target, opts) {
188
188
  build.dockerfile,
189
189
  ...args,
190
190
  build.context,
191
- ], { timeoutMs: BUILD_MS, signal: opts.signal }));
191
+ ], {
192
+ timeoutMs: BUILD_MS,
193
+ signal: opts.signal,
194
+ // The engine's own step lines, so a host watching a build of several
195
+ // minutes sees which step it is on rather than the last thing said before it.
196
+ onLine: (line) => {
197
+ const step = buildStep(line);
198
+ if (step) {
199
+ say(` ${step}`);
200
+ }
201
+ },
202
+ }));
192
203
  tail(built);
193
204
  if (built.code !== 0) {
194
205
  throw new ImageBuildError(`could not build ${build.dockerfile}`, last(built) || 'run the build by hand to see what the engine says');
@@ -227,4 +238,18 @@ function last(res) {
227
238
  const lines = (res.stderr.trim() || res.stdout.trim()).split('\n').filter((l) => l.trim());
228
239
  return lines.slice(-2).join(' — ');
229
240
  }
241
+ const STEP_LINE = /^(?:\[[^\]]*\]\s*)?STEP \d+\/\d+:/;
242
+ const STEP_MAX = 160;
243
+ /**
244
+ * An engine build line worth showing as progress — podman's `STEP 3/5: RUN pip install …` — cut
245
+ * to one short line; '' for everything else (the steps' own output).
246
+ */
247
+ export function buildStep(line) {
248
+ const text = line.trim();
249
+ if (!STEP_LINE.test(text)) {
250
+ return '';
251
+ }
252
+ const flat = text.replace(/\s+/g, ' ');
253
+ return flat.length > STEP_MAX ? `${flat.slice(0, STEP_MAX - 1)}…` : flat;
254
+ }
230
255
  //# sourceMappingURL=image.js.map
package/dist/process.d.ts CHANGED
@@ -14,6 +14,11 @@ export interface ProcOptions {
14
14
  * would otherwise outlive it and hold its output open.
15
15
  */
16
16
  group?: boolean;
17
+ /**
18
+ * Each complete line of stdout and stderr as it arrives, uncapped by `maxBytes`: how a long
19
+ * build reports its steps while it runs. Runners other than `runProcess` may ignore it.
20
+ */
21
+ onLine?(line: string): void;
17
22
  }
18
23
  export interface ProcResult {
19
24
  code: number;
package/dist/process.js CHANGED
@@ -45,8 +45,35 @@ export const runProcess = (bin, args, opts = {}) => new Promise((settle, fail) =
45
45
  into.push(chunk);
46
46
  return size + chunk.length;
47
47
  };
48
- child.stdout.on('data', (c) => (outSize = keep(out, outSize, c)));
49
- child.stderr.on('data', (c) => (errSize = keep(err, errSize, c)));
48
+ // A line split across chunks is kept until its end arrives; the last one, at close.
49
+ const lines = () => {
50
+ let partial = '';
51
+ return {
52
+ add(chunk) {
53
+ const parts = (partial + chunk.toString('utf8')).split(/\r?\n|\r/);
54
+ partial = parts.pop() ?? '';
55
+ for (const line of parts) {
56
+ opts.onLine?.(line);
57
+ }
58
+ },
59
+ end() {
60
+ if (partial) {
61
+ opts.onLine?.(partial);
62
+ }
63
+ partial = '';
64
+ },
65
+ };
66
+ };
67
+ const outLines = opts.onLine ? lines() : undefined;
68
+ const errLines = opts.onLine ? lines() : undefined;
69
+ child.stdout.on('data', (c) => {
70
+ outSize = keep(out, outSize, c);
71
+ outLines?.add(c);
72
+ });
73
+ child.stderr.on('data', (c) => {
74
+ errSize = keep(err, errSize, c);
75
+ errLines?.add(c);
76
+ });
50
77
  // SIGTERM first so a well-behaved process can flush; SIGKILL after, so
51
78
  // one that ignores it cannot hold the turn open forever.
52
79
  let hard;
@@ -79,6 +106,8 @@ export const runProcess = (bin, args, opts = {}) => new Promise((settle, fail) =
79
106
  : e));
80
107
  });
81
108
  child.on('close', (code) => {
109
+ outLines?.end();
110
+ errLines?.end();
82
111
  finish(() => settle({
83
112
  code: code ?? (timedOut ? 124 : 1),
84
113
  stdout: Buffer.concat(out).toString('utf8'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenera/sandbox",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
4
4
  "description": "Where an agent's commands run and the files they see: the Sandbox contract, podman and bubblewrap implementations, filesystem drivers and a contract test suite for other implementations.",
5
5
  "keywords": [
6
6
  "sandbox",