Giving AI voices file access without giving away the machine
The fastest way to make a multi-voice conversation more useful is to let the voices look at the thing you’re talking about. It’s also the fastest way to make it dangerous.
Until tonight, every Polyphon voice worked from what you typed or pasted. Ask the ensemble to review a module and you were the file system: copy, paste, repeat when someone asked for the caller. That’s fine for a demo and tedious for real work. So API voices can now call tools: read a file, list a directory, search a tree, write a change back.
The interesting part isn’t the tools. Every agent framework ships some version of read_file. The interesting part is deciding how much of the machine a voice gets, and being honest about where that decision is actually enforced.
The original plan had no sandbox
The first plan for this work was deliberately small: three tools (read_file, write_file, list_directory), chosen per voice, with full OS-level access. No sandbox, no new process boundaries. Ship the tool-use loop, see how it feels, tighten later.
It didn’t survive contact with the obvious question. A voice with write_file and no boundary can write anywhere your user account can, and that’s not a “tighten later” problem. So what shipped grew in both directions: more tools, and a sandbox.
Ten tools, and which ones can hurt you
The registry lives in src/main/tools/, and the list of what a voice may be offered lives in one shared constant, AVAILABLE_TOOLS. Each entry carries a name, a label, a description, and one boolean that matters more than the rest: isWritable.
| Tool | What it does | isWritable |
|---|---|---|
read_file | Read a UTF-8 file, truncated at 50 KB | no |
list_directory | Recursive listing, depth 3, max 500 entries | no |
search_files | Find files by name with * and ? | no |
grep_files | Regex search across file contents | no |
fetch_url | HTTP or HTTPS GET, 10 s timeout, 50 KB | no (but see below) |
write_file | Write or overwrite a file | yes |
move_file | Move or rename a file | yes |
copy_file | Copy a file | yes |
delete_file | Permanently delete a file | yes |
run_command | Run an executable and return its output | yes |
You pick tools per voice when you build a composition. The selection is saved with that voice (composition_voices.enabled_tools, a JSON array of names), and the main process checks every name against AVAILABLE_TOOLS before it stores anything. A voice gets exactly the tools you ticked and nothing else.
isWritable is a label, not a lock. It drives the UI: writable tools render in amber with a warning triangle, and the moment a voice has any of them enabled the editor shows a banner saying this voice can modify or delete files on your machine, in every session that uses the composition. Nothing in the main process reads that flag. It exists so the dangerous choices look dangerous when you make them.
run_command is marked writable on purpose. It runs a binary directly, without a shell, with a 30-second timeout and capped output. But a command can do anything your user account can, so it sits with the tools that change things.
API voices get tools; CLI voices never do
Polyphon has two kinds of voices, which I described in the launch post: API voices that call a provider directly, and CLI voices that wrap a binary like Claude Code or Codex.
Tools are API-only. Anthropic, OpenAI, and OpenAI-compatible voices run a shared tool loop in the APIVoice base class; Gemini voices don’t support tools yet. The model asks for a tool, the main process runs it, the result goes back to the model, and the loop continues until the model returns text. It stops after ten rounds. Each call shows up inline in the response as [tool: read_file], so you can see what the voice touched without a separate log view.
CLI voices never receive tools. When VoiceManager builds a CLI voice it sets enabledTools to undefined, whatever the composition says.
Part of that is mechanical: a CLI voice is a subprocess with its own protocol, not a request/response API I can inject tool definitions into. The bigger reason is that a CLI voice is already an agent with its own tools and its own permission model. Polyphon starts it in the session’s working directory and reads what it prints. It does not and cannot sandbox what that process does. Handing it a second, Polyphon-managed set of tools would only blur whose rules apply.
That asymmetry is worth stating plainly: everything below about sandboxing applies to API voices. A CLI voice in a sandboxed session is exactly as free as it would be in your terminal.
The boundary is per session
Tools are a property of a voice. The boundary is a property of a session.
Each session can have a working directory, picked or typed when you create it and validated as you type, so you know it exists before the session starts. That directory gets written into every voice’s system prompt so the voices know where they’re working. Alongside it is a checkbox, stored as sessions.sandboxed_to_working_dir. The main process only honors the flag when a working directory is actually set; ask for a sandbox without one and you get an unsandboxed session.
When the flag is on, each API voice re-resolves its tools with the working directory as a sandbox root, and its system prompt gains a line telling it that paths outside the directory will be rejected. The same composition can run sandboxed in one session and wide open in another. Which tools a voice should have is a question about its role. How far it should reach is a question about the job in front of you today.
How the sandbox actually works
The sandbox is a wrapper, not a rewrite. sandboxTools() takes the resolved tool list and returns a new list where each tool’s execute checks its path arguments before calling the original. A small table says which arguments are paths: path for the read, write, list, and delete tools; source and destination for move and copy; directory for the two search tools; cwd for run_command.
For each path argument:
const resolved = resolve(sandboxDir, String(raw));
const rel = relative(sandboxDir, resolved);
if (rel.startsWith('..') || isAbsolute(rel)) {
throw new Error('Access denied: path is outside the sandboxed working directory');
}That handles the three shapes a model actually produces:
- Relative paths resolve against the working directory, not the app’s process directory, so
src/index.tsmeans what the voice thinks it means. ..traversal is normalized away byresolve()before the check, so../../etc/passwdandsubdir/../../../etc/passwdboth land outside and get rejected.- Absolute paths pass through
resolve()unchanged and then fail therelative()test if they’re outside. An absolute path inside the sandbox is fine.
The check is a little too strict in one spot: a file inside the sandbox whose name starts with two dots, like ..cache, also fails the startsWith('..') test. That’s a false rejection, not an escape, so it can wait.
Two optional arguments default to the sandbox when the model leaves them out: run_command’s cwd and search_files’ directory. Without that, an omitted argument would quietly mean the app’s own working directory. Required arguments don’t get the same treatment; more on that below.
A blocked call never reaches the real tool. The error comes back to the model as the tool result, so the voice sees “Access denied” and can try again inside the lines. The unit tests pin all of this: traversal from inside, absolute paths outside, both ends of a move, the defaults, and the fact that the original execute is never called on a rejected path. None of them catch the gaps below.
What a path check doesn’t cover
A lexical path check is a good guardrail for a confused model. It is not a security boundary against a model that’s been steered by something it read, which is the realistic threat once a voice can fetch web pages or open files someone else wrote. That’s prompt injection, and I’d rather write the gaps down than let the word “sandbox” imply more than it does.
Two of them are bugs.
Symlinks. The check compares path strings; it never asks the file system where a path really leads. A symlink inside the working directory that points outside it passes the check, and read_file or write_file will follow it. list_directory skips symlinks because it uses lstat. search_files and grep_files mean to skip them, but they use stat, which follows the link first, so the skip never fires and a symlinked directory gets walked. The fix is to resolve real paths before comparing.
Empty paths. Only the two optional arguments default to the sandbox. If a model sends an empty path to list_directory or an empty directory to grep_files, the wrapper lets it through and the tool resolves it against the app’s own working directory. That should be a rejection.
Until those are fixed, don’t sandbox a directory that contains symlinks you didn’t create, and treat the sandbox as a guardrail rather than a guarantee.
The rest are trade-offs I made on purpose.
run_command. Only its cwd is checked. The executable and its arguments are not, so cat with an absolute path outside the sandbox runs fine from a sandboxed working directory. That’s why it’s marked writable and why I don’t enable it on voices that read untrusted content.
fetch_url. It has no path arguments, so the sandbox doesn’t touch it. It’s marked read-only because it doesn’t change your disk, but a voice with read_file and fetch_url can read a file and pack its contents into a request to any URL it likes in the same turn. Read-only describes the disk, not the data.
No approval step. An enabled tool runs when the model calls it. There’s no per-call confirmation. The [tool: …] markers tell you what happened, after it happened.
The trade-off
I could have built something stricter: per-call approvals, a separate process with OS-level sandboxing, an allowlist of commands. Each of those makes the feature safer and slower to use, and some of them would make the voices useless for the job I built this for, which is letting an ensemble work on a real project directory while I watch.
What I chose instead is two layers you can reason about. Per voice: which capabilities it has at all, with the destructive ones impossible to miss in the editor. Per session: whether those capabilities stop at a directory. And underneath both, the one layer Polyphon doesn’t provide: your own OS user, which is still the real boundary.
A sandboxed voice can’t wander out of the working directory by accident. A voice reading a web page written to manipulate it might still find one of the gaps above, which is why fetch_url, run_command, and a write tool on the same voice deserve a second look.
The pattern I’m starting with: research voices get the read-only tools. The one voice allowed to change files gets write tools in a sandboxed session and nothing that reaches the network. Nobody gets run_command casually.
Polyphon is at coreydaley.dev/projects/polyphon. Free, local-first, no account required.
When you give an AI voice access to your files, are you trusting the sandbox, the model, or your own ability to read the tool log after the fact?