Skip to content

feat(sandbox): bake the document skills' libraries into the runtime - #3787

Merged
yannickmonney merged 12 commits into
mainfrom
feat/sandbox-document-skill-packages
Sep 29, 2026
Merged

yannickmonney merged 12 commits into
mainfrom
feat/sandbox-document-skill-packages

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Customer feedback on document creation led us to check what the builtin docx, pptx, xlsx and pdf skills need at run time. They install libraries on the fly (npm install -g docx, npm install -g pptxgenjs, pip install "markitdown[pptx]", pip install Pillow) and import others the sandbox image did not carry (pandas, pdfplumber, pdf2image, reportlab, lxml). When sandbox egress blocks the package registries, as on a locked-down on-prem deployment, those installs fail and the skills fall back to a weaker path. This PR bakes those libraries into the sandbox runtime image. It follows the existing hash-locked pattern. The skills themselves stay org-seeded, and their SKILL.md files are untouched.

  • Release age: every version this PR adds to either lock was published at least 90 days ago, in line with the repository's Renovate policy (30/60/90 days for patch/minor/major). Younger releases are used only where they fix a known advisory: soupsieve 2.9.2 (two ReDoS advisories in 2.8.4), sharp 0.35.4 (HIGH libheif advisories below it), and the image-size 2.0.4 override. The 8 pre-existing pins and Hermes' own pins are unchanged.
  • Python: services/sandbox-runtime/document-python-requirements.txt gains markitdown[pptx] 0.1.6, pandas 3.0.3, pdfplumber 0.11.10, pdf2image 1.17.0, reportlab 5.0.0 and lxml 6.1.1, plus their full dependency closure (41 pins, up from 8; the existing 8 are byte-identical). Pillow 12.2.0 comes from Hermes' pin. The lock is resolved for Python 3.12 with uv pip compile --only-binary :all: --exclude-newer 2026-07-01 against the hermes-agent==0.18.0 resolution as constraints. Hermes installs into the same interpreter afterwards and pins Pillow, requests, certifi, cryptography, packaging and PyYAML itself, so building this way keeps it from swapping any locked version. Every pin carries the hash of each cp312 manylinux wheel for amd64 and arm64, and there are no sdists. The Dockerfile still installs it with --require-hashes --only-binary=:all:.
  • Node: there is a new services/sandbox-runtime/document-node/ with package.json and package-lock.json: docx 9.7.1, pptxgenjs 4.0.1, and react/react-dom 19.2.7, react-icons 5.7.0 and sharp 0.35.4 for the icon recipe in the pptx skill's pptxgenjs.md. The lock is written by npm 11, the major the image's Node 24 ships. It records libc on sharp's platform packages, so npm ci on glibc skips the musl builds. Every lock entry has an integrity hash, and no package has an install script. The image installs it with npm ci --ignore-scripts into /opt/tale/document-node and sets ENV NODE_PATH to it. entrypoint.sh prepends the session prefix to that value (NODE_PATH=/agent/.runtime/deps/node/lib/node_modules${NODE_PATH:+:$NODE_PATH}, the same pattern as PYTHONPATH), so a package a session installs still wins and require('docx') from /agent/workspace resolves. package-lock.json is gitignored repo-wide (bun is the package manager), so .gitignore now keeps this one lock. overrides lifts image-size, which pptxgenjs declares but never loads, from 1.2.1 to 2.0.4. Without that, the Trivy fs gate would fail on two HIGH advisories; npm audit --package-lock-only now reports 0.
  • Security workflow: security.yml now also triggers on services/sandbox-runtime/document-node/** and the Python requirements file, so a Renovate bump or manual refresh of the npm lock alone still runs the Trivy gate.
  • Left out on purpose: OCR (pytesseract needs a tesseract binary the image lacks), the qpdf/pdftk CLIs, and the JS alternatives pdf-lib/pdfjs-dist that the pdf reference mentions without an install step (pypdf covers those paths). I also kept the skills' own npm install -g/pip install lines as they are. With egress they refresh the session copy; without it they fail while the baked library keeps working.
  • Docs: EN/DE/FR platform/agents/harnesses now says the document skills work without registry access and that OCR is not included. EN/DE/FR self-hosted/operate/security/hardening tells operators setting SANDBOX_EGRESS_ALLOWLIST that these skills need no registry to create and read Word, PowerPoint, Excel and PDF files, and that OCR is not included. The sandbox-runtime README documents both locks, the release-age rule and how to regenerate them, and .agents/repo.md notes where the libraries live.
  • Tests: tests/integration/lib/document-tools.ts runs offline on a read-only root as uid 65534 and uid 10001. It checks both locks: bytes, exact versions, installed file hashes, and each npm package's installed integrity against the lock. It then runs the skills' actual paths: pandas reads the XLSX fixture, reportlab writes a PDF that pdfplumber, pypdfium2 and pdf2image/poppler read back, and Node writes a .docx and a pptxgenjs deck with a sharp-rasterized react-icons icon, which pandoc and python -m markitdown read back. The check now imports onnxruntime and pandas in one interpreter (about 300 MB resident when measured), so its memory cap goes from 256m to 1g. It keeps the default session profile's 128-pid cap and runs OpenBLAS and libvips with one thread each, so a many-core host does not exhaust the cap. container-sandbox-runtime-test.ts checks runnerd's NODE_PATH in a booted session and that a session-installed package shadows the baked one. The sandbox-runtime size budget goes from 5400 to 5900 MB.
  • Manual: new box TASK-F46 (agent with docx/pptx delivers a memo and an icon deck while SANDBOX_EGRESS_ALLOWLIST admits no registry) and a matching row in reference/automation.md.

Checklist

  • bun run check: not run in full locally, because the machine is shared and loaded. CI runs the full gate. For the touched workspaces I ran typecheck, oxlint, oxfmt, docs tests, the manual gate and the sandbox-runtime daemon tests (see Test plan).
  • bun run lint:sast passes on the final head (467 rules on 4060 files, 0 findings).
  • Translations: N/A, no message catalog keys changed. The docs changes ship in EN/DE/FR together (German du, French tu, with a French non-breaking space before ;/:).
  • Docs updated in docs/{en,de,fr}/ (harnesses, hardening).
  • README.md / README.de.md / README.fr.md: N/A, the root READMEs don't cover sandbox image contents. services/sandbox-runtime/README.md is updated.

Test plan

What I verified locally, without a docker build (the disk is full):

  • Python lock: uv pip compile with --exclude-newer 2026-07-01 (plus per-package exceptions for the pre-existing pypdf/elementpath pins and the soupsieve fix) gives identical results for x86_64-manylinux_2_36 and aarch64-manylinux_2_36. A script checked that every pin has at least one hashed cp312 manylinux wheel for each architecture; the same script regenerates the previous lock's hash lines byte for byte. An OSV query over all 41 pins flags only Hermes' Pillow and cryptography pins (see Follow-ups).
  • Node lock: npm audit --package-lock-only reports 0. npx npm@11 ci --ignore-scripts --omit=dev --os=linux --cpu=x64 --libc=glibc from the committed lock installs 37 packages, 127 MB: only the glibc sharp and libvips builds, no musl and no wasm32. With npm 10 the wasm32 fallback (about 9 MB) is still installed; the image's Node 24 ships npm 11. Publish dates of every lock entry were checked with npm view … time.
  • I ran the whole offline check script (Python and Node halves) on macOS against a Python 3.12 venv with exactly the pinned versions (macOS wheels, uv pip check clean) and an npm ci of the committed lock, with the thread-pool variables set. Only the /opt/tale paths were swapped for temp paths, and pandoc was replaced by reading word/document.xml, because pandoc is not installed here. It passes: 41 Python distributions, 4856 RECORD hashes, 37 npm integrity entries, and the DOCX/PPTX/PNG/PDF/XLSX round-trips.
  • bun run --filter @tale/platform typecheck, oxlint on the touched test files, oxfmt --check, bun run --filter @tale/docs test (171/171), sh -n on entrypoint.sh, commitlint on the new commits. Earlier in this PR: bun run lint:manual, check-guide.ts on suites/tasks.md, bun run lint:sast.
  • @tale/sandbox-runtime-daemon bun test (earlier in this PR): 174 pass, 2 fail. The same 2 fail on a clean main tree (the stageFiles stalled-URL deadline and the partial-exec-body timing test) because the machine is loaded; this change doesn't touch them.

How this gets proven for real: this PR touches services/sandbox-runtime/**, so build.yml runs Build sandbox-runtime (the actual image build, amd64) and then Validate images. That job runs container-image-test.ts, which includes the extended checkDocumentTools for both uids and the size budget, and container-sandbox-runtime-test.ts, which includes the NODE_PATH check (its expected value also proves the entrypoint composes with the image's ENV NODE_PATH). security.yml runs the Trivy fs gate over the new lock. arm64 is proven only at release time: release.yml's native "Verify native document tools" step runs the same checkDocumentTools against each pushed amd64/arm64 digest, and nothing builds arm64 on a PR.

Not verified:

  • The image build itself and the real image size. The ~5.3 GB estimate comes from the unpacked Python wheels (about 290 MB new) and the Node tree (about 130 MB, of which react-icons is about 85 MB). The next Validate images log shows the actual figure against the new 5900 MB budget.
  • Linux runtime of the re-resolved versions. The functional run above used macOS wheels and binaries; Linux behaviour of sharp, onnxruntime/magika and pdf2image is proven only by the CI image checks.
  • arm64 until a release build runs.
  • TASK-F46: I have not run a live agent task with blocked egress.
  • Other CLIs and NODE_PATH. A CLI in /opt/agents that probes for an optional module it doesn't bundle (for example sharp) will now find the baked copy. Its own node_modules still resolve first.

Follow-ups:

  • Hermes pins with advisories. Pillow 12.2.0 and cryptography 46.0.7, pinned by every hermes-agent release through 0.19.0, have fixed advisories upstream (Pillow 12.3.0, cryptography 49/50). The image already shipped them through Hermes before this PR; the lock just records them. Trivy doesn't read this requirements file by name for vulnerabilities, so no gate flags them.
  • Thread pools against the default session's pid cap. A default session caps pids at 128, which counts threads, and numpy/OpenBLAS, onnxruntime and libvips size their pools to the host's cores. On a host with many cores, a skill run that loads several of them could hit the cap. This was already true when the skills installed these libraries at run time; the offline check now pins the pools, but the session profile does not.
  • Docs screenshots: none affected.

The builtin docx, pptx, xlsx and pdf skills install their libraries at
run time (npm install -g docx / pptxgenjs, pip install markitdown[pptx]
and Pillow) and import others the image lacked (pandas, pdfplumber,
pdf2image, reportlab, lxml). On a deployment whose sandbox egress blocks
the package registries those installs fail and the skills fall back to
a degraded path, as they would on a locked-down on-prem deployment.

The Python libraries join the existing hash-locked
document-python-requirements.txt, resolved for Python 3.12 against the
hermes-agent pins so the later Hermes install keeps every version, with
a hash for every cp312 manylinux wheel on amd64 and arm64. The Node
libraries (docx, pptxgenjs, and react, react-dom, react-icons and sharp
for the icon recipe in pptxgenjs.md) come from a committed
package-lock.json installed with npm ci --ignore-scripts into
/opt/tale/document-node. The image's NODE_PATH names that prefix and
the session entrypoint puts the per-session npm prefix in front of it,
so a package an exec installs still wins. image-size, which pptxgenjs
declares but never loads, is overridden to a release without its
denial-of-service advisories so the Trivy gate stays green. The root
.gitignore keeps that one npm lock. The pdf skill's OCR route stays
unbaked, since the image has no tesseract binary.

The offline document check now covers both locks (bytes, versions,
installed hashes) and exercises the skills' own paths as both session
users with no network: pandas over the XLSX fixture, reportlab into
pdfplumber, pypdfium2 and pdf2image, and docx plus a pptxgenjs deck with
a sharp-rasterized icon read back through pandoc and markitdown. The
conformance test asserts runnerd's NODE_PATH layering. The check's
memory ceiling and the image size budget grow with the libraries.
The sandbox image now carries the libraries of the built-in docx, pptx,
xlsx and pdf skills, so an agent equipped with them produces Office and
PDF files on a deployment whose sandbox egress blocks package
registries. The harness page says so beside its outbound-access note,
including that the skills' own install commands then fail harmlessly
and that OCR for scanned PDFs is not included; the hardening page tells
operators restricting SANDBOX_EGRESS_ALLOWLIST that the document skills
need no registry. EN, DE and FR change together.
A live agent run is the half the image test cannot cover: TASK-F46 has
an agent equipped with docx and pptx deliver a Word memo and an icon
deck while SANDBOX_EGRESS_ALLOWLIST admits no registry. The automation
register records what the offline image check already owns, and the
suite and readme counts move to 85 and 922 boxes.
The first lock pinned the newest release of every library, several of
them one to twenty days old, while the repository's Renovate policy
holds a release back 30 to 90 days so a compromised or broken one is
pulled before adoption. These libraries land in every org's sandbox.

Re-resolve both locks with nothing published in the last 90 days. Two
younger releases stay because they fix known advisories: soupsieve
2.9.2 (two ReDoS advisories in 2.8.4) and sharp 0.35.4 (libheif HIGH
advisories below it); the image-size override stays for the same
reason. The pre-existing pins and Hermes' own pins are unchanged.

The Node lock is now written by npm 11, the major the image's Node 24
ships, which records libc on sharp's platform packages, so npm ci on
glibc no longer installs the musl builds (~18 MB). The README records
the release-age rule and the refresh recipe.
security.yml only triggers on bun.lock, package.json files one level
under services/, Dockerfiles and the Trivy ignore file. The sandbox
runtime's document-skill npm lock and Python hash lock match none of
them, so a Renovate bump or manual refresh of either would merge
without the HIGH/CRITICAL gate. Add both to the pull_request and push
path filters.
The entrypoint spelled out the baked document-library directory a
second time. Prepend the session prefix to the NODE_PATH the image sets
instead, the way PYTHONPATH already does, so the Dockerfile is the only
place that names the baked directory. The resolved value is unchanged.
The check runs under the default session profile's 128-pid cap, which
counts threads, while OpenBLAS (numpy) and libvips (sharp) size their
pools to the host's cores. On a host with many cores the check could
fail for reasons unrelated to the image. Run both with one thread.
The hardening page said the built-in document skills need no package
registry at all. They create and read Word, PowerPoint, Excel and PDF
files without one, but the pdf skill's OCR route is not in the image.
Qualify the sentence in English, German and French.
The new path-filter comment claimed the gate checks both document locks for advisories. Trivy scans the npm lock only; the Python hash lock's file name is not one it reads for vulnerabilities. Say so, so nobody relies on a gate that does not exist.
…-skill-packages

# Conflicts:
#	services/platform/tests/manual/readme.md
The image check found typing-extensions 4.16.0 where the document lock said
4.15.0: the Hermes install that follows the document libraries pins
pydantic 2.13.4, which pulls 4.16.0, so the lock no longer described the
image. The lock now names 4.16.0 with its wheel hash, so the later Hermes
install keeps every version the lock lists, as its header promises.
Code scanning flags 'RUN cd' in a Dockerfile; npm ci --prefix installs into the same directory from the committed lock without changing the working directory.
@yannickmonney
yannickmonney merged commit c9bb073 into main Sep 29, 2026
51 of 53 checks passed
@yannickmonney
yannickmonney deleted the feat/sandbox-document-skill-packages branch September 29, 2026 03:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants