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.
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:
- 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 Bibentry by calling an approved database function. - 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.,
BibIOorRIO) 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.
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
LIOlibrary.
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
TYPEGUARDandCaMeLachieved 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 (
TYPEGUARDcompleted 8/21,CaMeLcompleted 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