Language-Based Agent Control

Timothy Zhou, Loris D'Antoni, Nadia Polikarpova

TL;DR

Language-Based Agent Control (LBAC) is a new programming model that secures LLM agents by forcing them to interact with the world through a pure, type-safe programming language. By compiling agent actions into code that must pass a strict type-checker before execution, LBAC guarantees that agents cannot violate fine-grained security policies like data provenance or information-flow control.

What Problem Does This Paper Address?

Mainstream AI agent frameworks force developers into a frustrating trade-off between expressiveness and control.

On one hand, you can give an agent an unconstrained code interpreter (like a sandboxed Python environment). This makes the agent highly expressive and capable of complex, arbitrary computations, but it is incredibly difficult to secure. A sandboxed interpreter can stop an agent from wiping your hard drive, but it can't enforce application-level rules—such as preventing an agent from fabricating data or accidentally leaking Customer A's data to Customer B.

On the other hand, you can restrict the agent to a fixed set of specialized tools. While this offers strong control, it strips away flexibility. The agent can no longer write code to filter, sort, or compose tool outputs efficiently on its own.

Figure 1: Implementing a literature search agent using a code interpreter, specialized tools, and TYPEGUARD (our approach). Sandboxed interpreters (left panel) enable expressive program composition, but allow the agent to bypass the library and fabricate entries using the raw file-write function from the standard library. Restricted tools (middle) enforce strong control by restricting access to trusted operations, but limit expressiveness; our example requires modifying the set of tools so that the only tool we provide for writing to file also fetches the bib entry directly from the database. TYPEGUARD (right) reconciles this tradeoff: the agent can write programs and compose operations freely, while the type system enforces that all written entries originate from trusted sources.

Methods

The authors introduce LBAC, a model that treats agent control as a type-checking problem. To demonstrate this, they built TYPEGUARD, a practical implementation in Haskell.

Instead of interacting via raw text commands or rigid tool APIs, the agent communicates by generating code within an Embedded Domain-Specific Language (EDSL) defined by the developer. The safety of the application relies on two core features of a pure, typed language like Haskell:

  1. Abstract Data Types: By hiding the internal constructors of specific data types, developers can prevent the agent from forging sensitive data tokens. For example, the agent can only obtain a Trusted Bib entry by calling an approved database function.
  2. Purity: In a pure language, side effects (like reading/writing files or making network calls) are explicitly tracked in the type signature. The agent is restricted to a custom effect monad (e.g., BibIO or RIO) that only exposes safe, policy-compliant operations.

When an agent call is triggered, the LLM generates a piece of code. TYPEGUARD runs this code through the Haskell type-checker against a strictly defined target type. If the code fails to type-check, the error is fed back to the LLM to try again. If it passes, it is guaranteed to be safe and is executed.

Figure 2: Overview of the Language-Based Agent Control (LBAC) model. The entire agentic system is expressed within a single typed host language (in the case of TYPEGUARD, Haskell): developer- written scaffolding, agent-generated programs, and library code all live in the same environment. An agent call generates code, which must type-check before execution. As a result, the type system acts as the outer layer of control, ensuring that any property it enforces (e.g., capabilities, information-flow control, or resource bounds) holds for the entire system. Because TYPEGUARD is built in Haskell, it can directly leverage the rich ecosystem of existing type systems.

Datasets

The authors evaluated TYPEGUARD using the Slack suite of AgentDojo, a benchmark designed to test prompt-injection vulnerabilities and task utility in LLM agents. The evaluation consisted of 21 benign user tasks and 5 injection tasks, creating a total of 105 attack combinations.

Key Insights and Ideas

  • "If it type-checks, it is safe": The core philosophy is that if the host language's type system can guarantee a property for all well-typed programs, it will inherently guarantee it for agent-generated code too.
  • Dynamic Interleaving without Separation: Previous prompt-injection defenses often rely on strict "code/data separation"—forcing the agent to write all its code upfront before seeing untrusted data. LBAC completely removes this constraint. Agents can dynamically read data, reason, and spin up sub-agents because the type system enforces security hierarchically at every step.
  • Leveraging Decades of PL Research: Instead of inventing new security architectures, LBAC allows developers to import existing, battle-tested security libraries completely off-the-shelf. For instance, the authors implemented Information Flow Control (IFC) simply by integrating Haskell’s mature LIO library.

Key Results

The authors compared TYPEGUARD against CaMeL (a state-of-the-art language-based defense) using GPT-5.4-2026-03-05:

  • Perfect Security: When security policies were enabled, both TYPEGUARD and CaMeL achieved 100% security, successfully resisting all 105/105 prompt injection attempts under both direct and "important instructions" attacks.
  • Comparable Utility: Without security policies, both systems completed 15 out of 21 benign tasks. When strict information-flow policies were turned on, utility dropped similarly for both systems (TYPEGUARD completed 8/21, CaMeL completed 7/21). This drop occurs because strict security policies conservatively reject complex data flows that cannot be explicitly proven safe.

Limitations and Future Work

The primary limitation is the observed drop in utility when strict policies are enforced. Because the type system is highly conservative, it can reject benign agent programs if the information flow looks ambiguous.

For future work, the authors suggest exploring richer type disciplines to make policies more expressive without sacrificing safety. This includes refinement types (for functional correctness), linear types (for enforcing one-shot authorizations), and amortized resource analysis (to bound an agent's execution time or API spending limits).

Summary updated

BibTeX
@inproceedings{zhou2026language,
  author = {Timothy Zhou and Loris D'Antoni and Nadia Polikarpova},
  title = {{Language-Based Agent Control}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=16tteJWMPL},
}
Figure