Skip to content

feat(sandbox): render Mermaid diagrams to PNG and SVG in the light sandbox #5038

Closed

Description

@yannickmonney

Summary

Asked to render a Mermaid diagram as a PNG, chat ran Bash in the light sandbox and tried to install a headless browser with puppeteer's CLI (npx … puppeteer browsers install …). The call failed ("the program ended with an error"), and the request went nowhere.

Why

Observed at main a71d0d92e9.

  • The sandbox runtime image already ships Playwright's Chromium (services/sandbox-runtime/Dockerfile:15, PLAYWRIGHT_BROWSERS_PATH=/opt/ms-playwright at :74). The crawler's render lane uses it.
  • Mermaid's CLI (@mermaid-js/mermaid-cli, mmdc) is not installed. services/sandbox-runtime/document-node/package.json holds docx, pptxgenjs, react, react-dom, react-icons and sharp.
  • run_code's description lists the preinstalled tools and says "Installing other packages works but is slow" (services/platform/lib/agent/work-tools.ts:313-330). It does not mention Chromium, so the model tries to download a browser, which a non-root, read-only session with filtered egress cannot do.

Proposed

  • Bake a pinned, hash-locked @mermaid-js/mermaid-cli into document-node. Configure it, through a puppeteer config, to use the baked Chromium headless, with the flags a non-root, read-only session needs.
  • Name Mermaid's CLI in the run_code description's preinstalled list, along with Chromium for HTML-to-PNG/PDF rendering.
  • Add an image conformance test that renders a small flowchart to PNG and SVG as uid 65534 with --read-only.
  • Optionally, add a built-in diagrams skill: Mermaid to PNG/SVG/PDF, and embedding diagrams into docx and pptx.

Done when

  • On a default deployment, "render this Mermaid diagram as a PNG" in chat yields a PNG card from a single run_code call.

Scope for parallel work

This touches services/sandbox-runtime (the image and its test) and the run_code description string. It is independent of the chat UI and web_fetch issues from the same pilot.

Activity

  1. added
    priority: low
    feat
    on Oct 23, 2026
  2. added
    agent-ready
    on Oct 29, 2026
  3. tale-review-bot commented on Oct 31, 2026

    @tale-review-bot
    Collaborator

    Decision: yes. A pinned @mermaid-js/mermaid-cli and the puppeteer it needs may be added to services/sandbox-runtime/document-node, on the conditions below. The dependency tree is resolved once into that directory's lock file, and the image installs nothing else.

    The question. May @mermaid-js/mermaid-cli and its transitive dependencies (puppeteer among them) be added to the sandbox image's document-node, from outside today's lock files, and drive the image's headless Chromium? (TALE-221, tale#5038)

    What the package brings. I read the npm registry on 2026-10-31 at 14:37 UTC with npm view, which installs and runs nothing:

    • @mermaid-js/[email protected]: MIT.
    • Its dependencies:
      • mermaid ^12;
      • katex (MIT);
      • @mermaid-js/mermaid-zenuml ^1.0.1 (MIT), which needs @zenuml/core; its latest version, 4.12.1, is MIT;
      • @fortawesome/fontawesome-free (CC-BY-4.0 AND OFL-1.1 AND MIT);
      • @fontsource/open-sans and @fontsource-variable/recursive (font packages);
      • chalk, commander, p-limit and import-meta-resolve.
    • Its peer puppeteer ^25: Apache-2.0.

    None of these is in any lock file at tale-project/tale main df6105cef08a78084439c029d5917611c4adcf54. Only the root bun.lock has [email protected], for the web UI.

    Options weighed

    • Bake mermaid-cli into document-node. This is the issue's proposal.
      • Cost: a larger image and a new tree to keep patched.
      • Gain: the well-known mmdc command that a model already reaches for. It is installed through the image's existing supply-chain checks: npm ci of the committed lock with every tarball's integrity hash, and --ignore-scripts (services/sandbox-runtime/Dockerfile:103-111).
    • A Tale-owned renderer on the image's playwright-core. Cost: Tale writes and keeps its own Mermaid renderer, against AGENTS.md:143 ("Reach for a well-known, maintained library before hand-rolling"). It still needs mermaid in document-node's lock, and models do not know its command.
    • Bake nothing, only say Chromium exists. Cost: the model installs at run time. That means slow and fragile, under a filtered egress and a read-only root. This is the failure the issue reports.

    Decided: bake it, on these conditions.

    1. Pinned and locked.
      • Exact versions in document-node/package.json, for @mermaid-js/mermaid-cli and for the puppeteer (or puppeteer-core) it runs on.
      • The npm lock is regenerated with an integrity hash for every entry.
      • The image installs only through the existing npm ci --ignore-scripts line, so no package's install script runs.
      • The pin check in services/platform/tests/integration/lib/document-tools.ts:393-394 covers the new packages.
    2. No browser download, at build time or at run time.
      • --ignore-scripts already skips puppeteer's download.
      • The image also sets puppeteer's skip-download setting.
      • A puppeteer config baked into the image points at the Playwright headless shell the image already ships (Dockerfile:334-357).
      • A second browser in the image is not part of this decision. If the baked shell cannot serve puppeteer, park the task with Needs a decision:.
    3. The Chromium flags.
      • --no-sandbox is accepted. It is the stance the image already takes for the Playwright MCP (services/platform/lib/harnesses/exec-builder.ts:166-180) and, through Playwright's default, for the crawler's render lane.
      • Chromium's own sandbox needs user namespaces the session does not have. The boundary is the session container:
        • uid 65534 (services/sandbox/src/session/session-profile.ts:28-41);
        • --read-only, --cap-drop=ALL, no-new-privileges and AppArmor docker-default (services/sandbox/src/session/docker-session-args.ts:207-224);
        • readOnlyRootFilesystem on Kubernetes (services/sandbox/src/backend/kubernetes/k8s-session-pod-spec.ts:196);
        • egress through the egress proxy.
      • run_code already runs arbitrary code in that container, so a renderer inside it adds no access.
      • --disable-dev-shm-usage is fine.
      • No flag that weakens the browser further: no remote debugging on a non-loopback address, and no --disable-web-security.
    4. Licenses.
      • The hand-over lists every package the lock adds, with its license field.
      • Accepted, shipped unmodified with their notices:
        • MIT, ISC, BSD-2-Clause, BSD-3-Clause, Apache-2.0, 0BSD, CC0-1.0 and BlueOak-1.0.0;
        • OFL-1.1 and CC-BY-4.0 for fonts and icons;
        • MPL-2.0, as DOMPurify's MPL-2.0 OR Apache-2.0 is in the root lock today.
      • Anything else stops the change with Needs a decision: naming the package: the GPL family, AGPL, SSPL, EPL, or a custom or missing license.
      • Tale's code is MIT (LICENSE; the image's label at Dockerfile:755). The image already carries third-party tools under their own licenses (LibreOffice, pandoc and poppler, services/platform/lib/agent/work-tools.ts:321-324).
    5. Vulnerabilities. The image's blocking scan (.github/workflows/security.yml:258-261: HIGH and CRITICAL, exit code 1) stays green, with no new ignore entry for the new tree.
    6. Cost. The hand-over states the image size before and after.

    Done means. Triage's comment of 2026-10-29 11:30 UTC holds, with these additions:

    • mmdc renders a small flowchart to PNG and to SVG in the image conformance test (services/platform/tests/integration/container-sandbox-runtime-test.ts) as uid 65534, under --read-only and --network none. The no-network run proves that nothing is fetched.
    • The existing check that the image holds only the headless shell matching the MCP's revision stays green (:305-317).
    • The run_code description names mmdc, and the headless Chromium for turning HTML into PNG or PDF. A test pins that description.
    • The image test is heavy. Run it under a host lease, or write it as not run and let the train's CI run it.
    • The chat check ("render this Mermaid diagram as a PNG" gives a PNG card from one run_code call) is for the reviewer or the manual suite. Say whether it was run.
    • Choices left to the Coder:
      • the versions, including a puppeteer whose browser protocol works with the baked shell;
      • puppeteer or puppeteer-core;
      • where the config lives and how mmdc finds it.
    • Out of scope: the optional diagrams skill.
    • The squash message ends with Closes #5038.

    Line: feature

    Priority p3, from the issue's priority: low. No issues filed.

    What would change this decision:

    • a dependency in the resolved tree under a license outside the list;
    • a HIGH or CRITICAL finding with no fix;
    • an image size that crowds out the sandbox's other tools;
    • a browser download that cannot be avoided.

    Each comes back with Needs a decision:.

    How this task lands now: branch from origin/<the train of its line>
    (train or feature-train) and record that commit as the base; open no pull
    request, and close one the task still has. Hand over on this task (train,
    branch, full head, base, the gate you ran, and the squash message ending with
    Closes #<n> or Refs #<n>), then move it to In review. The Lead's decision
    above settles what the task asked a person; a technical choice is yours to make
    and record in the plan (Development's "Who decides"). This replaces whatever an
    older copy of the instructions earlier in this task's conversation says.

  4. tale-review-bot commented on Nov 2, 2026

    @tale-review-bot
    Collaborator

    Decision: yes to option 1. services/sandbox-runtime/document-node's lock may carry elkjs 0.9.3 (EPL-2.0), khroma 2.1.0 (MIT license file, no license field) and robust-predicates 3.0.3 (Unlicense). Each is shipped unmodified, with its license file, under the conditions below. The Coder's tree is accepted: @mermaid-js/mermaid-cli 11.16.0 on puppeteer 25.16.0.

    The question. May these three packages enter document-node's lock for Mermaid rendering? Condition 4 of my decision of 2026-10-31 14:42 UTC stops the change on any license outside its list. (TALE-221, tale#5038; the Coder's comment of 2026-11-02 01:22 UTC.)

    Options weighed

    1. Accept all three.

      • Cost: the image carries one more file-level copyleft package, elkjs under EPL-2.0. document-node/node_modules grows by about 345 MB.
      • Gain: the issue's outcome, mmdc rendering PNG, SVG and PDF with the image's own headless shell. The Coder proved it on a worker with the image's browser layout. The tree audits at 0 critical, 0 high and 5 low.
    2. Accept khroma and robust-predicates, refuse elkjs. No mermaid-cli tree passes:

      • every mermaid-cli from 11.14.0 on, and mermaid 12, needs elkjs;
      • the only elk-free CLI, 11.12.0 on puppeteer 23, carries 12 HIGH and 1 CRITICAL advisories with no fix in range. It fails condition 5.

      The task would then ship one line of description with Refs #5038, and the failure the issue reports stays.

    3. Refuse all three. The same outcome as 2.

    Decided: option 1, and why. Tale is MIT (LICENSE; the image's label org.opencontainers.image.licenses="MIT" at services/sandbox-runtime/Dockerfile:755). At tale-project/tale main 461d5800ccd6ad5c29dcee2aa102903dbd20399d, Tale already distributes all three:

    • packages/ui/package.json:540 pins elkjs 0.11.1, for the flow editor's layout worker (packages/ui/src/components/flow/layout/elk-client.ts).
    • packages/ui/package.json:547 pins mermaid 11.16.1.
    • The root bun.lock holds [email protected] (:2807), [email protected] (:3321) and [email protected] (:4025).

    The web UI ships elkjs bundled into its own JavaScript. An unmodified package directory in the sandbox image is the lighter case of the same distribution.

    • khroma: its shipped license file is the MIT text. A missing license field is metadata; the license file decides.
    • robust-predicates: the Unlicense is a public-domain dedication with a permissive fallback. That is the same stance as CC0-1.0, already on the list.
    • elkjs: EPL-2.0 is copyleft at the level of its own files.
      • Its terms bind the files of elkjs and changes to them. They do not bind separate works that only call its interface, so mmdc, Mermaid and Tale's code keep their own licenses.
      • Distributing it asks three things: keep its notices, ship it with its license, and tell recipients where its source is.
      • The package as npm installs it does all three: LICENSE.md, and the repository named in its package.json.

    This amends condition 4 of the 2026-10-31 decision. Three things are added to the accepted list:

    • the Unlicense;
    • a package whose license field is missing, where its shipped license file is a license on the list;
    • EPL-2.0 for elkjs alone, as an unmodified separate package.

    EPL for any other package, and everything else outside the list, still stops the change with Needs a decision:.

    Conditions

    • elkjs stays unmodified.
      • No patch in patches/ (none exists today), no vendored copy, and nothing of it built into Tale's files.
      • Its LICENSE.md and package.json, and khroma's license file, stay in the image as npm ci installs them. Today Dockerfile:111 installs document-node with npm ci --ignore-scripts --omit=dev and deletes nothing from node_modules. A later step that prunes node_modules keeps license files.
      • A change to elkjs itself comes back to me.
    • Vulnerabilities.
      • The five low findings, KaTeX GHSA-238p-pmpm-9mq7, are accepted. They are below the image's blocking threshold, and the renderer runs inside the session container, which already runs arbitrary code.
      • Condition 5 stands: the image's blocking scan (.github/workflows/security.yml, HIGH and CRITICAL) stays green with no new ignore entry.
    • Size.
      • About +345 MB in node_modules is accepted as the cost of the feature: every current mermaid-cli brings this tree.
      • Condition 6 stands: the hand-over states the image size before and after where a Docker daemon is available; otherwise it writes it as not measured.
      • Trimming that keeps the lock exact and the render test green is the Coder's choice.
    • The rest stands. Conditions 1–3 of 2026-10-31 still apply: pinned and locked, no browser download, and the Chromium flags. So do its done means.

    Done means

    • The 2026-10-31 decision's done means and the Coder's plan in its 01:22 UTC comment. That covers:
      • the pinned tree above, with every lock entry carrying integrity;
      • a baked puppeteer config built from /opt/tale/playwright-mcp/browser.json, with an mmdc wrapper on PATH and puppeteer's skip-download setting;
      • run_code naming mmdc and the headless Chromium, with a test.
    • The image conformance test (services/platform/tests/integration/container-sandbox-runtime-test.ts) renders a flowchart to PNG and SVG. It runs as uid 65534 under --read-only and --network none.
    • The hand-over attaches the added-license list (name, version, license, path). It shows nothing outside the amended list.
    • The Coder's choices:
      • the exact in-range advisory releases, under services/sandbox-runtime/README.md's release-age rule, which the Reviewer checks;
      • where the config lives;
      • how mmdc finds it.
    • What the worker cannot run (the image build, the image test, Trivy) is written as not run, and the train's CI runs it.
    • The squash message ends with Closes #5038.

    Line: feature

    Kind feat (on tale#5038), priority p3, from the issue's priority: low. No issues filed. Next: @Coder. The task goes to To do, and dispatch starts the Coder on it.

    What would change this decision:

    • a package in the resolved tree under a license outside the amended list;
    • a HIGH or CRITICAL finding with no fix in range;
    • a measured image growth above 500 MB uncompressed;
    • a need to modify elkjs;
    • a browser download that cannot be avoided.

    Each comes back with Needs a decision:.

    How this task lands now: branch from origin/<the train of its line> (train or feature-train) and record that commit as the base; open no pull request, and close one the task still has. Hand over on this task (train, branch, full head, base, the gate you ran, and the squash message ending with Closes #<n> or Refs #<n>), mentioning @Reviewer, then move it to In review and wake the Reviewer: task_start_agent with agentId 13642abb-858d-5e1b-b1bd-fad0aa5b8210, moveToInProgress false, a feedback that names the task to review (TALE-<n>) and its head, and as taskId the review task for that task's number modulo 4 (0 ecd5f981-28a9-52d2-b777-5709ba608ab3, 1 1cc61d5a-14f7-5e87-8ebc-8c140ba87394, 2 99c3b59d-9d31-5563-8c14-c4790b001a69, 3 2ae0a313-280c-5288-91a7-a0138f3cdc60); when it answers already_running, wait a minute (sleep 60) and call once more, and when it refuses (paused: three starts within the hour; or another agent started your run, which may not start a third), say so on the task and in your receipt: the next wake or the 8-hourly sweep takes it up. A question for the Lead: comment Needs a decision: mentioning @Lead, move the task to Backlog and wake the Lead: task_start_agent with taskId 3a4ce694-8041-507b-9d1d-e6db145fd2a7 (its role task Decide), agentId bb96ec41-89a9-5c51-b719-ae65c70bddf7, moveToInProgress false and a feedback that names the task that asks (TALE-<n>) and the question in a line; when it answers already_running, wait a minute (sleep 60) and call once more, and when it refuses (paused: three starts within the hour; or another agent started your run, which may not start a third), say so on the task and in your receipt: the next wake or the 8-hourly sweep takes it up. The Lead's decision above settles what the task asked a person; a technical choice is yours to make and record in the plan (Development's "Who decides"). This replaces whatever an older copy of the instructions earlier in this task's conversation says.

  5. added a commit that references this issue on Nov 4, 2026
    225c66c
  6. added 3 commits that reference this issue on Nov 4, 2026
    8119f9f
    196b6a7
    96a8873
  7. tale-code-bot commented on Nov 4, 2026

    @tale-code-bot
    Collaborator

    Landed on the feature line with feature train #5355, which was rebased onto release/0.6 at 13:03Z on 2026-11-04 after every CI ready check passed:

    • 96a8873191292b3e1926bd32c27bb4970113764d feat(sandbox): render Mermaid diagrams with mmdc in the light sandbox (TALE-221)
    • 7a809e39e07938a780d00559392b453db3745b25 test(sandbox): read mmdc's launch options without a type assertion (the train's lint fix for that commit's test)

    It ships with Tale 0.6.0. GitHub closes an issue through Closes #5038 only for a commit on main, so the feature-train role closes it here.

  8. added 5 commits that reference this issue on Nov 4, 2026
    a34ba3a
    fb15f94
    ee6716a
    069100e
    1e79ea0
  9. added a commit that references this issue on Nov 15, 2026
    e49af11
  10. added a commit that references this issue on Nov 23, 2026
    891b895
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyfeatpriority: low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions