Skip to content

fix(platform): harden chat tools and light sandboxes after review - #4849

Merged
yannickmonney merged 14 commits into
mainfrom
fix/chat-work-tools-hardening
Oct 12, 2026
Merged

yannickmonney merged 14 commits into
mainfrom
fix/chat-work-tools-hardening

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What

Follow-up to #4817 (chat makes files and uses skills, sandbox only as needed). That PR merged without an independent review, and it put a code-execution surface behind every chat. A read-only adversarial security review of the merged code (isolation, egress, paths, authorization, budgets, injection) found eight issues; a second independent review of the fixes found ten more, none critical. This PR fixes what the platform can fix, and lists the rest below with why they need a decision.

Fixed after the security review

# Finding Fix
1 A step's tool calls ran together with no count, no deadline, no abort signal, and nothing wrote the reply's heartbeat. Five parallel 170 s code runs outlived the 10 minutes the generation watchdog tolerates: the row was swept as dead under a batch that kept working, the composer unlocked for a second turn on the same sandbox, the budget hold vanished and Stop reached nothing. lib/chat/tool-batch.ts: at most 16 distinct calls run (the rest answer that they did not); the turn's heartbeat is written and its Stop read every 10 s while they run; a Stop, 5 minutes or the end of the turn aborts every call through its signal, with a 15 s grace before a call that does not listen is answered as left behind. run_code takes the signal: it cancels the program in the sandbox, starts nothing for a call told to stop while it waited behind another program, and stops waiting for a busy sandbox at once. Task runs on the shared engine get the same bounds. (CHAT-R25)
3 CHAT-R23 (16 images per reply) was bypassed by parallel calls: the count was taken after an await, so ten calls of four each all saw none admitted. The count is taken before anything is awaited and given back on a refusal or failure. (CHAT-R23; the test fails without it)
5 Light sandboxes mounted the organization's shared pip/npm/bun caches read-write, the volumes agent sessions install from. Pip serves a cached URL's bytes unverified and npm's index is as writable as its content, so code in a light sandbox could plant a package an agent session (LLM gateway key, bridge token) later installs. The spawner mounts no shared cache, sets no cache environment, and neither holds nor creates the cache volumes for the untrusted default profile. One predicate (sessionSharesPackageCaches) answers the question for the argv builder, the volume setup and the retention. Agent sessions keep the caches.
6 The chat_tools kill switch failed open: a policy file that fails to parse read as absent, and absent means every tool on. Read strictly: an absent file is the defaults, a policy that cannot be read (a file that fails to parse, an unset or unreadable configuration root) turns files, skills and code off until repaired. (CHAT-R26)
7 The idle sweep chose stale rows by row but acted on the session id, so the failed start of 5 minutes ago made it destroy the sandbox its retry had made whenever the conversation sat between two code runs. A stale row is a candidate only while no newer incarnation of its session id is live. (SBX-R26; a real-Postgres lane proves it and fails against the old query)
8a A program writing thousands of files grew the tool result, the reply's record and the next prompt without bound. A run examines at most 200 output entries and names at most 20 skipped ones; the rest are counted. (CHAT-R27)

Fixed after the second review

  • The Governance page showed an unreadable Chat tools file as every switch on. chat_tools now joins the policies the page reads the way their consumers do (strictly), so the page reports the problem with Retry instead of showing switches the chat is not using. (CHAT-R26; route and editor tests)
  • A late image settle could lower the next reply's budget hold. An image call that outlives its reply (a Stop abandons a tool that does not listen) settled against the thread's one generation row, which by then was the next reply's. The hold is now raised and given back on the row of the reply that took it; the spend is still booked. (CHAT-R22; new real-Postgres lane checkImageHoldIdentity, mutation-checked: against the old query the next reply's hold drops from 10 to 0)
  • run_code after a Stop. The cancel is repeated a few times when the sandbox does not know the program yet (it can overtake the request that starts it). The harvest hears the Stop between files and records files as delivered only when it completed, so a file is never recorded for a reply that did not get it. The files a harvest looks at are the 200 written most recently, and a delivered file out of view stays recorded instead of being attached again when it returns. A stopped program's answer tells the model its files stay and are attached by the next run. (CHAT-R24, CHAT-R25, CHAT-R27)
  • Light sandboxes held and created cache volumes they do not mount, which coupled their start to a cache volume's health and added Docker calls. They do neither now; the README, the source comments and the environment reference are corrected.
  • A task run's live log showed a stopped program as a success. One list of work-tool failure statuses now feeds the executors' type and the log.
  • Mock gateway: a second request for the same work after an earlier turn used tools ran no tool (the resume check read the whole conversation), which made the second leg of manual box CHAT-F72 impossible in mode A. It reads the turn in progress now.
  • Docs: the sandboxes page said private addresses are blocked for light sandboxes. They are not all (see below); it now says what is true, EN/DE/FR. The chat watchdog's comment no longer says the heartbeat stands still while tools run.

Not changed, and why

  • Egress and the sandbox network (4). Code in a light sandbox reaches public hosts through the egress proxy, like every sandbox. I probed a real light sandbox (uid 65534) on a local rig laid out like the Docker deployment: cloud-metadata addresses are blocked, but the spawner API (/health answers) and the backend are reachable by connection on the sandbox network, because that network carries them and the entrypoint exempts private ranges from the proxy redirect. They authenticate their callers and the sandbox holds no credential for them, but a light sandbox has no need of them. Closing this is a per-profile network policy in the runtime entrypoint (Kubernetes already restricts session Pods to the egress proxy, the LLM gateway and DNS); it changes the runtime image and wants its own PR. Until then the docs say what is reachable, and SANDBOX_EGRESS_ALLOWLIST limits the public hosts.
  • Disk quota (2). The sandbox workspace is a host bind mount; the only file limit is 100 MB per file, and the free-space floor gates admission only. A program can fill the host disk within one 180 s run. A real quota needs filesystem support (project quotas, a sized loop device) or an in-runtime watchdog, and it is as true of agent sessions as of light ones.
  • Explicit-only skills (8b). explicitOnly is a prompt-level contract in chat and in the harness alike; enforcing it in code needs the person's own naming of a skill carried into the tool scope.

Upgrade note

0.5.87 shipped light sandboxes with the organization's shared pip, npm and bun cache volumes mounted read-write. This PR stops that, but entries a light sandbox wrote before stay in those volumes. An operator who ran chat code on 0.5.87 and wants the caches cold can remove tale-sandbox-{pip,npm,bun}-cache-<organization> while none of the organization's sessions runs; the next agent session recreates them and installs take longer until they fill again.

Verification

  • Unit: tool-batch.test.ts (cap, heartbeat cadence, failed heartbeat, Stop, deaf tool, deadline, turn end, a tool that throws before it returns a promise, no timer left behind), turn.test.ts, run-code.test.ts (abort cancels the exec, repeated cancel, a parked call starts nothing, a stopped harvest records nothing, the newest-first window, a delivered file out of view), image-billing.test.ts, work-tools.test.ts (strict read, fail closed for a bad file and for an unavailable root), the governance routes.test.ts and the Chat tools editor test (an unreadable policy is reported), transcript.test.ts, the mock gateway's contract test, and the spawner's docker-session-args.test.ts and docker-session-cache-volumes.test.ts (a light sandbox neither creates nor holds the caches, an agent session still does).
  • Each test added in the second round was run against the code it guards with the fix taken out, and failed.
  • Real Postgres: new lanes checkLightSessionSweep and checkImageHoldIdentity, both mutation-checked.
  • On the local rig with the real spawner: a long program (mock trigger e2e:run-long-code, 170 s) with Stop generating after 20 s: the generation row was gone within 9 s, the reply settled stopped with the call paired to its stopped result, no file, and no process left in the sandbox. Left alone, the same run kept the generation heartbeat advancing every ~10 s for its whole 170 s and ended ok with done.txt attached. A light sandbox was also probed for what it can reach (above).
  • Manual boxes CHAT-F72 (Stop on a running program) and CHAT-B25 (unreadable policy file); automation rows in reference/automation/chat.md and tasks.md.

The default profile runs untrusted code: a chat's run_code and page
rendering. It mounted the organization's shared pip, npm and bun caches
read-write, the same volumes an agent session installs its tools from. Pip
serves a cached URL's bytes without checking them and npm's index is as
writable as its content, so code in a light sandbox could plant a package an
agent session later installed, one with an LLM gateway key and a bridge
token, and run as it.

The default profile now gets neither the volumes nor the environment that
points installs at them; an install inside it lands in its own workspace.
Agent sessions keep the shared caches, and DinD sessions still go without.
A session id names every incarnation of one owner's sandbox, each its own
row, and the spawner and the settle both act on the id. The idle sweep
chose stale rows by row, so the failed start of five minutes ago made the
sweep destroy the sandbox its retry had made, whenever the conversation was
between two code runs: the files it kept were gone.

A stale row is now a candidate only while no newer incarnation of its id is
live. A real-Postgres lane proves it, and fails against the old query.
Findings of an independent security review of the merged chat tools.

A step's tool calls ran together with no count, no deadline, no abort signal
and nothing writing the reply's heartbeat. Five parallel code runs of 170
seconds outlived the ten minutes the generation watchdog tolerates: the row
was swept as dead under a batch that kept working, the composer unlocked for
a second turn on the same sandbox, the budget hold vanished and Stop reached
nothing. The batch is now supervised: at most 16 distinct calls run and the
rest answer that they did not; the turn's heartbeat is written and its Stop
read every ten seconds while they run; and a Stop, five minutes, or the end
of the turn tells every call through its signal, with a short grace before a
call that does not listen is answered as left behind. A code run cuts its
program off in the sandbox, starts nothing for a call told to stop while it
waited behind another program, and stops waiting for a busy sandbox at once.
The same engine serves task runs, which gain the same bounds.

Images asked for in parallel counted the reply's ceiling after an await, so
ten calls of four each all saw none admitted; the count is taken first and
given back on a refusal.

A Chat tools policy file that exists and cannot be read now turns the tools
off, instead of the defaults an admin may have switched off. What a code run
names back of its output box is bounded however many files it wrote.

Spec rules CHAT-R25 to CHAT-R27 with tests naming them, manual boxes
CHAT-F72 and CHAT-B25, and a mock scenario for a long program.
Code in a light sandbox holds no credentials of the organization and sees
only the files of its own conversation or task, but it can reach public web
addresses like every sandbox; private and cloud-metadata addresses are
blocked. The page said "isolated" and no more. It now says this and points
at the egress allowlist that limits it. English, German and French.
The batch started each call outside the guard the old loop wrapped it in, so
an executor that threw synchronously rather than rejected would have ended
the whole turn over one call. It is answered as a broken tool, like a
rejection. Tests also pin that composing executors and the work tool
executor hand the turn's abort signal to the tool that owns the call.
Findings of a second independent review of the chat tool hardening.

The chat reads the Chat tools policy strictly and offers no tool when the
file cannot be read, but the Governance page read it leniently: a broken
file came back as no policy and the editor showed every switch on, with no
alert, while the chat offered nothing. The page now reads chat_tools the way
its consumer does, with the other strictly read policies, so it reports the
problem with Retry instead of the defaults.

The reader's docblock also said an unset configuration root is the defaults;
it fails closed like any policy that cannot be read, and a test pins both
causes.
…k it

An image raises its reply's budget hold by an estimate before the provider is
called and gives it back when it settles. Both statements named the thread,
which has one live generation row at a time. A call can outlive its reply (a
Stop abandons a tool that does not listen), so its settle could arrive after
the next reply had taken the thread and lower that reply's hold.

The hold now names the reply it was raised on, by its message: a settle that
finds another reply's row lowers nothing, and an admission that finds no row
holds nothing. The spend is booked either way. A real-Postgres lane proves
it, and fails against the old statement (the next reply's hold drops from 10
to 0).
…in view

Findings of a second independent review of the chat tool hardening.

The cancel of a stopped program could overtake the request that starts it,
and the sandbox then answered that it knew no such program, the same answer
it gives for one that already ended; the program ran on unsupervised. The
cancel is asked a few times.

The harvest of the output box ignored the Stop: a harvest that outlived the
batch's grace stored files and recorded them as delivered for a reply that
never got them. It now hears the Stop between files and records nothing when
it ended early, so a file can be attached twice but not lost. A stopped
program's answer says its files stay in the output box and are attached by
the next run.

The harvest looked at the first 200 entries in the sandbox's listing order,
so a file written by this run could sit behind a window of old ones, and
the record was rebuilt from the window alone, so a delivered file out of
view was attached again on its return. It looks at the 200 newest files and
keeps a delivered file that is out of view recorded.

The chat watchdog's comment no longer says the heartbeat stands still while
tools run.
A work tool answers a call it could not carry out with a failure status, and
a task run's log shows a result carrying one as an error entry. The log kept
its own copy of the list, which lacked `cancelled`, the status a call stopped
with its reply now answers; the card showed a killed program as a success.
One list of failure statuses in the work tool table now feeds both the
executors' failure type and the log.
The untrusted default profile no longer mounts the organization's shared pip,
npm and bun caches, but its start still held them and created their volumes,
which added Docker calls to every light sandbox start and let a cache
volume's trouble fail a sandbox that mounts none.

One predicate, `sessionSharesPackageCaches`, now answers the question for the
argv builder, the volume setup and the hold that keeps the retention away:
an agent session without Docker inside mounts, holds and creates them; a
session with Docker inside, or one that runs untrusted code, does none of
the three. The README, a source comment, the environment reference
(English, German, French) and the manual coverage row say the same.
The mock gateway answers a work scenario's closing reply once the
conversation carries a tool result, but it read the whole conversation: after
a Stop, asking for the same work in the same chat found the earlier turn's
tool round and returned the closing reply without running anything, which
made the second leg of manual box CHAT-F72 impossible in mode A. It reads
the turn in progress, the messages after the last user message.
The sandboxes page said private addresses are blocked for light sandboxes.
A probe from a real light sandbox on a rig laid out like the Docker
deployment found cloud-metadata addresses blocked, public hosts reached
through the egress proxy, and the other services on the sandbox network, the
spawner and the backend among them, reachable by connection. The sandbox
holds no credential for them. The page now says exactly this in English,
German and French, and still points at the egress allowlist for the public
hosts.
CHAT-R22 says an image's hold is given back on the reply that took it;
CHAT-R25 that a stopped program is asked to stop a few times and its files
wait for the next run; CHAT-R27 that a run looks at the newest 200 files and
a delivered file out of view stays recorded.
@yannickmonney
yannickmonney added this pull request to the merge queue Oct 12, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 12, 2026
@yannickmonney
yannickmonney added this pull request to the merge queue Oct 12, 2026
Merged via the queue into main with commit 79926ce Oct 12, 2026
@yannickmonney
yannickmonney deleted the fix/chat-work-tools-hardening branch October 12, 2026 15:30
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.

1 participant