◈ AWS AGENTCORE BLUEPRINTS
PART III · TOOLS AND OPERATIONS · CHAPTER 16 / 36
TOCCONSULTING.FR
AMAZON BEDROCK / SERVICE DETAIL S06 CODE INTERPRETER

AGENTCORE CODE INTERPRETERPRACTICAL

CHAPTER 16 / 36
TOPIC open a safe computer, run code, close it
REV 2026.07
IN PLAIN WORDS

You will open a safe cloud computer, run a line of Python in it, read the result, and close it. Two ways: the simple SDK client, or raw boto3 for more control. Terms: session = one open run of the sandbox (default 15 minutes); aws.codeinterpreter.v1 = the built-in interpreter; executeCode = the action that runs your code; stream = the result arrives piece by piece.

[ 1 ] INSTALL AND CHECK CREDENTIALS
$ pip install bedrock-agentcore boto3 $ aws sts get-caller-identity # confirm your AWS login works
[x] Python 3.10+, AWS credentials
[x] An IAM execution role with Code Interpreter permissions
[x] Model access: Anthropic Claude Sonnet 4.0 (per the docs quickstart, if using a model)
[ 2 ] RUN CODE, THE SIMPLE WAY (SDK client)
from bedrock_agentcore.tools.code_interpreter_client import CodeInterpreter
import json

code_client = CodeInterpreter('<Region>')        # e.g. 'us-west-2'
code_client.start()                              # open a session
try:
    response = code_client.invoke("executeCode", {
        "language": "python",
        "code": 'print("Hello World!!!")'
    })
    for event in response["stream"]:
        print(json.dumps(event["result"], indent=2))
finally:
    code_client.stop()                           # always clean up
[ 3 ] RUN CODE, WITH FULL CONTROL (boto3)
import boto3
client = boto3.client("bedrock-agentcore", region_name="<Region>")

s = client.start_code_interpreter_session(
    codeInterpreterIdentifier="aws.codeinterpreter.v1",   # the built-in interpreter
    name="my-code-session",
    sessionTimeoutSeconds=900)                            # 900s = 15 minutes
session_id = s["sessionId"]
try:
    r = client.invoke_code_interpreter(
        codeInterpreterIdentifier="aws.codeinterpreter.v1",
        sessionId=session_id,
        name="executeCode",
        arguments={"language": "python", "code": 'print("Hello World!!!")'})
    for event in r["stream"]:
        if "result" in event:
            for c in event["result"].get("content", []):
                if c["type"] == "text": print(c["text"])
finally:
    client.stop_code_interpreter_session(
        codeInterpreterIdentifier="aws.codeinterpreter.v1", sessionId=session_id)
Permissions: your IAM identity needs the bedrock-agentcore Create / Start / Invoke / Stop / Delete / List / Get CodeInterpreter actions, and the execution role must trust bedrock-agentcore.amazonaws.com. Keep the interpreter in Sandbox (no public internet; limited access to AWS services like S3) unless a task truly needs Public.
SRC: AWS AgentCore Developer Guide (code interpreter get started, using directly, session management)
DRAWN 2026.06, REV 2026.07.26
◄ PREVIOUS · CH 15
AgentCore Code Interpreter, Plain Language
NEXT · CH 17 ►
AgentCore Browser, Plain Language
AWS AGENTCORE BLUEPRINTS · CONTENTS
Back to tocconsulting.fr Cover & Table of Contents
PART I · FOUNDATIONS
01AgentCore Overview, Plain LanguageCONCEPT02AgentCore, Key Terms in Plain LanguageCONCEPT03AgentCore, Common Mistakes ExplainedCONCEPT04Inside an AgentCore Agent, BlueprintCONCEPT05Harness, Practical 1, Strands PathPRACTICAL06Harness, Practical 2, Managed HarnessPRACTICAL
PART II · CORE SERVICES
07AgentCore Runtime, Plain LanguageCONCEPT08AgentCore Runtime, PracticalPRACTICAL09AgentCore Memory, Plain LanguageCONCEPT10AgentCore Memory, PracticalPRACTICAL11AgentCore Gateway, Plain LanguageCONCEPT12AgentCore Gateway, PracticalPRACTICAL13AgentCore Identity, Plain LanguageCONCEPT14AgentCore Identity, PracticalPRACTICAL
PART III · TOOLS AND OPERATIONS
15AgentCore Code Interpreter, Plain LanguageCONCEPT16AgentCore Code Interpreter, PracticalPRACTICAL17AgentCore Browser, Plain LanguageCONCEPT18AgentCore Browser, PracticalPRACTICAL19AgentCore Observability, Plain LanguageCONCEPT20AgentCore Observability, PracticalPRACTICAL21AgentCore Evaluations, Plain LanguageCONCEPT22AgentCore Evaluations, PracticalPRACTICAL
PART IV · GOVERNANCE AND TRANSACTIONS
23AgentCore Policy, Plain LanguageCONCEPT24AgentCore Policy, PracticalPRACTICAL25AgentCore Registry, Plain LanguageCONCEPT26AgentCore Registry, PracticalPRACTICAL27AgentCore Payments, Plain LanguageCONCEPT28AgentCore Payments, PracticalPRACTICAL
PART V · MULTI-AGENT AND ARCHITECTURE
29A2A and Multi-Agent, Plain LanguageCONCEPT30A2A and Multi-Agent, PracticalPRACTICAL31Architecture Patterns, Plain LanguageCONCEPT32Multi-Tenant Agents, Plain LanguageCONCEPT33Agent Security and Threat Model, Plain LanguageCONCEPT34Governance at Org Scale, Plain LanguageCONCEPT35Governance at Org Scale, PracticalPRACTICAL36Multi-Region and Distribution, Plain LanguageCONCEPT