Repository navigation
fix(platform): harden chat tools and light sandboxes after review - #4849
Merged
Merged
Conversation
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
added this pull request to the merge queue
Oct 12, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Oct 12, 2026
yannickmonney
added this pull request to the merge queue
Oct 12, 2026
This was referenced Oct 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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_codetakes 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)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.CHAT-R23; the test fails without it)defaultprofile. One predicate (sessionSharesPackageCaches) answers the question for the argv builder, the volume setup and the retention. Agent sessions keep the caches.chat_toolskill switch failed open: a policy file that fails to parse read as absent, and absent means every tool on.CHAT-R26)SBX-R26; a real-Postgres lane proves it and fails against the old query)CHAT-R27)Fixed after the second review
chat_toolsnow 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)CHAT-R22; new real-Postgres lanecheckImageHoldIdentity, mutation-checked: against the old query the next reply's hold drops from 10 to 0)run_codeafter 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)CHAT-F72impossible in mode A. It reads the turn in progress now.Not changed, and why
/healthanswers) 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, andSANDBOX_EGRESS_ALLOWLISTlimits the public hosts.explicitOnlyis 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
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 governanceroutes.test.tsand the Chat tools editor test (an unreadable policy is reported),transcript.test.ts, the mock gateway's contract test, and the spawner'sdocker-session-args.test.tsanddocker-session-cache-volumes.test.ts(a light sandbox neither creates nor holds the caches, an agent session still does).checkLightSessionSweepandcheckImageHoldIdentity, both mutation-checked.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 endedokwithdone.txtattached. A light sandbox was also probed for what it can reach (above).CHAT-F72(Stop on a running program) andCHAT-B25(unreadable policy file); automation rows inreference/automation/chat.mdandtasks.md.