Skip to content

computer: Keep exec in a read-only tool set on backends that only read - #345

Open
scuffi wants to merge 2 commits into
mainfrom
computer/readonly-exec
Open

scuffi wants to merge 2 commits into
mainfrom
computer/readonly-exec

Conversation

@scuffi

@scuffi scuffi commented Nov 25, 2026

Copy link
Copy Markdown
Member

readonly: true leaves exec out of every tool set, because a command can write files. But a backend can refuse writes itself: a CodemodeBackend built with access: "read" runs code that reads the Workspace and can't change it, which is what Backend authority suggests for different authority levels. An agent that may only read still wants to run code on that backend, and today the only way to offer it is to build the full tool set and filter out write, edit and delete by name.

This lets the backend say so. Module backends get an optional access, which CodemodeBackend sets from its access option, and runtime.backends() reports it for every backend, "read-write" for any that doesn't say. A read-only tool set keeps read, ls, find and grep, and offers exec on the backends that report "read", whether listed in exec.backends or registered:

const workspace = new Workspace({
  storage: ctx.storage,
  backends: [
    new CodemodeBackend({ id: "codemode-readonly", loader: env.LOADER, access: "read" }),
    new CodemodeBackend({ id: "codemode", loader: env.LOADER }),
  ],
});

createPiTools({ workspace, readonly: true });
// read, ls, find, grep, and exec on codemode-readonly only

With no such backend a read-only set has no exec, as before, so shell and container backends, and a set that lists only backends that write, are unchanged. The tool set doesn't decide what's safe: it trusts the access the backend reports, and the backend enforces it.

The same goes for createAITools, createTanStackTools and createPiTools, which all build from resolveToolOptions. Most of the diff in those three is re-indenting the write tools under if (!readonly) instead of returning early; it reads better with whitespace hidden.

Testing

codemode.test.ts checks that runtime.backends() reports each CodemodeBackend's access. The pi tests check that a read-only set offers exec with only the read-only backend, runs on it, and has no exec when exec.backends names only backends that write. The AI SDK and TanStack tests check that a read-only set keeps exec for a read-only backend.

A read-only tool set left out exec, since a command can write files.
But a backend can refuse writes itself: a CodemodeBackend built with
`access: "read"` runs code that can read the Workspace and not change
it. An agent that may only read still wants to run code there, so a
consumer had to build the full tool set and filter it by name.

Module backends now say what their execs may do to the Workspace, as
`access`, and `runtime.backends()` reports it for every backend,
`"read-write"` for any that doesn't say. A read-only tool set keeps
the file tools that read, and offers exec on the backends that report
`"read"`, as listed in `exec.backends` or registered. With none, it
has no exec, as before. The backend enforces the access, so the tool
set stays read-only.
@changeset-bot

changeset-bot Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8bf026e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@cloudflare/computer Patch
@cloudflare/dofs Patch
@cloudflare/computer-rpc Patch
@cloudflare/computerd Patch
@cloudflare/remote-exec Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@cloudflare/computer@345

commit: 8bf026e

@scuffi
scuffi marked this pull request as ready for review November 27, 2026 10:48

@devin-ai-integration devin-ai-integration Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.

Devin Review found 6 potential issues.

Devin Review

Comment thread .changeset/readonly-exec.md Resolved
Comment on lines +18 to +22
/**
* Omit `write`, `edit`, `delete`, and `publish`, and offer `exec` only
* on backends that can't change the Workspace, such as a
* `CodemodeBackend` with `access: "read"`.
*/

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Missing runnable read-only execution example

The example rules require an example update for public API changes. The changed readonly option has no runnable example; the pi agent already uses the tool factory.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 new potential issues.

Devin Review

Comment on lines +156 to +159
function canDetach(backends: ExecBackends, runtime: ExecWorkspaceLike["runtime"]): boolean {
return (runtime.backends?.() ?? []).some(
(info) => info.detachable === true && info.id in backends,
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Excluded backend can keep detach

canDetach counts an excluded detachable backend named constructor. defineExec finds no selected backend that can detach and rejects the tool set.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +159 to +165
/**
* Save output too long to show, and return values too large to show,
* to files in the Workspace, which the reply names. Defaults to
* `true`. With `false` the model sees them cut, and nothing is
* written: a read-only tool set turns it off.
*/
saveOutput?: boolean;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Read-only example still saves output

The RLM executor uses a read-only backend but leaves saveOutput at its default. The example does not demonstrate the new option for callers who build an exec tool directly.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

A read-only set's exec ran on backends that can't change the
Workspace, but the runtime still saved long output, and the tool
large return values, to files in the Workspace from the host, past
the backend's guard. The exec tool takes `saveOutput: false`, which
cuts them for the model with nothing written, and says so in its
description; a read-only set passes it.

A read-only set also kept `exec.detach` when no backend it kept could
detach, so building the set threw where it used to leave exec out. It
now drops `detach` in that case. TanStack's "mutating" approval no
longer gates a read-only set's exec, and the AI SDK factory's comment
says when exec is offered.
@scuffi
scuffi force-pushed the computer/readonly-exec branch from f376e7f to 8bf026e Compare November 27, 2026 11:21
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