![[アップデート] Amazon Bedrock AgentCore RuntimeでStrands Boxが使えるようになりました! #AWSreInvent](https://devio2024-media.developers.io/image/upload/f_auto,q_auto/c_limit,w_1200/v1796065643/eyecatch/dlg5ttmg1mm8clcwzkmp.png)
[アップデート] Amazon Bedrock AgentCore RuntimeでStrands Boxが使えるようになりました! #AWSreInvent
はじめに
こんにちは、コンサル部の神野です。
絶賛re:Inventに来て、Keynoteを聴いていました!
今日のアップデートでAmazon Bedrock AgentCore Runtimeがエージェントをサンドボックスに入れて動かすStrands Boxに対応しました!
これまでは自前でビルドしてスタックを用意する必要がありましたが、今回からはAgentCore CLIだけでRuntimeと通信制御用のGatewayまで作れます!
主な変更点をまとめて、公式の手順に沿ってRuntimeへのデプロイまで試してみます!
Strands Box自体は以前試していて、仕組みは下記の記事で紹介しているので合わせてご参照ください!
主な変更点
Box入りのエージェントをCLIでデプロイできる
Strands公式のサンプルではLinux ARM64の環境でBoxをソースからビルドし、
パッケージをS3に置いてスタックも自分で用意する手順になっています。
今回からはAgentCore CLIのBox用テンプレートでプロジェクトを作り、agentcore deploy を実行するだけでRuntimeと外への通信の出口になるGatewayまで作成可能です!
イメージのビルドはAWS CodeBuildで行われるので、MacからでもLinux ARM64の環境を用意せずにデプロイできました。

なおAgentCoreのドキュメントでは、Strands Boxへの対応はプレビューとなっています。
通信はBoxが判定してGateway経由で出ていく
デプロイされる構成はこんな形です。

Runtimeのセッションはそれぞれ専用のmicroVMで動き、その中でBoxがエージェントを閉じ込めます。
エージェントが外へ通信するとBoxがポリシーで判定し、許可したものだけがBox用のGatewayを通って出ていきます。
許可するホストはBoxのプロファイル(profile.toml)に書いて、ビルドのときにCLIがGatewayのターゲットへ変換してくれます。Bedrockへの呼び出しはGatewayのIAMロールで署名されるので、エージェント自身はAWSの認証情報を持ちません。
テンプレートには実行ロールの認証情報を返すインスタンスメタデータへの接続を禁止するポリシーも最初から入っていました。このポリシーは以前AgentCore PolicyのTemporal Policiesで使ったDogwoodで書かれています。
許可・拒否の判定はRuntimeのロググループにCloudWatch Logsのレコードとして1件ずつ記録されます。
インターネットへの経路がないVPCにも置ける
agentcore create に --containment private-vpc を付けると、インターネットへの経路がないVPCの中でRuntimeを動かす構成になります。作成だけ試してみると、CLIが月額の目安を表示しました。
containment: private VPC with no internet path · about $58/month while deployed for CodeZip, $88 for a container, more with 3 AZs · the VPC is kept after the stack is deleted and counts toward the account's VPC quota until you delete it
コンテナ型だと月88ドルほどかかるので結構高額ですね。
今回はデフォルトの contained でデプロイします。
前提
| 項目 | 内容 |
|---|---|
| AgentCore CLI | 1.5.0 |
| Strands Box | 0.3.3 |
| ローカルのPC | macOS 26.6.2(Apple silicon) |
| リージョン | us-east-1 |
| モデル | Claude Sonnet 5.5(テンプレートのデフォルト) |
Box用のプロジェクトはRuntimeのplatform version V2で動くので、V2に対応したリージョンを選びます。東京リージョンも対応しています。
CLIはビルドやデプロイのときにboxコマンドでプロファイルを読むので、Boxも入れておきます。
pnpm add -g @aws/agentcore@1.5.0
brew install --cask strands-agents/tap/box
やってみた
Boxのプロジェクトは公式ドキュメントでもAgentCore CLIで作る手順になっているので、今回もCLIで進めます。
プロジェクトを作る
Box用のテンプレートを指定してプロジェクトを作ります。
agentcore create --name MyBoxProject --template agent-python-strands-box-container
cd MyBoxProject
作られたBoxのプロファイルには、Bedrockへの呼び出しをAWSの認証情報で署名する設定とメタデータへの接続を禁止するポリシーファイルの指定が入っていました。
packs = ["@box/base", "@box/bedrock"]
policies = ["aws-metadata-block.dw"]
[egress.bedrock]
secret.ref = "aws://"
Dockerfileでは box run がコンテナの入口になっていて、Boxが8080番で受けたリクエストを中のエージェント(8081番)へ渡します。
ENTRYPOINT ["/opt/box/box", "run", "/home/bedrock_agentcore/box-profile/profile.toml", "--no-banner"]
外部サイトを取得するツールを足す
公式手順と同じく、GitHubかexample.comのどちらかを取得するツールを app/agent/main.py の tools.append(add_numbers) の後ろに追加します。
app/agent/main.py に追加したツール
SITES = {
"github": "https://api.github.com/zen",
"example": "https://example.com",
}
@tool
def fetch_site(site: str) -> str:
"""Fetch the first 500 characters from a known site. The site is "github" or "example"."""
import urllib.request
url = SITES.get(site)
if url is None:
return f"UNKNOWN SITE: {site}"
try:
with urllib.request.urlopen(url, timeout=10) as r:
return r.read(500).decode("utf-8", "replace")
except Exception as e:
return f"FETCH FAILED: {type(e).__name__}: {e}"
tools.append(fetch_site)
許可するホストを足す
プロファイルの末尾にapi.github.comを足します。
[egress.github]
destinations = ["api.github.com"]
ビルドすると、追加したホストがGatewayのターゲット egress-github として登録されました。
agentcore build
adding gateway target 'egress-github' to 'agent-box-egress' for api.github.com
adding target 'bedrock' to gateway 'agent-box-egress' in agentcore.json, for the boxed agent's model calls
Gatewayのターゲットを自分で書かなくても、プロファイルに書いたホストから作ってくれるのは楽ですね。
ホストを外すときもプロファイルを直してビルドし直すだけとなります。
デプロイして呼び出す
agentcore deploy
初回はCodeBuildでイメージをビルドするので、デプロイが終わるまで7分ほどかかりました。agentcore status を実行すると、GatewayにBedrock用とGitHub用の2つのターゲットがデプロイされています。
{
"resourceType": "gateway",
"name": "agent-box-egress",
"children": [
{ "resourceType": "gateway-target", "name": "egress-github", "deploymentState": "deployed" },
{ "resourceType": "gateway-target", "name": "bedrock", "deploymentState": "deployed" }
],
"deploymentState": "deployed"
}
許可したGitHubと許可していないexample.comを続けて取得するよう頼みます。
agentcore invoke --runtime agent \
--payload '{"prompt":"Use fetch_site with the site github and tell me what it returned. Then use fetch_site with the site example and tell me what happened."}'
I made both calls.
1. **github**: The call worked. It returned the text "It's not fully shipped until it's fast."
2. **example**: The call failed. It returned `FETCH FAILED: URLError: <urlopen error Tunnel connection failed: 403 Forbidden>`. The proxy tunnel refused the connection with a 403 Forbidden error, so I got no content from that site.
GitHubからは一言が返ってきて、example.comは403で拒否されましたね!
判定のログを見る
Runtimeのログから拒否の記録を探します。
agentcore logs runtime --since 15m --query '"deny"'
"strands.box.policy.action": "net:connect",
"strands.box.policy.resource": "example.com:443",
"strands.box.policy.verdict": "deny",
"strands.box.policy.cause": "no_match",
"strands.box.policy.reason": "no permit matched",
"strands.box.policy.rule": "<default-deny>"
どのルールにも当てはまらず、接続(net:connect)の段階で拒否されています。
許可の記録も含めて1行ずつに整形すると、今回の呼び出しではこう判定されていました。
permit net:connect bedrock-runtime.us-east-1.amazonaws.com:443 route_bedrock-api-key_connect
permit http:request bedrock-runtime.us-east-1.amazonaws.com:443/model/global.anthropic.claude-sonnet-5-5/converse-stream route_bedrock-api-key_request
deny net:connect example.com:443 <default-deny>
permit net:connect api.github.com:443 route_github_connect
permit http:request api.github.com:443/zen route_github_request
プロファイルに書いたgithubという名前がルール名(route_github_connect)に出ているので、どの設定で通ったのか追いやすいですね。
判定の記録を整形したコマンド
agentcore logs runtime --since 20m --query '"strands.box.policy.decision"' \
| cut -d' ' -f3- \
| jq -r 'select(.eventName == "strands.box.policy.decision") | .attributes
| [.["strands.box.policy.verdict"], .["strands.box.policy.action"],
.["strands.box.policy.resource"], .["strands.box.policy.rule"]] | @tsv'
後片付け
agentcore remove all --yes
agentcore deploy --yes
RuntimeとCodeBuildのロググループはスタックの外にあるので残ります。イメージのビルドを起動するLambdaのロググループも削除されずに残るので、公式ドキュメントの後片付けの手順で確認して消しておきます。
aws logs delete-log-group --log-group-name /aws/bedrock-agentcore/runtimes/<RuntimeのID>-DEFAULT
aws logs delete-log-group --log-group-name /aws/codebuild/<CodeBuildのプロジェクト名>
おわりに
AgentCore RuntimeでStrands Boxを使ってみました!今後統制を意識したエージェントを作りたい時に使う可能性もあるかもしれませんね!実際に使用したり運用した際にブログを書いていきたいですね!
本記事が少しでも参考になりましたら幸いです。最後までご覧いただきありがとうございました!









