Dev.to AI 🤖 Ai 👁 0 📖 12 min read

Putting AI in a Cage: The Architecture of Controlled Intelligence

"AI agents can reason, use tools, modify files, and execute tasks. But how do we give them useful capabilities without surrendering control? A practical look at the architecture behind controlled AI." Puttin

Putting AI in a Cage: The Architecture of Controlled Intelligence

"AI agents can reason, use tools, modify files, and execute tasks. But how do we give them useful capabilities without surrendering control? A practical look at the architecture behind controlled AI."

Putting AI in a Cage: The Architecture of Controlled Intelligence

I've been thinking about a particular question as AI systems become more capable:

How do we give artificial intelligence the ability to do things without giving it unrestricted authority to do anything?

We're moving beyond systems that simply generate text.

AI agents can interact with APIs, inspect repositories, execute commands, modify files, retrieve information, and coordinate other tools. Some can work through multiple steps toward a goal without requiring a person to approve every individual action.

That changes the security conversation.

We're no longer discussing only what a model might say. We're discussing what an entire system might do because a model was given the ability to act.

And that distinction matters.

I started thinking about this through the idea of putting AI in a cage.

Not necessarily preventing intelligence from operating, but creating an environment where its capabilities have boundaries.

The more I explored the idea, the more I realized that the model itself is only one part of the problem.

The surrounding architecture matters just as much.

1. The model isn't the entire system

When people discuss AI safety, conversations often focus on the model.

Its training.
Its alignment.
Its instructions.
Its refusal behavior.
Its ability to recognize harmful requests.

These are important, but they don't represent the entire security boundary.

Consider a coding agent.

The model might receive an instruction to inspect a project, identify a bug, modify some files, and run tests.

To complete that task, the system might have access to:

  • A language model.
  • A filesystem.
  • A terminal or shell.
  • A code repository.
  • External APIs.
  • Package managers.
  • Network access.
  • Credentials.
  • An execution environment.

The model is reasoning about what to do, but the surrounding tools determine what it can actually do.

If the model makes a mistake, misunderstands an instruction, or processes malicious input, the consequences depend heavily on the authority available to it.

A model can be instructed not to delete important files.

But if the agent has unrestricted filesystem access, that instruction is not an enforceable security boundary.

This is where I think the architecture needs to change.

We should not depend entirely on an intelligent system choosing to behave safely when we can design its environment to limit the consequences of unsafe behavior.

2. The seven layers of controlled intelligence

I began organizing this idea into seven connected layers.

Each layer has a different responsibility, and none should be mistaken for the entire security system.

Layer 1 — Model

This is the intelligence layer.

It receives context, interprets instructions, generates responses, and determines what action it believes should happen next.

It could be:

  • A locally hosted model.
  • A cloud-hosted model.
  • A specialized coding model.
  • A model selected dynamically through a routing system.

The important architectural distinction is that the model should be replaceable.

The system should not depend on one model being permanently available, trustworthy, or capable of handling every task.

A model provides intelligence. It should not automatically become the authority governing the entire environment.

Layer 2 — Orchestration

The orchestration layer coordinates the work.

It determines which model or tool handles a task, manages context, tracks workflow state, and coordinates execution.

For example:

  1. Receive a coding request.
  2. Retrieve relevant project documentation.
  3. Identify the files involved.
  4. Assign the task to an appropriate model.
  5. Coordinate tool usage.
  6. Collect the result.
  7. Send the result through validation.

This layer also provides an opportunity to enforce workflow rules.

An agent should not be able to invent its own permissions simply because it decides another tool would be useful.

Orchestration coordinates capability. It should not silently grant unrestricted authority.

Layer 3 — Permissions

This is where the system begins establishing enforceable boundaries.

What can the agent access?

Can it:

  • Read files?
  • Modify files?
  • Execute shell commands?
  • Access the internet?
  • Interact with APIs?
  • Read credentials?
  • Modify repositories?
  • Deploy applications?
  • Spend money?

These permissions should be defined according to the actual task.

For example, an agent asked to review a repository does not automatically need permission to modify it.

An agent asked to edit a particular project does not automatically need access to the user's entire filesystem.

The principle is least privilege: provide only the access necessary to complete the assigned work.

Permissions should be enforced outside the model, at the application, operating system, API, or infrastructure level.

A prompt saying "do not access this directory" is not equivalent to a filesystem permission preventing access.

Layer 4 — Execution

The execution layer is where the agent's decisions become actions.

This might involve:

  • Running terminal commands.
  • Executing scripts.
  • Modifying source code.
  • Installing dependencies.
  • Calling external services.
  • Running automated tests.

Execution needs a controlled environment.

Depending on the risk, that could mean a task-scoped workspace, container, virtual machine, restricted account, or dedicated sandbox.

Isolation matters because a mistake should not automatically become a problem for the host machine or production environment.

However, a sandbox is not magic.

Its effectiveness depends on its configuration, exposed interfaces, mounted directories, credentials, network access, and isolation boundaries.

An environment that has unrestricted access to sensitive host resources is not meaningfully restricted just because it is called a sandbox.

Layer 5 — Validation

This layer answers a question that is surprisingly easy to overlook:

How do we know the agent actually completed the task correctly?

An agent reporting success is not proof of success.

A generated application compiling is not proof that it is secure.

A completed code modification is not proof that the modification is appropriate.

Validation can include:

  • Unit and integration tests.
  • Static analysis.
  • Dependency scanning.
  • Security testing.
  • Schema validation.
  • Reviewing generated changes.
  • Checking expected outputs.
  • Comparing results against acceptance criteria.

The validation process should be as independent as practical from the model that generated the result.

The system needs evidence, not simply confidence.

Layer 6 — Observability

A controlled system needs a record of what happened.

What did the agent attempt?

Which tools did it call?

Which files did it modify?

What commands were executed?

What failed?

What resources were consumed?

Which actions required approval?

Observability makes the system easier to investigate, debug, evaluate, and improve.

It also helps distinguish between an agent that completed a task through the expected workflow and one that reached the same apparent result through an unintended path.

Logging must be designed carefully.

Credentials, API keys, private information, and sensitive user data should not be exposed through logs simply because the system is recording activity.

Layer 7 — Human Control

This is the layer that preserves accountability.

Not every action needs a human approval prompt.

An agent performing a read-only inspection or running an approved test suite can often operate without interrupting the user.

But certain actions deserve explicit authorization.

For example:

  • Publishing an application.
  • Deploying to production.
  • Deleting important data.
  • Changing permissions.
  • Modifying credentials.
  • Making financial transactions.
  • Sending external communications.

The objective is not to prevent automation.

It is to distinguish between actions that can safely happen within an established boundary and actions that require human judgment or authorization.

The agent can prepare the deployment.

The human can authorize the deployment.

Those are two different responsibilities.

3. Where things can go wrong

The architecture becomes easier to understand when we look at how its layers can interact with real threats.

One important example is prompt injection.

An AI agent may retrieve a webpage, inspect a repository, read an email, or process a document.

That content could contain instructions deliberately designed to manipulate the agent.

The agent might interpret those instructions as something it should follow, even though they came from an untrusted source.

This becomes particularly dangerous when the agent has access to tools.

Imagine an agent instructed to summarize a collection of documents.

One document contains malicious instructions asking the agent to retrieve sensitive files and transmit them to an external endpoint.

The problem is no longer limited to generating an incorrect summary.

If the agent has the necessary permissions and execution capabilities, the malicious content could influence real actions.

This is why prompt injection cannot be solved simply by adding another instruction telling the model to ignore malicious instructions.

The surrounding system must also limit what happens when the model gets manipulated.

Some practical protections include:

  • Treat retrieved content and tool outputs as untrusted input.
  • Separate instructions from data wherever possible.
  • Restrict access to sensitive resources.
  • Require explicit authorization for consequential actions.
  • Validate tool arguments and outputs.
  • Monitor unexpected tool usage.
  • Avoid exposing secrets to the model or unnecessary tools.

The goal is to make a successful manipulation less consequential.

OWASP identifies prompt injection and excessive agency among the major security risks affecting LLM applications. Its guidance is useful because it moves the discussion beyond the model and toward the application surrounding it.

4. Excessive agency: when capability becomes authority

There is another distinction I think deserves attention.

Capability and authority are not the same thing.

An agent might be capable of accessing a database.

That does not mean it should have unrestricted authority to modify every record.

It might be capable of executing shell commands.

That does not mean every command should be permitted.

It might be capable of interacting with external APIs.

That does not mean it should be able to transmit arbitrary information.

This is the problem of excessive agency.

When an AI system receives too much functionality, too many permissions, or too much autonomy, unexpected model behavior can have consequences far beyond the original task.

A useful way to approach this is to separate the agent's capabilities into permission categories.

Permission Example Typical control
Read Inspect project files Scoped filesystem access
Write Modify source code Task-specific writable directory
Execute Run scripts or tests Command allowlists and isolation
Network Contact external services Restricted egress and approved destinations
Credentials Authenticate to APIs Scoped, short-lived credentials
Publish Release an application Explicit human approval
Delete Remove important resources Strong authorization and recovery controls

The important point is that these permissions should not be bundled together by default.

An agent does not need every capability simply because the system supports it.

5. A practical example: building a controlled coding agent

Let's bring this down to something more tangible.

Suppose I want to build an AI coding agent that can inspect a repository, fix bugs, and test its changes.

I would not start by giving it unrestricted access to my development environment.

I would start with a smaller workflow.

Step 1 — Define the task

The agent receives a specific objective, the relevant project context, and clear acceptance criteria.

Step 2 — Retrieve context

It reads the project documentation and relevant source files.

At this stage, read-only access may be sufficient.

Step 3 — Plan the changes

The agent identifies the files it intends to modify and explains the proposed changes.

Step 4 — Execute within a boundary

It receives write access only to the appropriate workspace.

Commands and network access are restricted according to the task.

Step 5 — Validate

Tests run, generated changes are inspected, and relevant security checks are performed.

Step 6 — Record the outcome

The system records meaningful actions, errors, changes, and test results.

Step 7 — Request authorization

If the task requires publishing, deploying, deleting, or changing something consequential, the agent pauses for human approval.

This is not the most autonomous possible coding agent.

That is precisely the point.

The objective is not to maximize the number of actions an agent can perform.

It is to maximize the amount of useful work it can complete safely and verifiably.

6. Local AI doesn't automatically mean secure AI

I also want to address something that comes up frequently when discussing local AI.

Running a model locally can improve privacy and reduce dependence on external providers.

Tools such as Ollama make local inference accessible, and local models can be useful components in a more private, cost-conscious architecture.

But local inference does not automatically make an agent secure.

A locally running agent can still:

  • Delete important files.
  • Execute unsafe commands.
  • Expose credentials.
  • Install malicious dependencies.
  • Modify code incorrectly.
  • Access resources it should not access.

The location of the model and the authority of the agent are separate architectural questions.

A local model with unrestricted shell access can still cause serious damage.

Likewise, a hosted model can operate within a tightly controlled environment.

The security boundary needs to exist around the entire workflow, regardless of where inference happens.

7. The architecture is only useful if it can be tested

A diagram can make a system look secure.

A collection of security rules can make it sound secure.

Neither proves that the implementation works.

The architecture needs to be tested against realistic failure scenarios.

For example:

Test scenario Expected behavior
Agent attempts to read a restricted file Access denied
Retrieved document contains malicious instructions Content treated as untrusted data
Agent attempts an unauthorized shell command Execution blocked
Agent produces invalid output Validation rejects it
Agent attempts to publish without approval Workflow pauses
Agent exceeds its resource budget Execution is limited or stopped
Agent fails during execution Failure is recorded and recovery is possible

These are examples of acceptance criteria, not proof that a particular implementation already enforces them.

The implementation needs to demonstrate the expected behavior through actual tests.

This is also where frameworks such as the NIST AI Risk Management Framework, the NIST Generative AI Profile, and MITRE ATLAS become useful references.

They provide ways to think about AI risks, system-level controls, and adversarial techniques rather than treating model behavior as the only security concern.

8. What does putting AI in a cage actually mean?

I initially approached this as a technical problem.

Build a sandbox.
Restrict permissions.
Control execution.
Monitor behavior.

But the more I thought about it, the more the question expanded.

Can we govern powerful intelligence simply by placing boundaries around it?

The technical answer is that we can establish meaningful boundaries around the systems we build.

But those boundaries do not make the model inherently trustworthy, eliminate every possible failure, or guarantee that every future interaction will be predictable.

There is a difference between controlling an environment and understanding everything that can happen inside it.

And there is a difference between creating a capable system and deciding how that capability should be used.

That second distinction is just as important as the first.

As the cost of producing and reproducing software decreases, more people will be able to create systems with capabilities they may not fully understand.

Generating code is not the same as understanding the system it creates.

Giving an agent access to a tool is not the same as knowing how safely it will use that tool.

And allowing automation to complete a task is not the same as transferring responsibility for the outcome.

For me, this is where cybersecurity, AI development, and the broader philosophy behind building systems meet.

We need to become better at directing capability, not simply increasing it.

The architecture should make that principle concrete.

The model provides intelligence. The architecture establishes boundaries. Verification provides evidence. Human judgment remains accountable.

Putting AI in a cage is not about making intelligence powerless.

It is about making sure that capability does not become unrestricted authority.

References and further reading

  1. OWASP — Top 10 for Large Language Model Applications (2025)
  2. OWASP — LLM06:2025 Excessive Agency
  3. NIST — Artificial Intelligence Risk Management Framework
  4. NIST AI 600-1 — Generative Artificial Intelligence Profile
  5. MITRE ATLAS — Adversarial Threat Landscape for AI Systems

This article presents a practical architectural approach to AI agent security. The seven-layer model is a design framework, not a claim that one architecture can eliminate every AI-related risk.

More of My Work

The whole library: TagzAuthor

Support the work: ko-fi.com/tagzauthor

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.