@zenera/sandbox 1.3.4 → 1.3.6

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
@@ -1,6 +1,12 @@
1
1
  import type { PrepareOptions } from './contract.ts';
2
2
  import type { Runner } from './process.ts';
3
3
  export declare const SANDBOX_BASE_REPO = "ghcr.io/zenera-ai/zenera-sandbox";
4
+ /**
5
+ * Shell that fails unless `python` and `python3` are both on PATH and are one interpreter:
6
+ * a script's `#!/usr/bin/env python` must run where `python3 -m pip install` put its packages.
7
+ * Every image zen builds passes it (the base, a project's sandbox image, an agent image).
8
+ */
9
+ export declare const SAME_PYTHON_CHECK: string;
4
10
  /**
5
11
  * The base image's Dockerfile, for `--build-arg ZEN_VERSION=<a published version>`.
6
12
  * packages/sandbox/sandbox-base.Dockerfile is this, kept in step by a test.
package/dist/base.js CHANGED
@@ -18,6 +18,14 @@ import { join } from 'node:path';
18
18
  export const SANDBOX_BASE_REPO = 'ghcr.io/zenera-ai/zenera-sandbox';
19
19
  /** `FROM [--platform=…] ghcr.io/zenera-ai/zenera-sandbox:<version>`: the version is the tag. */
20
20
  const BASE_FROM = /^\s*FROM\s+(?:--platform=\S+\s+)?ghcr\.io\/zenera-ai\/zenera-sandbox:([^\s@]+)/gim;
21
+ const REAL_EXECUTABLE = `-c 'import os, sys; print(os.path.realpath(sys.executable))'`;
22
+ /**
23
+ * Shell that fails unless `python` and `python3` are both on PATH and are one interpreter:
24
+ * a script's `#!/usr/bin/env python` must run where `python3 -m pip install` put its packages.
25
+ * Every image zen builds passes it (the base, a project's sandbox image, an agent image).
26
+ */
27
+ export const SAME_PYTHON_CHECK = `p3="$(python3 ${REAL_EXECUTABLE})" && test -n "$p3" ` +
28
+ `&& test "$(python ${REAL_EXECUTABLE})" = "$p3"`;
21
29
  /**
22
30
  * The base image's Dockerfile, for `--build-arg ZEN_VERSION=<a published version>`.
23
31
  * packages/sandbox/sandbox-base.Dockerfile is this, kept in step by a test.
@@ -33,6 +41,11 @@ export function sandboxBaseDockerfile() {
33
41
  FROM docker.io/library/node:24-bookworm-slim AS node
34
42
  FROM docker.io/library/python:3.14-slim-bookworm
35
43
 
44
+ # Command-line tools agents reach for first: fetching, JSON, searching, archives.
45
+ RUN apt-get update \\
46
+ && apt-get install -y --no-install-recommends ca-certificates curl jq ripgrep unzip \\
47
+ && rm -rf /var/lib/apt/lists/*
48
+
36
49
  # Copy Node.js runtime and global modules from official Node image
37
50
  COPY --from=node /usr/local/bin/node /usr/local/bin/node
38
51
  COPY --from=node /usr/local/include/node /usr/local/include/node
@@ -71,9 +84,18 @@ RUN npm install -g \\
71
84
  "yazl@^3.3.1" \\
72
85
  "zod@^4.6.7"
73
86
 
74
- # HTTP clients agents' scripts commonly reach for. Global npm packages resolve for require()
75
- # through NODE_PATH; ESM import does not read it (built-in fetch needs nothing).
76
- RUN pip install --no-cache-dir "requests>=2.32,<3" \\
87
+ # Libraries agents' scripts commonly reach for: HTTP clients, JSON Schema validation, YAML,
88
+ # dates, HTML. \`python\` and \`python3\` must be one interpreter, the one pip installs into.
89
+ # Global npm packages resolve for require() through NODE_PATH; ESM import does not read it
90
+ # (built-in fetch needs nothing).
91
+ RUN pip install --no-cache-dir \\
92
+ "requests>=2.32,<3" \\
93
+ "jsonschema>=4,<5" \\
94
+ "pyyaml>=6,<7" \\
95
+ "python-dateutil>=2.9,<3" \\
96
+ "beautifulsoup4>=4.12,<5" \\
97
+ && ${SAME_PYTHON_CHECK} \\
98
+ && python -c "import bs4, dateutil, jsonschema, requests, yaml" \\
77
99
  && npm install -g "axios@^1"
78
100
  ENV NODE_PATH=/usr/local/lib/node_modules
79
101
 
package/dist/image.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import { readFileSync, readdirSync } from 'node:fs';
3
3
  import { join, relative, sep } from 'node:path';
4
- import { ensureSandboxBases } from "./base.js";
4
+ import { ensureSandboxBases, SAME_PYTHON_CHECK } from "./base.js";
5
5
  import { SandboxError } from "./contract.js";
6
6
  import { runProcess } from "./process.js";
7
7
  // ---------------------------------------------------------------------------
@@ -193,6 +193,23 @@ async function obtain(engine, run, target, opts) {
193
193
  if (built.code !== 0) {
194
194
  throw new ImageBuildError(`could not build ${build.dockerfile}`, last(built) || 'run the build by hand to see what the engine says');
195
195
  }
196
+ // The tag existing is what skips the next build, so an image that fails this is removed.
197
+ const same = await run(engine, [
198
+ 'run',
199
+ '--rm',
200
+ '--network',
201
+ 'none',
202
+ '--entrypoint',
203
+ '/bin/sh',
204
+ target.image,
205
+ '-c',
206
+ SAME_PYTHON_CHECK,
207
+ ], { timeoutMs: 120_000, signal: opts.signal });
208
+ if (same.code !== 0) {
209
+ await run(engine, ['rmi', '--force', target.image], { timeoutMs: 60_000 });
210
+ throw new ImageBuildError(`${build.dockerfile}: \`python\` and \`python3\` are not the same interpreter`, "start FROM zen's sandbox base, or install python3 and link python to it: " +
211
+ '`ln -sf "$(command -v python3)" /usr/local/bin/python`');
212
+ }
196
213
  return;
197
214
  }
198
215
  say(`pulling ${target.image} — this happens once`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenera/sandbox",
3
- "version": "1.3.4",
3
+ "version": "1.3.6",
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",