← Latest papers
🤖 AI

LACUNA: Safe Agents as Recursive Program Holes

LACUNA is a safe programming model for LLM agents that treats actions as typed program holes filled by the model and validated via static type-checking before execution, thereby unifying agent control flow with generated code while preventing runtime failures and bounding tool access.

Original authors: Yaoyu Zhao, Yichen Xu, Oliver Bračevac, Cao Nguyen Pham, Frank Zhengqing Wu, Martin Odersky

Published 2026-05-28
📖 6 min read🧠 Deep dive

Original authors: Yaoyu Zhao, Yichen Xu, Oliver Bračevac, Cao Nguyen Pham, Frank Zhengqing Wu, Martin Odersky

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you are the CEO of a company, and you hire a brilliant but slightly unreliable assistant (the AI) to do your work.

The Old Way (Current Agents):
Usually, you give the assistant a specific, tiny instruction: "Call the phone company." The assistant does exactly that, then stops and waits for your next command. You hold the clipboard, decide the order of tasks, and keep the keys to the office. The assistant can't decide to call the bank instead, or to rewrite the office rules, because they only have a single button to press at a time.

The Problem:
Sometimes, the assistant gets confused by a tricky note you wrote (a "prompt injection"), or they get halfway through a task and make a mistake, leaving the office in a messy, inconsistent state. Because the assistant is only allowed to press buttons, they can't break the building, but they can still cause a lot of chaos within the room they are in.

The New Way (LACUNA):
The paper introduces LACUNA, which changes the relationship. Instead of giving the assistant a single button to press, you give them a blank space in a contract (a "typed hole") and say, "Fill this space with whatever code you need to solve this problem, but it must fit perfectly into our legal contract."

Here is how it works, using simple analogies:

1. The "Magic Contract" (Typed Holes)

Imagine you have a contract that says, "The final result of this section must be a List of Numbers."

  • You ask the AI: "Go find the prime numbers in this list."
  • The AI writes a whole paragraph of instructions (code) to solve it.
  • The Safety Check: Before the AI is allowed to actually do anything, a strict Inspector (the compiler) checks the AI's paragraph.
    • Does the paragraph actually result in a "List of Numbers"? If the AI tries to return a "List of Apples," the Inspector rejects it immediately.
    • Did the AI try to use a tool they aren't allowed to touch? (e.g., trying to open a file they don't have a key for). The Inspector catches this too.
    • The Result: If the AI makes a mistake, the contract is rejected before any action happens. The office stays clean. The AI gets the rejection notice, tries again, and writes a better paragraph.

2. The "All-or-Nothing" Rule

In the old way, if an AI tried to "Delete a file" and then "Calculate a sum," and the calculation failed, the file might already be deleted.
In LACUNA, it's like a single, indivisible block of clay.

  • The AI sculpts the whole block.
  • The Inspector checks the entire block at once.
  • If any part of the sculpture is wrong (the wrong shape, the wrong material), the entire block is thrown away. Nothing happens. The office remains exactly as it was before the AI started. This prevents "half-finished" disasters.

3. The "Key Ring" (Capabilities)

The paper also talks about Capabilities. Imagine the AI is given a specific set of keys (a key ring) for the job.

  • If the job is "Read the menu," the AI gets the "Menu Key."
  • If the job is "Send an email," the AI gets the "Email Key."
  • Even if the AI is tricked by a bad note saying, "Use the Bank Key to steal money," they physically cannot do it. They don't have the Bank Key in their pocket. The Inspector checks their key ring before they are allowed to turn the lock.
  • This means even if a hacker tricks the AI into trying to do something bad, the AI literally lacks the "keys" to open those doors.

4. The "Nested Russian Dolls" (Recursion)

The AI can write code that includes more instructions for itself.

  • You ask: "Write a report on three topics."
  • The AI writes a plan that says: "First, I will ask the AI to research Topic A, then Topic B, then Topic C, and finally combine them."
  • Each of those smaller requests is also a "hole" that gets checked by the Inspector before it runs. It's like a set of Russian nesting dolls, where every single doll is inspected before it's allowed to open.

What the Paper Actually Found

The researchers tested this system (LACUNA) using a programming language called Scala 3.

  • Safety: They found that the "Inspector" caught about 8.6% of the AI's attempts before they could run. These were attempts that were either the wrong shape or tried to use tools the AI didn't have permission for.
  • Retry: When the AI made a mistake, the system asked it to try again. On average, it only took 0.7 tries to get a valid answer.
  • Performance: The system solved about 27% of difficult research tasks and 76% of customer service tasks. This was roughly the same as other standard AI agents, proving that adding this strict safety check didn't make the AI "dumber," just safer.
  • Security: They tested the system against hackers trying to trick the AI (prompt injection). Because the AI was limited by its "key ring" (capabilities), the hackers could not get the AI to do things outside its allowed scope, even if they successfully tricked the AI into trying.

The Catch (Limitations)

The paper admits a few things:

  • It's not perfect: The Inspector checks if the AI followed the rules (did it use the right tools? did it return the right type of answer?), but it doesn't check if the AI did the right thing logically. If the AI writes a perfect code that calculates the wrong math, the Inspector lets it through.
  • It needs a smart AI: If the AI isn't very good at writing code, it will get rejected often, and the process will be slow.
  • It's slower: Because the system has to stop, check, and re-check the code every time, it takes more time and computing power than just letting the AI press a button.

In summary: LACUNA turns the AI from a button-pusher into a contractor who must submit a full plan for approval before doing any work. If the plan breaks the rules, the work never starts, keeping the system safe from mistakes and tricks.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →