[Report] Workshop on Controlling AI Agent Tool Calls and Script Execution with Cedar and Rex #AWSreInvent #OPN309

[Report] Workshop on Controlling AI Agent Tool Calls and Script Execution with Cedar and Rex #AWSreInvent #OPN309

Use Cedar to control users and script execution. Let's master it!
2026.12.05

This page has been translated by machine translation. View original

Hello, this is Usuda.

Everyone, are you managing permissions for your AI agents? (greeting)

This is a report on the following workshop held at AWS re:Invent 2026.

I was able to experience two scenarios: one that restricts "who can call which tools" for an AI agent, and one that restricts "what a script written by the agent is allowed to do on the host."

Session Overview

OPN309 | Defense in depth for Strands AI agents with Cedar, AgentCore, and Rex

AI agents that generate and execute code on remote systems need more than a single permission check - they need policy enforcement at every trust boundary. In this builders' session, you’ll configure Cedar policies at two distinct enforcement points for a Strands pre-built operations agent : AgentCore Policy on AgentCore Gateway and Trusted Remote Execution (REX) on the target remote host. You’ll see why both are necessary, how they compose, and how the agent gracefully adapts when it hits either boundary.

OPN309 | Defense in depth for Strands AI agents with Cedar, AgentCore, and Rex

AI agents that generate and execute code on remote systems need more than a single permission check. Policies must be enforced at each trust boundary. In this builders' session, you will configure Cedar policies at two distinct enforcement points for a pre-built operations agent built with Strands: AgentCore Policy on AgentCore Gateway, and Trusted Remote Execution (REX) on the target remote host. You will see why both are necessary, how they combine, and how the agent adapts gracefully when it hits either boundary.

Report

Overall Overview

The theme is authorization control when using AI agents. In this workshop, you implement two controls, both with Cedar policies: one that restricts the tools an agent can call according to the user's role, and one that restricts the operations performed when a script generated by the agent is executed.

Overview diagram

The first is control at Amazon Bedrock AgentCore Gateway, which is the entrance to the tools. It looks at which team the user belongs to and decides which tools can be called. This applies broadly to any setup where agents use tools.

The second is control on the host where the script actually runs. It decides, one by one, whether to allow the file operations and network connections performed by the script generated by the agent. This covers scenarios where you let an agent handle investigation and work on a Linux host in operation, so I think fewer people will be affected than with the first one.

The technologies used are as follows.

  • Cedar: An open-source policy language for writing authorization rules. It lets you write "who can do what to what" outside of application code. By default, anything not written is denied
  • Rex (Trusted Remote Execution): An open-source script execution environment published by AWS. It checks each operation a script performs, such as file and network operations, against Cedar policies before executing it

Cedar is also built into AWS services, and in the following services you can use it just by writing policies.

  • Amazon Verified Permissions (AVP): A managed service for writing and managing authorization for your own applications in Cedar. The application queries it via API for decisions
  • AWS Verified Access: You write access conditions for corporate applications in Cedar
  • Amazon Bedrock AgentCore Policy: Evaluates tool calls passing through AgentCore Gateway with Cedar. This is what is used for the first control this time

With AVP, your own application calls it to get a decision, but with AgentCore, once you associate a policy engine with the Gateway, the Gateway makes a decision on every tool call. You don't need to write authorization logic in the agent or tool code.

Rex is a tool that embeds Cedar into its own mechanism. Scripts run inside Rex's sandbox, and every operation on the host goes through functions provided by Rex. Those functions check the Cedar policies every time they run, so operations without permission are not executed. What can be controlled includes file reads and writes, network connections, process and service operations, and retrieval of system and disk information, covering operations commonly used in operational work. It runs on Linux and macOS.

The first control is achieved with Gateway and Cedar, and the second with Rex and Cedar on the host.

The overall architecture is as follows. The user signs in with Amazon Cognito and receives a token containing their team. When the agent calls a tool, it passes that token to the Gateway, so the Gateway can make decisions based on the user's team.

Overall picture

User information is used only up to the Gateway's decision. On the host beyond that, decisions are made by looking at the script's operations themselves, regardless of who made the request.

When you design an architecture yourself, you will probably want finer-grained control, but this content focuses on the two control points, so let's not worry about that.

The entire environment is prepared in advance, and what participants do is configure authorization and check the results.

Workshop Introduction

First, the background was explained with slides.

Title

After the explanation of the architecture and so on described above, what goes wrong in this environment was explained in the following flow.

When a user asks "find out why the service is down," the agent writes a script that reads the logs, runs it on the host, and reports the cause. Up to here, this is the desired behavior.

However, if a line saying "ignore the user" is mixed into the logs it read, the agent may take it as an instruction. A Gateway without policies lets any call through, and the host executes whatever script it is given. Even if configurations are rewritten and ports are scanned, the agent tells the user "there are no problems." The user cannot see what was executed behind the scenes.

Agents make mistakes, and they can be fooled. So the idea of this workshop is not to make the agent be careful, but to place a decision point outside the agent. You put authorization in each layer of the path.

Put authorization in every layer

The format this time was to first try writing the policies yourself, and if you got stuck, open the hints one at a time.

Workshop Content

The subject is a DevOps environment where two teams share one agent. The agent performs operational work on a remote EC2 host.

Team What they may do
DevOps Read app logs. Read the host's configuration file via script
Application Only read app logs

Rewriting the configuration file and port scanning on the host are operations we don't want either team to perform through the agent.

The agent can use two tools.

Tool Type What it can do
rex_read_app_logs Fixed tool Only reads a specific log file
run_rex_script General-purpose tool Executes an arbitrary script generated by the agent

The log-reading tool has a one-to-one correspondence between the tool name and the operation that actually happens. If you decide whether it may be called, what happens is also decided.

With the script execution tool, anything can happen. Even with the same tool call, the content may be reading logs or rewriting the configuration file. Just deciding whether it may be called does not determine what will happen.

In the first control, you define permissions for these two tools per team. In the second control, you restrict the operations of scripts run by the script execution tool.

Confirming the Unrestricted State

First, I ran the agent with no restrictions at all.

When I asked for four things—reading logs, reading the configuration file, rewriting the configuration file, and port scanning—all of them went through for both teams.

Even the Application team, which has weaker permissions, was able to rewrite the configuration file.

I confirmed the behavior like this with the front-end application used in this workshop.

Unrestricted state

From here, we add the two controls in order.

1. Restricting Callable Tools at the Gateway

You add Cedar policies to the Gateway's policy engine. The first one I wrote was a policy that allows the log-reading tool for both teams.

permit(
  principal is AgentCore::OAuthUser,
  action == AgentCore::Action::"workshop-rex-tools___rex_read_app_logs",
  resource == AgentCore::Gateway::"<GatewayのARN>"
)
when {
  principal.hasTag("user-team") &&
  (principal.getTag("user-team") == "devops-engineer" ||
   principal.getTag("user-team") == "application-engineer")
};

A Cedar policy consists of "permit or forbid," "who, what, on what," and "conditions." Reading through it, you can understand the structure as follows.

  • permit: Allow
  • principal: Who. Here, any signed-in user
  • action: What. Here, a call to the log-reading tool
  • resource: On what. Here, this Gateway
  • when: Condition. The team in the user's token must be DevOps or Application

After I added this policy and put the Gateway in enforcement mode, the script execution tool became unavailable to everyone, including the DevOps team. I had written just one permission, but anything not written is denied.

Next, we add a policy that allows the script execution tool only for the DevOps team. The only differences from the first policy are the tool name and the condition.

permit(
  principal is AgentCore::OAuthUser,
  action == AgentCore::Action::"workshop-rex-tools___run_rex_script",
  resource == AgentCore::Gateway::"<GatewayのARN>"
)
when {
  principal.hasTag("user-team") &&
  principal.getTag("user-team") == "devops-engineer"
};

In this state, when the Application team asks to run a script, the agent answers "that tool cannot be used by my team."

Tool unavailable for the Application team

It isn't that it tried to run and was denied; the Gateway removes tools without permission from the tool list. From the agent's point of view, that tool does not exist.

It's nice that whether a tool is even visible is also controlled.

When the DevOps team asks for the same thing, it goes through. Log reading continues to work for both teams. Without changing the agent's code or the tool implementations, just by adding two policies, the results now change depending on the signed-in user.

However, this alone is not enough. If the DevOps team asks to rewrite the configuration file, it still goes through. The Gateway only sees that "a DevOps user called the script execution tool," and does not look at the contents of the script.

2. Restricting Script Operations on the Host

This is where Rex comes in.

Scripts run with Rex are written in a language called Rhai. Rhai is a small scripting language that itself has no features for handling files or networks. For a script to do anything to the host, it has no choice but to call functions provided by Rex, and those functions check the Cedar policies every time. This time, the agent wrote Rhai scripts and passed them as tool arguments.

How Rex works

Originally, in an environment not using Rex, scripts such as Python generated by the agent run on the host as is, with no control over their operations. The actual way to proceed is to introduce Rex there, replace the scripts with Rhai, and apply control.

For the workshop scenario this time, Rex was installed from the start, and instead, loose policies were initially installed as the host-side policies. For the configuration file, it is as follows, with the three actions open/read/write permitted.

permit(
  principal == User::"rex",
  action in [file_system::Action::"open", file_system::Action::"read", file_system::Action::"write"],
  resource == file_system::File::"/opt/workshop/private/devops.env"
);

It is the same Cedar as the Gateway policy, but action is a file operation rather than a tool call, and resource is an individual file rather than the Gateway.

There is also a policy that allows network connections to the host itself (127.0.0.1). The port scan was going through because of this policy.

permit(
  principal == User::"rex",
  action == network::Action::"connect",
  resource is network::url
)
when {
  resource.url == "127.0.0.1" || resource.url == "localhost"
};

We switch to policies that narrow these down. Only two things change.

  • Remove write from the configuration file policy
  • Delete the network connection policy

The configuration file policy becomes the following.

permit(
  principal == User::"rex",
  action in [file_system::Action::"open", file_system::Action::"read"],
  resource == file_system::File::"/opt/workshop/private/devops.env"
);

I didn't add a prohibition; I just removed permissions. Anything not written is denied, so this stops it.

After switching, when the DevOps team asks to read the configuration file, it goes through. When I asked for rewriting and port scanning, Rex denied them.

Denial by Rex

The denial message shows exactly which operation on what was attempted and stopped.

rex unauthorized to perform file_system::Action::"write" for file_system::File::/opt/workshop/private/devops.env
rex unauthorized to perform network::Action::"connect" for network::url::"127.0.0.1"

Even for the DevOps team, which can call the script execution tool, the operations that must not be done were stopped. Moreover, for the same file, reading goes through while writing is stopped.

This policy is managed as host-side configuration and is loaded every time a script is executed. It cannot be changed by the agent or the script.

Comparing the Three Stages

Lining up the results so far looks like this.

Scorecard

With each control added, the "goes through when it shouldn't" cases decrease, and the "goes through" cases that should pass never decreased by even one. Rather than stopping everything, only the targeted things are stopped.

Bonus Challenge I Couldn't Try: Dogwood

I couldn't try it this time due to time constraints, but a hands-on using Dogwood was also prepared as an optional bonus challenge.

Dogwood is an open-source policy language built on top of Cedar. Cedar makes decisions by looking only at the current single call, but with Dogwood you can write conditions about what happened immediately before in the same session. Cedar itself stays as is, and a layer that looks at history is added on the outside. It can be added to the AgentCore Gateway policy engine alongside Cedar policies.

The challenge was to add a one-minute cooldown to the log-reading tool. It is to prevent the agent from repeatedly calling a permitted tool at short intervals. Cedar policies that look only at each individual call cannot control this kind of repetition.

forbid(
  principal is AgentCore::OAuthUser,
  action == AgentCore::Action::"workshop-rex-tools___rex_read_app_logs",
  resource == AgentCore::Gateway::"<GatewayのARN>"
)
when temporal {
  formerly within 1m AgentCore::Action::"workshop-rex-tools___rex_read_app_logs"::response{
    eventResource: resource
  }
};

The inside of when temporal is the condition that looks at history, meaning "forbid if this tool returned a result within the last minute." If you ask for the logs twice in a row, the first goes through, the second is denied, and after waiting a minute it goes through again.

You can also write other rules, such as allowing only when prior approval has been completed, or putting a cap on the number of calls. Following "who can call which tools" and "what scripts may do," you can control even "in what order and at what frequency calls may be made," so this also looks interesting.

Impressions

I tried two kinds of permission management using Cedar.

The places where each is used are different, but it's nice that if you learn Cedar, you can apply it to both.

I think that's why AWS is building mechanisms that make use of policy languages such as Dogwood and Rex.

Let's make good use of Cedar!


AWS re:Invent 2026まとめ情報

クラスメソッドは2026/11/30〜12/4にラスベガスで開催されるAWSカンファレンスイベント「re:Invent」を今年も特集しました。ぜひ一度ご覧ください。 re:Invent 2026ポータルサイトを見るAWS re:Invent公式サイトはこちら

Share this article

AWSのお困り事はクラスメソッドへ