ファイルシステム構成によるセッション状態の永続化とシェルコマンドの実行
AWSはAmazon Bedrock AgentCore Runtimeにセッション状態の永続化とシェルコマンド実行機能を追加し、AIエージェントの開発・運用におけるファイルシステム消失とコマンドルーティングの課題を解決する。
キーポイント
AIエージェントのファイルシステム消失問題
マイクロVMアーキテクチャによりセキュリティは確保されるが、セッション終了時に生成物や依存関係が全て消失する実務上の課題がある。
AgentCore Runtimeの新機能公開
セッション状態を永続化する「Managed session storage」と、環境内でシェルコマンドを直接実行する「InvokeAgentRuntimeCommand」の2つが追加された。
開発ワークフローの効率化と標準化
LLM経由や外部ツールリングに頼らず、安全な環境内でnpm testやgit pushなどの決定論的操作を直接実行可能になり、開発体験と計算リソースの効率が向上する。
制御プレーンクライアントの初期化
boto3を使用してAWS Bedrock Agent Coreの制御プレーンクライアントを指定リージョンで初期化し、ランタイムの作成・管理を行う。
Session State Persistence & Seamless Resume
Configuring filesystemConfigurations with a mount path automatically persists files to managed storage. Stopping or timing out a session terminates the compute environment, but resuming with the same runtime-session-id mounts the storage to a new microVM, preserving all files and state without re-downloading or reinstalling.
Data Retention & Version Management
Session storage data is retained for 14 days of idle time by default, after which it is cleaned up. Updating the agent endpoint to a different version automatically refreshes the session data, providing a clean context for the new version.
Deterministic Shell Command Execution
InvokeAgentRuntimeCommand enables executing known shell commands directly inside a running session and streaming output over HTTP/2. This is optimal for deterministic, validation-focused operations (e.g., npm test), whereas the LLM agent should be reserved for reasoning, creative work, or complex decision-making.
影響分析・編集コメントを表示
影響分析
AIエージェントの実用化において、セッション状態の保持と環境内コマンド実行はインフラ層の重要な進歩である。AWSがこの機能を公式サポートすることで、開発者はカスタムツールリングに依存せず安全かつ効率的なエージェント運用が可能になる。これにより、エンタープライズレベルのAIワークフロー標準化が加速すると予想される。
編集コメント
エージェント開発の実務課題を的確に捉えた機能追加であり、今後は同様の「状態管理」機能が主要クラウドベンダー間で標準化されるだろう。技術的な堅牢さと開発者体験の向上を両立した実用的なアップデートだ。
AIエージェントはチャットを超えて大幅に進化しました。コードの生成、ファイルシステムの状態の永続化、シェルコマンドの実行、そしてファイルシステム全体を通じた状態管理は、エージェントが行えることの一例です。エージェンティックなコーディングアシスタントや開発ワークフローが成熟するにつれ、ファイルシステムはエージェントの主要な作業メモリとなり、コンテキストウィンドウを超えた能力を拡張しています。この変化は、本番環境のエージェントを構築するすべてのチームが直面する2つの課題を生み出します。
・ファイルシステムは揮発性です。エージェントのセッションが終了すると、インストールされた依存関係や生成されたコード、ローカルのGit履歴など、エージェントが作成したすべてのものが消去されます。
・npm testやgit pushのような決定論的な操作が必要なワークフローの場合、大規模言語モデル(LLM)を介してルーティングするか、ランタイム外の独自ツールを開発するかの二者択一を迫られます。どちらの選択肢も最適ではありません。
Amazon Bedrock AgentCore Runtimeは、現在2つの機能によってこれらの課題に対処しています。1つ目はエージェントのファイルシステム状態を永続化する管理されたセッションストレージ(パブリックプレビュー)です。2つ目は、各アクティブなエージェントセッションに関連付けられたマイクロVM内で直接シェルコマンドを実行するための「コマンド実行(InvokeAgentRuntimeCommand)」です。それぞれ単独でも有用ですが、組み合わせることで以前は不可能だったワークフローが可能になります。
この投稿では、エージェントのファイルシステム状態を永続化するために管理されたセッションストレージを使用する方法と、エージェントの環境内でシェルコマンドを直接実行する方法について説明します。
エージェントコアランタイムセッション内
エージェントコアランタイムは、各セッションを専用のmicroVMで実行します。これには、独自のカーネル、メモリ、ファイルシステムを含む隔離されたリソースが含まれます。このアーキテクチャは強力なセキュリティ境界を提供しますが、すべてのセッションがクリーンなファイルシステムから起動することを意味します。microVMが明示的なstopまたはアイドルタイムアウトを通じて終了すると、エージェントが作成したすべてのものが消滅します。
これが実際に何を意味するかを考えてみましょう。コーディングエージェントがプロジェクトのスケルトン作成に20分費やします:ディレクトリ構造の設定、依存関係のインストール、ボイラープレートコードの生成、ビルドツールの設定などです。あなたが昼食のために席を離れ、戻ってきて同じセッションを呼び出すと、エージェントは最初からやり直します。すべてのパッケージが再インストールされ、すべてのファイルが再生成されます。エージェントが有用な作業を再び行えるようになる前に、20分間の計算リソースが無駄になります。この制限は、セッションを停止する前にファイルをAmazon Simple Storage Service (Amazon S3) にアップロードし、再開時にダウンロードするか、セッションを存続させて状態を失わないようにするチェックポイントロジックを書くことで解決できます。このワークアラウンドは機能しますが、ファイルシステムレベルの制限に対処するものではなく、エージェントコードに複雑さが追加されます。
決定論的な操作においても同様の摩擦が生じます。エージェントが修正を終え、テストを実行する必要がある場合、コマンドをツール呼び出しとしてLLM経由でルーティングすると、予測可能な操作にトークンコスト、レイテンシ、非決定性が追加されます。別の選択肢は、ランタイムの外部で独自のオーケストレーションロジックを構築することですが、これにはエージェントのファイルシステムに接続する必要があり、複雑さが増します。
管理されたセッションストレージ(パブリックプレビュー):存続する状態
最初の課題である、エフェメラル(一時的)なファイルシステムの問題は、管理されたセッションストレージによって解決されます。これにより、エージェントに停止/再開サイクルをまたいで存続する永続的なディレクトリが提供されます。この永続性はランタイムに組み込まれており、エージェント作成時に設定されます—計算環境が置き換えられても、そのディレクトリに書き込まれたすべてのデータは存続します。
永続ストレージの設定
永続ストレージを設定するには、次の操作を行います。
エージェントランタイムのファイルシステム設定(filesystemConfiguration)にセッションストレージ(sessionStorage)を追加します:
aws bedrock-agentcore create-agent-runtime \
--agent-runtime-name "coding-agent" \
--role-arn "arn:aws:iam::111122223333:role/AgentExecutionRole" \
--agent-runtime-artifact '{"containerConfiguration": {
"containerUri": "123456789012.dkr.ecr.us-west-2.amazonaws.com/my-agent:latest"
}}' \
--filesystem-configurations '[{
"sessionStorage": {
"mountPath": "/mnt/workspace"
}
}]' または、Python 用 AWS SDK(Boto3)を使用します:
import boto3
# ランタイムの作成と管理にコントロールプレーンのクライアントを使用する
control_client = boto3.client('bedrock-agentcore-control', region_name='us-west-2')response = control_client.create_agent_runtime(
agentRuntimeName='coding-agent',
agentRuntimeArtifact={
'containerConfiguration': {
'containerUri': '123456789012.dkr.ecr.us-west-2.amazonaws.com/my-agent:latest'
}
},
roleArn='arn:aws:iam::111122223333:role/AgentExecutionRole',
protocolConfiguration={
'serverProtocol': 'HTTP'
},
networkConfiguration={
'networkMode': 'PUBLIC'
},
filesystemConfigurations=[{
'sessionStorage': {
'mountPath': '/mnt/workspace'
}
}]
)
Note: AgentCore uses two Boto3 service clients. The control plane client (bedrock-agentcore-control) handles runtime lifecycle operations like CreateAgentRuntime, GetAgentRuntime, and DeleteAgentRuntime. The data plane client (bedrock-agentcore) handles session operations like InvokeAgentRuntime and InvokeAgentRuntimeCommand. The mount path must start with /mnt followed by a folder name (for example, /mnt/workspace or /mnt/data). After configured, any file that your agent writes to this path is automatically persisted to managed storage.
The stop/resume experience
You invoke your agent and ask it to set up a project:
aws bedrock-agentcore invoke-agent-runtime \
--agent-runtime-arn "arn:...:agent-runtime/coding-agent" \
--runtime-session-id "session-001" \
--payload '{"prompt": "Set up the project and install dependencies in /mnt/workspace"}'
必ずJSON形式で返してください:
{"translation": "response = control_client.create_agent_runtime(\n agentRuntimeName='coding-agent',\n agentRuntimeArtifact={\n 'containerConfiguration': {\n 'containerUri': '123456789012.dkr.ecr.us-west-2.amazonaws.com/my-agent:latest'\n }\n },\n roleArn='arn:aws:iam::111122223333:role/AgentExecutionRole',\n protocolConfiguration={\n 'serverProtocol': 'HTTP'\n },\n networkConfiguration={\n 'networkMode': 'PUBLIC'\n },\n filesystemConfigurations=[{\n 'sessionStorage': {\n 'mountPath': '/mnt/workspace'\n }\n }]\n) \n\n \\nNote: AgentCore uses two Boto3 service clients. The control plane client (bedrock-agentcore-control) handles runtime lifecycle operations like CreateAgentRuntime, GetAgentRuntime, and DeleteAgentRuntime. The data plane client (bedrock-agentcore) handles session operations like InvokeAgentRuntime and InvokeAgentRuntimeCommand. The mount path must start with /mnt followed by a folder name (for example, /mnt/workspace or /mnt/data). After configured, any file that your agent writes to this path is automatically persisted to managed storage.\n\n \\n## The stop/resume experience\n \\nYou invoke your agent and ask it to set up a project:\n\n \\n \\n aws bedrock-agentcore invoke-agent-runtime \\\n --agent-runtime-arn \"arn:...:agent-runtime/coding-agent\" \\\n --runtime-session-id \"session-001\" \\\n --payload '{\"prompt\": \"Set up the project and install dependencies in /mnt/workspace\"}'", "technical_terms": ["Boto3", "control plane client", "data plane client", "runtime lifecycle operations", "session operations", "mount path", "managed storage"]}
エージェントはコードをダウンロードし、パッケージをインストールして、そのセッション専用のマイクロVM内で設定ファイルを生成します。その後、セッションを終了するかアイドルタイムアウトが発生すると、マイクロVMは終了します。
同じ runtime-session-id を指定して再度呼び出します:
aws bedrock-agentcore invoke-agent-runtime \
--agent-runtime-arn "arn:...:agent-runtime/coding-agent" \
--runtime-session-id "session-001" \
--payload '{"prompt": "Run the tests and fix any failures"}'
新しい計算環境(マイクロVM)が起動し、同じストレージをマウントします。エージェントは、ソースファイル、node_modules、ビルド成果物、.git の履歴を含む、以前の状態のまま /mnt/workspace を確認できます。エージェントは再インストールや設定再生成を行うことなく、中断した箇所から処理を再開します。
エージェントの観点からは、特別なことは何も起きていません。通常どおりディレクトリに対してファイルの読み書きを行っています。エージェントのコードを変更する必要はありません——特別な API も、保存/復元ロジックも、シリアライズ処理も不要です。/mnt/workspace にファイルを書き込み、セッションを停止して再開すれば、そのファイルはそこに存在します。
昨日のセッションの計算環境(マイクロVM)は消滅しましたが、ファイルシステムは存続しています。
データの存続期間を制御する
デフォルトでは、セッションストレージのデータは14日間のアイドル時間後に保持されます。この期間内にセッションが再開されない場合、データはクリーンアップされます。エージェントエンドポイントが異なるバージョンに更新され、同じ runtime-session-id が呼び出されると、セッションデータはリフレッシュされます。これにより、マウントされたディレクトリには新しいバージョン用のクリーンなコンテキストが提供されます。
複数日にわたる開発ワークフロー
実際にこれがどのように見えるかを見ていきましょう。1日目 – コーディングエージェントを呼び出し、コードベースのダウンロード、ファイルの確認、開発環境の設定を依頼します:
aws bedrock-agentcore invoke-agent-runtime \
--agent-runtime-arn "arn:...:agent-runtime/coding-agent" \
--runtime-session-id "fefc1779-e5e7-49cf-a2c4-abaf478680c4" \
--payload '{"prompt": "s3://amzn-s3-demo-bucket/fastapi-demo-main.zip からコードをダウンロードし、すべてのファイルを一覧表示してください"}'
エージェントはリポジトリを /mnt/workspace にダウンロードし、展開して、以下のように報告します:
fastapi-demo-main プロジェクト内のファイル:
- Dockerfile
- README.md
- main.py
- requirements.txt
あなたはラップトップを閉じて帰宅します。2日目 – 同じセッションIDで呼び出します:
aws bedrock-agentcore invoke-agent-runtime \
--agent-runtime-arn "arn:...:agent-runtime/coding-agent" \
--runtime-session-id "fefc1779-e5e7-49cf-a2c4-abaf478680c4" \
--payload '{"prompt": "main.py に hello_world という新しい関数を追加してください"}'
エージェントは、プロジェクトを最後に変更した状態のまま正確に認識します。main.py を直接修正します。再ダウンロードも、再解凍も不要です。ファイルの一覧をエージェントに依頼すると、新しい hello_world 関数が追加された修正済みの main.py を含むすべてのファイルが表示されます。昨日作成された計算環境(microVM)はすでに終了していますが、作業内容は保持されています。
これは最初の課題に対応するものですが、ここでエージェントが新しいコードを記述したので、その動作を確認する必要があります。これが2つ目の機能の出番です。
シェルコマンドの実行:エージェントの環境内で直接実行される決定論的操作
2つ目の課題である、LLMを介さずに決定論的操作を実行する問題は、InvokeAgentRuntimeCommand によって解決されます。実行中の AgentCore Runtime セッション内でシェルコマンドを直接実行し、その出力を HTTP/2 経由でストリーミングとして返すことができます。
重要な洞察は、エージェントとシェルコマンドが異なる得意分野を持っていることです:
コマンドの実行を使用する
エージェントを使用する
既知のコマンドを持つ操作(npm test、git push など)
推論が必要な操作(「このコードを分析してバグを修正する」など)
同じコマンドで同じ結果が得られる決定論的な実行を望む場合
LLM に行動を判断させたい場合
長時間実行されるプロセスからのストリーミング出力が必要である場合
ループ内でツールを使用するエージェントが必要である場合
ワークフロー内の検証ゲートとしての操作
創造的または分析的な作業としての操作
エージェントが開始される前に環境をブートストラップしている
エージェントにタスクの作業を依頼している
エージェントがコードの記述を終え、テストを実行する必要がある場合、そのために大規模言語モデル(LLM)を必要とするべきではありません。npm testは単に npm test です。コマンドは既知のものであり、動作は決定論的であるべきであり、LLM による解釈ではなく、生の出力結果を求めています。
コマンドの実行
AWS SDK for Python (Boto3) を使用してコマンドを実行します:
import boto3
import sys
client = boto3.client('bedrock-agentcore', region_name='us-west-2')
response = client.invoke_agent_runtime_command(
agentRuntimeArn='arn:aws:bedrock-agentcore:us-west-2:111122223333:runtime/my-agent',
runtimeSessionId='session-id-at-least-33-characters-long',
body={
'command': '/bin/bash -c "npm test"',
'timeout': 60
}
)
for event in response['stream']:
if 'chunk' in event:
chunk = event['chunk']
if 'contentStart' in chunk:
print("Command execution started")
if 'contentDelta' in chunk:
delta = chunk['contentDelta']
if delta.get('stdout'):
print(delta['stdout'], end='')
if delta.get('stderr'):
print(delta['stderr'], end='', file=sys.stderr)
if 'contentStop' in chunk:
stop = chunk['contentStop']
print(f"\nExit code: {stop.get('exitCode')}, Status: {stop.get('status')}")
レスポンスは、リアルタイムで3つのイベントタイプをストリーミングします:
| イベント | 発生タイミング | 内容 |
|---|---|---|
| contentStart | 最初のチャンク | コマンドの開始を確認 |
| contentDelta | 実行中 | stdout および/または stderr の出力 |
| contentStop | 最後のチャンク | exitCode とステータス(COMPLETED または TIMED_OUT) |
出力は生成されながらストリーミングされるため、完全な実行を待つことなく、最初の数秒で失敗を検知し即座に対応することができます。
コンテナ、同じファイルシステム
これが重要なポイントです:コマンドは、サイドカーやソケットを介して通信する別プロセスではなく、エージェントと同じコンテナ、ファイルシステム、環境内で実行されます。エージェントが /mnt/workspace/fix.py に書き込んだファイルは、cat /mnt/workspace/fix.py を実行するコマンドから即座に参照可能です。同期ステップやファイル転送、設定が必要な共有ボリュームはありません。
AgentCore Runtime のマイクロVMには、デベロッパーツールがデフォルトで含まれていません。これはつまり、コマンドが依存する git、npm、言語ランタイムなどのツールは、コンテナイメージに追加するか、実行時に動的にインストールする必要があることを意味します。
利用方法を形作る設計上の選択
- 一発実行。各コマンドは新しい bash プロセスを起動し、完了(またはタイムアウト)するまで実行され、結果を返します。コマンド間の永続的なシェルセッションは存在しません。これはエージェントフレームワークがコマンド実行を利用する方法、つまりコマンドを構築し、実行し、出力を読み取り、次の行動を決定するという挙動に一致しています。
- 非ブロッキング。コマンドの実行はエージェントの呼び出しをブロックしません。同じセッション内で、エージェントの呼び出しとコマンドの実行を並行して行うことができます。
- コマンド間でステートレス。各コマンドは新規に開始され、シェル履歴や前回のコマンドから引き継がれる環境変数はありません。状態を保持する必要がある場合は、コマンド内にそれをエンコードしてください:
cd /workspace && export NODE_ENV=test && npm test。
何人がそれを使って構築しているか
- テスト自動化 — エージェントがコードを記述した後、コマンドとして
npm testやpytestを実行します。出力をストリーミングし、特定の失敗をエージェントにフィードバックして反復処理を行います。
- Git ワークフロー — ブランチ作成、コミット、プッシュは決定論的です。コマンドとして実行し、バージョン管理のロジックを大規模言語モデル(LLM)から分離します。
- 環境ブートストラップ — エージェントが開始する前に、リポジトリをクローンし、パッケージをインストールし、ビルドツールチェーンを設定します。これらは直接コマンドとして実行されるため、より高速かつ信頼性が高くなります。
- ビルドパイプライン — 指定されたとおりに正確に実行されるべき、既知のコマンドを持つあらゆる処理。例:
cargo build --release、mvn package、go build。
- 検証ゲート — エージェントがコードを記述した後、コミットする前に実行されるリンター、型チェッカー、セキュリティスキャナーなどの検証ゲートを実行します。
- デバッグ — 実行時環境を調査する:インストールされたパッケージ、ディスク使用量、実行中のプロセスを確認します。これらはエージェントの失敗を理解する際に有用です。
一緒に使用するとさらに強力:ファイルシステムが共有コンテキストとなる
管理されたセッションストレージ(公開プレビュー中)は、一時的なファイルシステムの課題に対処します。Execute command は決定論的操作の課題に対処します。それぞれ単独でも価値がありますが、全体ワークフローを結びつける同じファイルシステムを共有するため、組み合わせることでより強力になります。
エージェントランタイムに /mnt/workspace で管理されたセッションストレージが構成されている場合、すべてが同じ永続ディレクトリ上で動作します:
- InvokeAgentRuntime はコードを記述し、アーティファクトを生成し、/mnt/workspace 内のファイルを管理します。
- InvokeAgentRuntimeCommand はテスト、git 操作、ビルドを実行し、同じ /mnt/workspace から読み書きを行います。
- セッションを停止します。コンピューティング(microVM)がスピンダウンし、/mnt/workspace が永続化されます。
- 翌日再開します。新しいコンピューティングが同じストレージをマウントします。エージェントとコマンド実行の両方が、同じファイルを見ることができます。
ファイルシステムは、エージェントの推論、決定論的操作、そして時間を結びつける共有コンテキストとなります。これがコード上でどのように見えるかを示します:
import boto3
import json
client = boto3.client('bedrock-agentcore', region_name='us-west-2')
AGENT_ARN = 'arn:aws:bedrock-agentcore:us-west-2:111122223333:runtime/my-coding-agent'
SESSION_ID = 'fefc1779-e5e7-49cf-a2c4-abaf478680c4'
def run_command(command, timeout=60):
"""シェルコマンドを実行し、終了コードを返します。"""
response = client.invoke_agent_runtime_command(
agentRuntimeArn=AGENT_ARN,
runtimeSessionId=SESSION_ID,
contentType='application/json',
accept='application/vnd.amazon.eventstream',
body={'command': command, 'timeout': timeout}
)
for event in response.get('stream', []):
if 'chunk' in event and 'contentStop' in event['chunk'
原文を表示
AI agents have evolved significantly beyond chat. Writing code, persist filesystem state, execute shell commands, and managing states throughout the filesystem are some examples of things that they can do. As agentic coding assistants and development workflows have matured, the filesystem has become agents’ primary working memory, extending their capabilities beyond the context window. This shift creates two challenges that every team that’s building production agents runs into:
- The filesystem is ephemeral. When your agent’s session stops, everything that it created, like the installed dependencies, the generated code, or the local git history disappears.
- When your workflow needs a deterministic operation like npm test or git push, you’re forced to route it through the large language model (LLM) or build custom tooling outside the runtime. Neither option is good.
Amazon Bedrock AgentCore Runtime now addresses both challenges with two capabilities: managed session storage for persistent agent filesystem state (public preview) and execute command (InvokeAgentRuntimeCommand) for running shell commands directly inside the microVM associated with each active agent session. Each of them is useful on its own. Together, they unlock workflows that weren’t possible before.
In this post, we go through how to use managed session storage to persist your agent’s filesystem state and how to execute shell commands directly in your agent’s environment.
Inside an AgentCore Runtime session
AgentCore Runtime runs each session in a dedicated microVM with isolated resources, including its own kernel, memory, and filesystem. This architecture provides strong security boundaries, but it also means that every session boots into a clean filesystem. When the microVM terminates, whether through explicit stop or idle timeout, everything that the agent created disappears.
Think about what that means in practice. Your coding agent spends twenty minutes scaffolding a project: setting up directory structures, installing dependencies, generating boilerplate code, configuring build tooling. You step away for lunch, and when you come back and invoke the same session, the agent starts from scratch. Every package re-installed, every file re-generated. Twenty minutes of compute burned before the agent can do useful work again. This limitation can be addressed by writing checkpoint logic to upload files to Amazon Simple Storage Service (Amazon S3) before stopping a session and downloading them on resume or to keep sessions alive to avoid losing state. This workaround can work, but it doesn’t address the limitations at the filesystem level and complexity is being added into agent code.
The same friction exists for deterministic operations. When the agent finishes a fix and you need to run tests, routing the command through the LLM as a tool call adds token cost, latency, and non-determinism to a predictable operation Another option is to build a separate orchestration logic outside of the runtime, which requires you to connect to the agent’s filesystem, adding complexity.
Managed session storage (public preview): state that survives
The first challenge, ephemeral filesystems, is addressed by managed session storage. It gives your agent a persistent directory that survives stop/resume cycles. Persistence is built into the runtime and configured at agent creation—everything written to that directory survives even when the compute environment is replaced.
Configuring persistent storage
To configure persistent storage, do the following:
Add sessionStorage to your agent runtime’s filesystemConfiguration:
aws bedrock-agentcore create-agent-runtime \
--agent-runtime-name "coding-agent" \
--role-arn "arn:aws:iam::111122223333:role/AgentExecutionRole" \
--agent-runtime-artifact '{"containerConfiguration": {
"containerUri": "123456789012.dkr.ecr.us-west-2.amazonaws.com/my-agent:latest"
}}' \
--filesystem-configurations '[{
"sessionStorage": {
"mountPath": "/mnt/workspace"
}
}]'Or using the AWS SDK for Python (Boto3):
import boto3
# Use the control plane client for creating and managing runtimes
control_client = boto3.client('bedrock-agentcore-control', region_name='us-west-2')
response = control_client.create_agent_runtime(
agentRuntimeName='coding-agent',
agentRuntimeArtifact={
'containerConfiguration': {
'containerUri': '123456789012.dkr.ecr.us-west-2.amazonaws.com/my-agent:latest'
}
},
roleArn='arn:aws:iam::111122223333:role/AgentExecutionRole',
protocolConfiguration={
'serverProtocol': 'HTTP'
},
networkConfiguration={
'networkMode': 'PUBLIC'
},
filesystemConfigurations=[{
'sessionStorage': {
'mountPath': '/mnt/workspace'
}
}]
)Note: AgentCore uses two Boto3 service clients. The control plane client (bedrock-agentcore-control) handles runtime lifecycle operations like CreateAgentRuntime, GetAgentRuntime, and DeleteAgentRuntime. The data plane client (bedrock-agentcore) handles session operations like InvokeAgentRuntime and InvokeAgentRuntimeCommand. The mount path must start with /mnt followed by a folder name (for example, /mnt/workspace or /mnt/data). After configured, any file that your agent writes to this path is automatically persisted to managed storage.
The stop/resume experience
You invoke your agent and ask it to set up a project:
aws bedrock-agentcore invoke-agent-runtime \
--agent-runtime-arn "arn:...:agent-runtime/coding-agent" \
--runtime-session-id "session-001" \
--payload '{"prompt": "Set up the project and install dependencies in /mnt/workspace"}'The agent downloads the code, installs the packages and generates the configuration in the microVM that’s dedicated to that session. Then, you stop the session or the idle timeout kicks in, and the microVM terminates.
You come back and invoke with the same runtime-session-id:
aws bedrock-agentcore invoke-agent-runtime \
--agent-runtime-arn "arn:...:agent-runtime/coding-agent" \
--runtime-session-id "session-001" \
--payload '{"prompt": "Run the tests and fix any failures"}'A new compute environment (microVM) spins up and mounts the same storage. The agent sees /mnt/workspace exactly as it left it, including source files, node_modules, build artifacts and .git history. The agent picks up mid-thought, without the need to re-install and re-generate.
From the agent’s perspective, nothing special is happening. It reads and writes files to a directory like it normally would. Your agent code doesn’t need to change—no special APIs, no save/restore logic, no serialization. Write a file to /mnt/workspace, stop the session, resume it, and the file is there.
The session’s compute environment (microVM) from yesterday is gone, but the filesystem survived.
Controlling how long the data lives
By default, session storage data is retained for 14 days of idle time. If the session isn’t resumed within this window, the data is cleaned up. When the agent endpoint is updated to a different version and the same runtime-session-id is invoked, the session data is refreshed. This gives the mounted directory a clean context for the new version.
A multi-day development workflow
Let’s walk through what this looks like in practice. Day 1 – You invoke your coding agent and ask it to download a code base, inspect the files, and set up the development environment:
aws bedrock-agentcore invoke-agent-runtime \
--agent-runtime-arn "arn:...:agent-runtime/coding-agent" \
--runtime-session-id "fefc1779-e5e7-49cf-a2c4-abaf478680c4" \
--payload '{"prompt": "Download the code from s3://amzn-s3-demo-bucket/fastapi-demo-main.zip and list all files"}'The agent downloads the repository to /mnt/workspace, extracts it, and reports back:
Files in the fastapi-demo-main project:
- Dockerfile
- README.md
- main.py
- requirements.txtYou close your laptop and go home. Day 2 – You invoke with the same session ID:
aws bedrock-agentcore invoke-agent-runtime \
--agent-runtime-arn "arn:...:agent-runtime/coding-agent" \
--runtime-session-id "fefc1779-e5e7-49cf-a2c4-abaf478680c4" \
--payload '{"prompt": "Add a new function called hello_world to main.py"}'The agent sees the project exactly as it left it. It modifies main.py directly. No re-downloading, no re-extracting. When you ask the agent to list the files, everything is there, including the modified main.py with the new hello_world function. The compute environment (microVM) from yesterday has already been terminated, but the work persists.
That addresses the first challenge, but now your agent has written new code and you need to verify that it works. This is where the second capability comes in.
Execute shell command: deterministic operations, directly in the agent’s environment
The second challenge, running deterministic operations without routing them through the LLM, is addressed by InvokeAgentRuntimeCommand. You can execute shell commands directly inside a running AgentCore Runtime session and stream the output back over HTTP/2.
The key insight is that agents and shell commands are good at different things:
Use execute command
Use the agent
The operation has a known command (npm test, git push)
The operation requires reasoning (“analyze this code and fix the bug”)
You want deterministic execution—same command, same result
You want the LLM to decide what to do
You need streaming output from a long-running process
You need the agent to use tools in a loop
The operation is a validation gate in your workflow
The operation is the creative or analytical work
You’re bootstrapping the environment before the agent starts
You’re asking the agent to work on a task
When your agent finishes writing code and you need to run tests, you shouldn’t need the LLM for that. npm test is npm test. The command is known, the behavior should be deterministic, and you want the raw output, not the LLM’s interpretation of it.
Running a command
Execute a command using the AWS SDK for Python (Boto3):
import boto3
import sys
client = boto3.client('bedrock-agentcore', region_name='us-west-2')
response = client.invoke_agent_runtime_command(
agentRuntimeArn='arn:aws:bedrock-agentcore:us-west-2:111122223333:runtime/my-agent',
runtimeSessionId='session-id-at-least-33-characters-long',
body={
'command': '/bin/bash -c "npm test"',
'timeout': 60
}
)
for event in response['stream']:
if 'chunk' in event:
chunk = event['chunk']
if 'contentStart' in chunk:
print("Command execution started")
if 'contentDelta' in chunk:
delta = chunk['contentDelta']
if delta.get('stdout'):
print(delta['stdout'], end='')
if delta.get('stderr'):
print(delta['stderr'], end='', file=sys.stderr)
if 'contentStop' in chunk:
stop = chunk['contentStop']
print(f"\nExit code: {stop.get('exitCode')}, Status: {stop.get('status')}")The response streams three event types in real time:
Event
When
Contains
contentStart
First chunk
Confirms the command started
contentDelta
During execution
stdout and/or stderr output
contentStop
Last chunk
exitCode and status (COMPLETED or TIMED_OUT)
As the output is streamed as it’s produced, you can detect a failure in the first few seconds and react immediately, rather than waiting for the full run.
Container, same filesystem
This is the critical detail: commands run in the same container, filesystem, and environment as your agent, not a sidecar, or a separate process talking over a socket. A file that the agent wrote at /mnt/workspace/fix.py is immediately visible to a command running cat /mnt/workspace/fix.py. There’s no synchronization step, no file transfer, and no shared volume to configure.
The AgentCore Runtime microVM doesn’t include developer tools by default. This also means that any tools that your commands depend on, git, npm, or language runtimes, must be added in your container image or installed dynamically at runtime.
Design choices that shape how you use it
- One-shot execution. Each command spawns a new bash process, runs to completion (or time out), and returns. No persistent shell session between commands. This matches how agent frameworks use command execution, craft a command, run it, read the output, and decide what to do next.
- Non-blocking. Command execution doesn’t block agent invocations. You can invoke the agent and run commands concurrently on the same session.
- Stateless between commands. Each command starts fresh, there’s no shell history and environment variables from previous commands don’t carry over. If you need state, encode it in the command: cd /workspace && export NODE_ENV=test && npm test.
What people are building with it
- Test automation — After the agent writes code, run npm test or pytest as a command. Stream the output and feed specific failures back to the agent for iteration.
- Git workflows — Branching, committing, and pushing are deterministic. Run them as commands, keeping version control logic out of the LLM.
- Environment bootstrapping — Clone repos, install packages, set up build tooling before the agent starts. This will be faster and more reliable as direct commands.
- Build pipelines — Anything with a known command that should run exactly as specified, for example: cargo build --release, mvn package, go build.
- Validation gates — Run linters, type checkers, security scanners as a gate after the agent writes code, but before committing.
- Debugging — Inspect the runtime environment: check installed packages, disk usage, and running processes. These will be useful for understanding agent failures.
Better together: the filesystem is the shared context
Managed session storage (in public preview) addresses the ephemeral filesystem challenge. Execute command addresses the deterministic operations challenge. Each is valuable on its own, but they’re more powerful when combined because they share the same filesystem that ties the entire workflow together.
When your agent runtime has managed session storage configured at /mnt/workspace, everything operates on the same persistent directory:
- InvokeAgentRuntime writes code, generates artifacts, and manages files in /mnt/workspace.
- InvokeAgentRuntimeCommand runs tests, git operations, and builds reading from and writing to the same /mnt/workspace.
- Stop the session. Compute (microVM) spins down. /mnt/workspace is persisted.
- Resume the next day. New compute mounts the same storage. Both the agent and execute command see the same files.
The filesystem becomes the shared context that connects agent reasoning, deterministic operations, and time. Here’s what that looks like in code:
import boto3
import json
client = boto3.client('bedrock-agentcore', region_name='us-west-2')
AGENT_ARN = 'arn:aws:bedrock-agentcore:us-west-2:111122223333:runtime/my-coding-agent'
SESSION_ID = 'fefc1779-e5e7-49cf-a2c4-abaf478680c4'
def run_command(command, timeout=60):
"""Execute a shell command and return the exit code."""
response = client.invoke_agent_runtime_command(
agentRuntimeArn=AGENT_ARN,
runtimeSessionId=SESSION_ID,
contentType='application/json',
accept='application/vnd.amazon.eventstream',
body={'command': command, 'timeout': timeout}
)
for event in response.get('stream', []):
if 'chunk' in event and 'contentStop' in event['chunk'
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み