Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Code Interpreter で、AIに安全に コードを書かせる。
Search
yoko / Naoki Yokomachi
April 17, 2026
Technology
8.9k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Code Interpreter で、AIに安全に コードを書かせる。
yoko / Naoki Yokomachi
April 17, 2026
More Decks by yoko / Naoki Yokomachi
See All by yoko / Naoki Yokomachi
Inside the collaboration paradox -AI駆動開発とアジャイル開発と60%と20%とハーネスと私-
yokomachi
1
130
Building a Personal AI Agent with Strands Agents × Amazon Bedrock AgentCore
yokomachi
1
41
Strands Agents × Amazon Bedrock AgentCoreで パーソナルAIエージェントを作ろう
yokomachi
3
370
身体を持ったパーソナルAIエージェントの 可能性を探る開発
yokomachi
1
190
AITuberKit+Bedrock AgentCoreで作る 3Dキャラクターエージェント
yokomachi
2
3.3k
ご飯食べながらエージェントが開発できる。そう、Agentic Engineeringならね。
yokomachi
1
430
"人"が頑張るAI駆動開発
yokomachi
1
920
AIハッカソンで1人雰囲気SDDをした学びの共有
yokomachi
1
60
『FailNet~やらかし共有SNS~』エレベーターピッチ
yokomachi
1
640
Other Decks in Technology
See All in Technology
論語・武士道・産業革命から見る かわるもの、かわらないもの
ichimichi
8
1.9k
AIツールを導入しても生産性はあがらない? カオナビが直面した 3つの壁と乗り越え方。/ Overcoming 3 Barriers to AI-Driven Productivity at kaonavi
kaonavi
0
480
MCPをつなげて作る組織横断のAIエージェント基盤
tsubakimoto_s
0
430
QAと開発の両側から進める AI活用 -QAプロセスAI支援ツールキットと Inner Loop / Outer Loopの取り組み-
legalontechnologies
PRO
2
380
Atlassian Cloudサポート業務でのAIエージェント活用事例
smt7174
0
120
WEBフロントエンド研修【MIXI 26新卒技術研修】
mixi_engineers
PRO
2
820
現場をAIで動かす「フィジカル AI」の組み込み設計の考え方【SORACOM Discovery 2026】
soracom
PRO
0
150
AI Agent を本番環境へ―― Microsoft Foundry × Azure Serverless で作る Enterprise-Ready な基盤
shibayan
PRO
1
910
歴史から理解するクラウドインフラのしくみ
kizawa2020
0
190
DevOps Agentで運用判断をチーム資産にする~Agent InstructionsとAgent Skillを継続的に育てる~
fujioka6789
0
180
自己解決や回答速度を上げる、サポート業務へのAIの組み込み方【SORACOM Discovery 2026】
soracom
PRO
0
120
データ活用研修 データマネジメント【MIXI 26新卒技術研修】
mixi_engineers
PRO
4
810
Featured
See All Featured
AI: The stuff that nobody shows you
jnunemaker
PRO
9
850
Designing for Performance
lara
611
70k
Odyssey Design
rkendrick25
PRO
2
740
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
190
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
Optimising Largest Contentful Paint
csswizardry
37
3.9k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Designing for Timeless Needs
cassininazir
1
420
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4.2k
Documentation Writing (for coders)
carmenintech
77
5.4k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.7k
Designing Powerful Visuals for Engaging Learning
tmiket
1
470
Transcript
LT · 5 min · 2026.04 AMAZON BEDROCK AGENTCORE Code
Interpreter で、 AIに安全に コードを書かせる。 yoko / Naoki Yokomachi Strands Agents × AgentCore で作る可視化ワークフロー zenn.dev/yokomachi
ABOUT ME 個人開発で AIエージェントを作っています。 TONaRi パーソナルAIエージェント。 基本構成は Strands Agents +
Amazon Bedrock AgentCore。 テックニュースの投稿などもXで発信中。 Blog / Zenn AWS・AIエージェントまわりを書いています。 今日は最近書いた記事を元に、 Code Interpreter の実装例を紹 介します。 zenn.dev/yokomachi 01 — About yoko / Naoki Yokomachi
TODAY 今日の5分で話すこと 01 AgentCore Code Interpreter とは AIに安全にコードを書かせる AWS のビルディングブロック
02 Strands Agents の Skills と組み合わせる 手順を SKILL.md に外出しして、 動的にロードする仕組み 03 AWSコスト可視化ワークフロー Cost Explorer → Code Interpreter → matplotlib → S3 02 — Agenda 5 min talk
01 · THE BUILDING BLOCK AgentCore Code Interpreter AgentCore Runtime
上のエージェントが、 サンドボックス環境で安全にコードを実行できるビルディングブロック。 MENTAL MODEL AIが書いたコードを、 そのまま自分のマシンで動かすのは怖い。 その "怖い部分" を AWS に丸ごと預けられる、 と 考えると分かりやすい。 SANDBOX — ap-northeast-1 # エージェントが書いた Python import pandas as pd import matplotlib.pyplot as plt ... # ↑ を隔離環境で実行して結果だけ返す → stdout / stderr / 生成ファイル がエージェントに返る 03 — Code Interpreter docs: AWS ML Blog
01 · FEATURES 特徴は3つ 01 サンドボックス環境で 安全に実行 エージェントが生成した Python を、
隔離環境 でそのまま走らせる。 ホスト環境への影響ゼ ロ。 isolation 02 プリインストール済み ライブラリ pandas / numpy / matplotlib などの定 番が最初から使える。 セットアップ不要。 batteries included 03 ユーザー定義の ネットワーク デフォルトは制限付き。 必要なら、 パブリックア クセスや VPC 接続のある環境も定義できる。 custom env 04 — Features sandbox / libs / network
02 · STRANDS AGENTS Skills — 手順を外に出す Anthropic 提案の仕組みが、 Strands
Agents でも使えるようになった (2026.03)。 手順は SKILL.md に書き、 メタデータだけシステムプロンプトに注入。 必要になったタイミングで、 エージェントが動的にロードして実行する。 → トークン節約 & コンテキスト汚染の抑制 skills/aws-cost/SKILL.md --- name: aws-cost description: Analyze and visualize AWS cost data with get_aws_cost & execute_python for matplotlib charts allowed-tools: get_aws_cost execute_python --- # AWS Cost Analysis Skill Two-step process: fetch data, then visualize. ## Critical Rules - NEVER call plt.savefig() - NEVER call plt.close() - Use English for ALL chart text 05 — Skills Anthropic → Strands Agents
03 · WORKFLOW 作ったもの — AWSコスト可視化 USER 「今月のAWSコスト教えて」 ↓ AGENT
Strands Agents · Main Agent ① skills — SKILL.md をロード ② get_aws_cost — Cost Explorer API ③ execute_python 3-1 Code Interpreter で matplotlib → PNG 3-2 S3 アップロード → 署名付き URL ↓ UI チャットに画像をインライン表示 06 — Workflow user · agent · tools · UI
03 · IMPLEMENTATION キモ: execute_python エージェントが書いたコードの前後にキャプチャ用コードを自動注入して、 生成された matplotlib 画像を確実に回収する。 @tool
def execute_python(code: str) -> str: img_code = f""" import matplotlib matplotlib.use('Agg') {code} # ← エージェントが生成したコード import matplotlib.pyplot as plt, base64, io, json as _json _imgs = [] for _i in plt.get_fignums(): # ← 開いている figure を全部拾う _b = io.BytesIO() plt.figure(_i).savefig(_b, format='png', bbox_inches='tight', dpi=100) _imgs.append({{'i': _i, 'd': base64.b64encode(_b.getvalue()).decode()}}) print('_IMG_' + _json.dumps(_imgs) + '_END_') """ with code_session(CODE_INTERPRETER_REGION) as client: resp = client.invoke("executeCode", {"code": img_code, ...}) # stdout の _IMG_..._END_ から画像を抽出 → S3 へ 07 — execute_python auto-inject capture
03 · DEMO 動かすとこんな感じ USER 先月のAWSコスト、 サービス別で棒グラフにして。 AGENT › skills:
aws-cost をロード › get_aws_cost(months=1, group_by_service=True) › execute_python(...matplotlib...) 先月は合計 $142.80。 内訳はこちらです → aws_cost_2026_03.png via S3 presigned URL $60 $30 $0 Bedrock EC2 S3 Lambda CloudW. Other AWS Cost by Service — 2026/03 08 — Demo S3 URL → inline image
WRAP-UP 持ち帰ってほしい3つ CODE INTERPRETER AIに安全に Python を実行させる AWS のサンドボックス。 matplotlib
も最初から入っているので、 データ分析との相 性が良い。 SKILLS 手順を Markdown で外出し、 必要な 時だけロード。 プロンプト肥大化・コンテキスト汚染を避けながら複雑な手 順を扱える。 COMBINED データ取得 → 可視化まで、 一気通貫 でエージェントに任せられる。 今回はデフォルト環境。 ユーザー定義環境なら、 さらに自由 度が上がる。 Blog: Strands Agents Skill と AgentCore Code Interpreter で AWS コストの可視化ワークフローを作る zenn.dev/yokomachi 09 — Takeaway safe · scoped · end-to-end
END · THANK YOU ありがとう。 yoko / Naoki Yokomachi ·
zenn.dev/yokomachi · x.com/tonari_with