Skip to main content

Browser Scripting (Sandbox)

Sometimes the useful thing an agent can do is run code, like transforming a file, computing a result, or testing a snippet. @distri/fs ships a script runner that executes code in the browser, with the user in the loop before anything runs.

The script_runner tool

ScriptRunnerTool is a UI tool. When the agent calls it, the user sees an editor pre-filled with the agent's proposed code, picks a language, and presses Run. The result goes back to the agent:

import { ScriptRunnerTool } from '@distri/fs';

<Chat agent={agent} threadId="repl" externalTools={[ScriptRunnerTool]} />

Supported languages: JavaScript, TypeScript, Python, and bash. On run, the tool dispatches a distri_execute_code call with the language, code, and any metadata, and streams the output back into the conversation.

Human-in-the-loop by design

The agent proposes and the person decides. Nothing executes until the user hits Run, so an agent can't silently run arbitrary code. The editor is the gate. This is the same in-product tool pattern used for approvals and forms, applied to code execution.

Testing scripts against files

Pair it with the IndexedDB filesystem and the ScriptTestingPanel component to run scripts against a project's files and see the output side by side:

import { ScriptTestingPanel } from '@distri/fs';

<ScriptTestingPanel projectId="project-123" />