Engineering notes · Agent permissions
Code Mode raises a familiar question for us at Keller: how can agents work with fewer interruptions while we retain control over their actions? Some longstanding ideas from programming languages offer a useful starting point.
No Haskell background assumed.
More work between model calls #
Anthropic recently introduced experimental Code Mode in Claude Code. The idea is straightforward: the agent writes JavaScript that calls its tools, processes the results, and returns the information it needs. It can put a loop or a conditional in that code instead of coming back to the model for every decision. The feature is available from version 2.1.323. Anthropic’s documentation explains the current behavior.
The benefits are practical: fewer model round trips, less intermediate data in context, and opportunities to run independent operations in parallel. Code can handle the bookkeeping between calls. The speedup depends on the task, but work that previously required another model response can often proceed directly. Anthropic described the broader approach in its earlier article on code execution with MCP.
As coding agents become more capable, the way we handle permissions becomes increasingly important. How can we let them work at full speed, with fewer interruptions for us, while keeping our systems safe?
For us, a recurring concern is the point where an agent interacts with an external system. Reading a document, changing a file, or sending data to a service requires a decision about whether that action is appropriate. You may be comfortable letting an agent write the code while still wanting control over those effects.
The cost of answering “allow” #
Some tasks required my agents to work outside the sandbox and make changes on my host computer. I wanted to approve those actions, but switching windows to find each prompt and understand it kept interrupting my work. I built Agent Dock, inspired by AgentPeek, to bring Claude Code and Codex permission requests into a macOS menu-bar panel.
Bringing the prompt into view reduces the interruption, but you still have to understand the proposed action.
The choice can feel like a toggle. Broad permission lets the agent proceed, including with actions you might not have intended. Requiring approval for sensitive operations preserves your opportunity to intervene, but repeatedly draws your attention back to the task. More selective rules help, though you still have to decide which categories of action to authorize in advance.
Code Mode still s for individual tool calls that need your approval under your permission settings. Auto mode already has a classifier review the whole snippet before execution, while deny rules, ask rules, and tool hooks still apply to individual calls. This already makes a group of operations the subject of a single review. The distinction is documented here.
We are interested in what that review could establish before execution. Alongside an assessment of the code, could the snippet carry a concise, machine-checked statement of its permitted effects?
A limited way to reach the outside world #
One part of the answer comes from capability security. A capability gives its holder authority to perform particular operations on a particular resource. An open file handle that permits reading is a useful example. Possessing it lets the program read that file; it need not confer permission to open every other file on the machine.
For an agent, imagine a small service window. It can ask for a document through that window and hand back an edited version. There is no door beside it that opens onto your entire computer. In software terms, that means the program must have no alternate route through a shell, raw filesystem access, or another tool with broader authority.
This has a long history. Capsicum brought capability-based compartmentalization to Unix applications. Deno provides a familiar, related example of explicit permissions: a program can be granted reads under one directory or network access to one host. Its permissions are shared by code on the same thread, so that is not the same as giving each library its own object capabilities. Deno’s security documentation makes this scope clear.
Mobile apps have made restricted access familiar too. Android and iOS combine application sandboxes with permissions or entitlements. These are related approaches to limiting authority; neither should be described simply as a pure capability system.
What about Linux? #
Linux has several relevant mechanisms with different meanings. Linux capabilities, such as CAP_NET_ADMIN, divide privileges traditionally associated with root. They are not object capabilities for individual documents or URLs.
Landlock lets an unprivileged process restrict its own access and that of its descendants. It is a practical way to reduce ambient filesystem and other rights. There was also a Capsicum port to Linux; that page describes an experimental port against Linux 3.11.1, not a claim that ordinary Linux installations provide FreeBSD’s Capsicum API.
These are useful places to look for enforcement. They answer different questions from a type checker, which can examine how a program uses the interface before execution.
Code Mode is not itself the complete boundary pictured above. Its shell sandbox does not isolate the JavaScript or its non-shell tool calls. Anthropic documents that distinction.
Confinement gives us a place to enforce permissions. We also need a way to describe a particular piece of work inside that boundary. “This program can read documents” is useful. “This program can update only documents it has already read” gives you a more specific basis for approval.
Where type systems can help #
I became interested in Haskell years ago and attended conferences and a meetup in Boston. I read the monad tutorials too, including the burrito analogies and the posts explaining why those analogies were unhelpful. I was the intended audience for both.
One idea from that period is especially relevant here: a function’s type can tell you something about what it is allowed to do before you run it.
The claim in the title concerns the underlying techniques. Haskell did not solve coding-agent permissions twenty years ago, but it provided ways to separate effects and enforce abstraction boundaries that we can apply to this problem. Some of the foundations are older still: Launchbury and Peyton Jones described type-enforced encapsulation of mutable state in 1994. The examples below show how those ideas can inform agent permissions.
Let's consider a simple function that counts words:
There is no file read in that signature. The caller supplies the text. In Haskell’s safe language subset, this function cannot open a file or send the text to a server. It can compute, fail, or run forever, but it cannot perform those external operations.
Reading a file has a different type:
IO makes the distinction visible, but it is broad. A function returning IO Int could read a file, write one, or make a network request before returning its number. The type does not tell you which of those operations it uses. Haskell’s I/O model gives us the first separation; a narrower interface supplies the next one.
We can define an interface with just a read operation, and write our function against that:
CanRead is a type class: an interface that an execution environment can implement. The variable m stands for that environment’s computation type. The part before ⇒ says what the function requires. In plain language, the function can produce a word count in any environment that supports file reading.
The body shows the sequence. do groups the actions; <- names the value returned by one; pure returns a result without adding an external operation.
The Monad constraint lets us chain actions and feed a result into the next step. It does not itself provide a file writer or a network client.
Suppose the agent inserts writeText path "" into this function. If writeText requires a separate CanWrite m constraint, the body no longer fits the declared type. The checker rejects it. The function has to work for any permitted m that supports reading, including environments that have no writer.
This guarantee depends on restricting agent code to approved imports and trusted implementations of these operations. It cannot also get arbitrary IO, an unsafe escape hatch, or the ability to redefine what a trusted operation does. Safe Haskell exists to help preserve type and module boundaries when code is untrusted. Compiling an arbitrary Haskell project with unrestricted build steps would not establish this boundary.
Within that setup, the signature gives us a checked upper bound. It says reading is available to this function. It does not say the function will read exactly once, or that every permitted read would be appropriate.
The same idea through a branch and a loop #
Suppose you are writing an article and ask an agent to find a few sources on a topic and save a local note with excerpts. Search once; if there are no results, try a broader query. Fetch up to three results and write the note.
In the style of Code Mode, the orchestration could look like this. These are illustrative tool names, not Anthropic’s API:
The equivalent Haskell program keeps the same branch and loop. Its signature lists the three capabilities it requires:
The search result can change which branch runs. It can change which pages we fetch. Neither choice gives the code another capability. The compiler checks both branches and the loop body under the same constraints.
For approval, this means we can establish a useful limit without knowing the search results in advance: the task cannot launch a shell or edit arbitrary project files. That conclusion depends on the trusted search, fetch, and report operations exposing only the authority described.
The signature leaves other questions unanswered. It does not count the calls, identify the query strings, or establish that the report will be useful. A wider signature can list a capability the body never uses. What it establishes is a bound, not an exact forecast.
Where the arguments came from #
“May fetch pages” is still a broad permission. For this research task, you might want a narrower rule: fetch only URLs returned by a search in this run.
We can change the interface so a search returns a special value, and fetching requires that value:
The earlier gatherSources function already fits this interface: it passes each search result directly to fetchPage. If the agent substitutes an arbitrary URL string, the types no longer match.
The host needs to issue real search-result values only after a search succeeds, validate them when used, and keep them bound to the current run. The simple type above does not distinguish sessions by itself. A session index in the types, or a host-side check of the issuing session, can supply that additional restriction.
The exact URLs are unknown before execution, yet we can establish the relationship between search and fetch beforehand. The permission describes where the URLs must come from without requiring their values in advance.
This is a provenance rule. A malicious page can still appear in search results. The rule tells you how the URL was obtained. You still have to decide whether that provenance is sufficient grounds to permit the fetch. The fetch implementation also needs an explicit redirect policy, since a search result can redirect somewhere else.
Editing a file only after reading it
The same technique fits a familiar frustration with coding agents: an agent edits a file without first reading what is there. Give the read operation a result that the write operation requires:
Here App has a fixed, restricted set of operations. The read must complete before the host issues the file value, and the write must actually validate that value. Haskell is lazy, so simply adding an unused evidence argument to an otherwise unrestricted writer would not force a read to happen.
For “read the relevant README first,” add another step:
The trusted host determines which README governs that file, reads it, and issues a new value tied to the same file. A read of some unrelated README cannot satisfy the prerequisite. The writer must also handle file identity and concurrent changes correctly, for example by rejecting a replacement when the version read is no longer current.
This proves a modest but useful property: the prerequisite operation occurred before the write. It cannot prove the agent understood the README or followed its advice. Reading a rule and complying with it are different requirements.
Fixed destinations and call counts
Some facts are available even before the first tool result. If a task fetches two specified documentation pages, we can represent those requests as an inspectable plan:
A reviewer for this restricted plan can list both URLs and count two planned fetches without performing them. This comes from the plan representation and its trusted interpreter. Ordinary Haskell does not automatically extract URL literals or call counts into a type signature. Nor does “two planned fetches” mean both will complete; a failure can stop the run.
In the research example, the fallback makes the search count one or two, and take 3 bounds the loop at three fetches. Those are properties of this particular body, assuming the helpers add no tool calls. The capability signature alone says nothing about the count.
A system could verify such bounds with an indexed or graded computation type. It could also enforce a per-run quota in the tool broker, charging every attempt, including retries, against the approved budget. Linear types offer another way to design consumable authority, but require a suitable execution interface: putting a linear arrow on a token does not prevent replaying an ordinary reusable IO action. GHC’s linear-types extension is a newer development, outside the set of techniques available in Haskell twenty years ago.
We would favor the simpler mechanism where it expresses the rule clearly. The useful result is an approval that states its limits accurately, including which parts are checked statically and which are enforced while the task runs.
One decision for this piece of work #
When an agent submits a new piece of code, the system could derive a summary of its possible effects before executing it. You would review that summary and approve or deny the submission. The sequence below uses the research example from earlier: the code comes first, followed by a checked description of the work it may perform.
Reviewing one submitted piece of code
Gather sources for an article about Haskell and agent permissions
Find up to three sources and save excerpts to notes/haskell-sources.md.
One snippet containing several tool calls
let hits = await tools.search("Haskell capability security");
if (hits.length === 0) {
hits = await tools.search("typed effects security");
}
const excerpts = [];
for (const hit of hits.slice(0, 3)) {
const page = await tools.fetchPage(hit);
excerpts.push(excerpt(page));
}
await tools.writeReport(render(excerpts));
The host’s writeReport operation targets the file named above. The snippet has not run yet.
What this submitted code may do
- Search
- One call, plus a fallback if the first returns no results. At most 2 calls.
- Fetch
- Up to 3 pages, using only results from those searches.
- Write
- At most 1 replacement of
notes/haskell-sources.md. - Other access
- No shell commands or other file writes.
Derived from the code and trusted tool contracts. Types establish capabilities and provenance; counts require analysis of the branch and loop. This example assumes pure text helpers and no automatic retries.
Allow this code to execute with these limits?
Approval applies to this submission and this execution. New code receives its own summary and decision.
What would this approval cover?
The examples below explain the scope of this submission. “Yes” means the operation is covered if you approve the code above. It does not authorize that operation in a future snippet or session.
| Example operation | Covered? |
|---|---|
| Run the fallback search when the first search returns no results. | Yes |
| Fetch up to three results returned by those searches. | Yes |
Save the excerpts to notes/haskell-sources.md . |
Yes |
| Fetch a fourth page or a URL found inside a fetched page. | No |
| Write to another file or execute a shell command. | No |
If the submitted code requested one of the “No” examples, its summary would need to include that additional authority for you to consider before execution.
One approval covers the branch and loop in the submitted code. You can see that the fallback search is conditional and that the loop fetches at most three results. Once you approve the snippet, those operations can proceed without separate decisions from you.
A revised snippet that fetches a fourth page or saves to another file would produce a different summary and require its own decision. Approval is attached to the submitted code, not retained as a general permission for later work.
This preserves your ability to judge a particular situation while reducing the number of decisions you have to make. The summary must be checked against the submitted code and its tool contracts. During execution, the runtime still enforces constraints that depend on live values, such as the provenance of search results and the identity of the output file.
The binding matters. Approval must refer to the checked code, its trusted dependencies, and the granted policy, so the agent cannot replace the program after review. It also cannot mint its own authority. Ordinary host protections still apply. A task-level grant should not override a narrower organizational restriction.
There is still judgment involved. A report writer could overwrite a good note with a bad one. A search query could disclose information you did not intend to send. If those are the concerns, the policy needs to cover file versions, query contents, or information flow as well. A verified property helps only when it addresses the risk you need to control.
More room than a single permission slider #
We can apply these ideas without requiring agents to use Haskell. Other languages can express related properties; Koka, for example, makes effects part of its type system. A restricted language for agent tasks could expose an even smaller set of concepts.
There is also a connection to formal verification tools such as Lean. Strictly speaking, Lean is not an alternative to type systems: its kernel checks proof terms in a dependent type theory. It lets us express and prove richer propositions than the simple interfaces here. Its documentation explains that division between producing a proof and checking it.
We could use such tools to prove properties of the policy machinery, or of a task whose behavior needs a more detailed specification. For a simple “this operation requires evidence of that read” rule, a carefully designed abstract type may already be enough. The scope of the guarantee matters more than which tool produced it.
There are costs. Someone has to design the interfaces, implement the trusted wrappers correctly, and keep the review understandable. Broad tools are harder to constrain: permission to execute an arbitrary shell command says very little about the command’s effects. A system that exposes narrower operations may be easier to reason about but take more work to integrate.
The distinction is clearest with a permission such as “always allow web search.” Researching public documentation may be appropriate, while a query containing confidential customer information may not be. The capability is the same; the context changes the decision. A standing permission skips that judgment even when most uses would be acceptable. Reviewing a checked task preserves the opportunity to decide in context, while allowing its approved operations to run together.
Code Mode makes the unit of work larger. We expect approval systems to evolve toward reviewing those larger units through more precise descriptions of their effects. Whole-snippet classification is one approach already being tried. Checked effect summaries and explicit grants seem like a useful addition.
An agent could present the work it proposes, the limits it fits within, and the properties that have been checked. You could decide whether those actions are appropriate in this context, then let the submitted code proceed. That preserves the judgment a standing permission would skip, without requiring another decision for every tool call.
Haskell gives us a useful precedent: we can design an interface so that specific properties of a program follow from its type. We still have to choose properties that reflect the decisions we care about. At Keller, that is what makes these techniques worth revisiting as agents take on more work: they could let tasks finish faster while preserving our ability to decide what is appropriate in each situation.
The Haskell fragments illustrate proposed interfaces and omit the trusted tool implementations. They have not been compiler-checked. The diagrams describe proposed mechanisms rather than a shipped integration. Product behavior was checked against the linked documentation on November 23, 2026.