v vanemmerik.ai / aws-ai
Tip of the Day 2026 · 06 · 01 ≈ 9 min read Bedrock AgentCore · Code Interpreter

AgentCore Code Interpreter, the sandbox.

AgentCore Code Interpreter is the managed sandbox where an agent can write code, run it, and inspect the result without you having to host a Jupyter kernel, harden a container, or trust the model not to delete your S3 bucket. Yesterday's Observability tip covered the dashboard you didn't have to build. Today's question is the one underneath it: where does the code actually run?

$ pip install bedrock-agentcore boto3  — start, invoke, stop

01Why Code Interpreter exists

Most useful agentic work eventually wants to run a small program. Parse a CSV, plot a chart, validate a JSON schema, solve an integer-program, re-encode a video. The model can write the code; the question is where that code executes.

The two failure modes both end the same way:

AgentCore Code Interpreter is AWS's managed answer. From Execute code and analyze data using Amazon Bedrock AgentCore Code Interpreter: "The AgentCore Code Interpreter runs in a containerized environment within Amazon Bedrock AgentCore, ensuring that code execution remains isolated and secure." It supports Python, JavaScript, and TypeScript, ships with hundreds of pre-installed libraries, exposes a tight session API, and is logged to CloudTrail. You don't manage the container.

The shift

You stop hosting an interpreter. AgentCore gives you a per-session sandbox with 2 vCPU / 8 GB / 10 GB of disk and a clear contract for getting code in and results out.

02Two modes — managed and custom

There are two paths into the Code Interpreter, and the choice is purely about how much control you need over execution role and network egress.

ModeHow you reference itWhen to pick it
Managed (system) codeInterpreterIdentifier="aws.codeinterpreter.v1" Default. No setup, no IAM role to provision, no network policy to wire. Use when the agent only needs to crunch numbers or build charts.
Custom CreateCodeInterpreter → returns a codeInterpreterId you pass to start_code_interpreter_session Use when you need an execution role that can read/write a specific S3 bucket, or when you want explicit SANDBOX vs PUBLIC network mode.

Custom Code Interpreters are created on the bedrock-agentcore-control endpoint; sessions and invocations land on the bedrock-agentcore data-plane endpoint. The two-client pattern is the same one Memory and Gateway use.

~/agent — create_code_interpreter.py
# bedrock-agentcore-control = control plane (create/delete interpreters) cp = boto3.client("bedrock-agentcore-control", region_name="us-east-1") resp = cp.create_code_interpreter(   name="my-data-sandbox",   description="S3-reading sandbox for the analyst agent",   executionRoleArn="arn:aws:iam::111122223333:role/CodeInterpreterExecRole",   networkConfiguration={"networkMode": "SANDBOX"}, ) code_interpreter_id = resp["codeInterpreterId"]

Custom interpreter — control plane creates, data plane invokes

The execution role's trust policy must let bedrock-agentcore.amazonaws.com assume it; the calling identity needs the bedrock-agentcore:CreateCodeInterpreter / InvokeCodeInterpreter / StartCodeInterpreterSession actions scoped to arn:aws:bedrock-agentcore:<region>:<account>:code-interpreter/*.

03The session model

Code Interpreter is session-based. You create the interpreter (or use the managed one) once; every invocation runs inside a session you explicitly start and stop. Each session keeps its own state — Python globals, files on disk, environment variables — so successive executeCode calls within the same session can build on each other.

The state you care about lives in three fields on start_code_interpreter_session:

When the session is stopped — explicitly, or by hitting the timeout — the sandbox is destroyed. Anything not exported to S3 or returned in a response is gone. The high-level SDK (bedrock_agentcore.tools.code_interpreter_client.CodeInterpreter) wraps the lifecycle in a code_session context manager, which is the path the docs steer you toward.

04The tool surface — one verb, nine names

Every Code Interpreter call goes through one boto3 method, invoke_code_interpreter, with a name field that selects the tool. The API reference examples list nine:

Tool nameArgumentsWhat it does
executeCodelanguage, codeRun a Python/JS/TS snippet. Returns a stream of result events.
executeCommandcommandRun a synchronous shell command (ls -l, pip install …). Bounded by the 15-minute sync ceiling.
startCommandExecutioncommandFire-and-forget for long-running shell work. Returns a taskId.
getTasktaskIdPoll the status of a long-running task.
stopTasktaskIdCancel a long-running task.
writeFilescontent: [{path, text}, …]Drop files into the sandbox before executing code that reads them.
readFilespaths: […]Read sandbox files back into the calling process.
listFilesdirectoryPathWalk the sandbox's filesystem.
removeFilespaths: […]Clean up temporary files between steps.

Calls return a stream of events with a result field; the SDK helper flattens them, but with boto3 you iterate response["stream"] and pull event["result"]["content"] for text and image outputs.

05Batteries included

The sandbox image ships with hundreds of pre-installed libraries so the agent rarely has to pip install (and you rarely have to widen the network policy to let it). The pre-installed libraries doc is exhaustive; the headline shape:

If you do need to install something, pip install <pkg> works in PUBLIC network mode; in SANDBOX mode it fails — that's the trade.

06Network modes and S3

The single most-asked question after "does it run pandas" is "can it read my S3 bucket?". Two pieces decide that:

With that role in place, the agent can aws s3 cp files in and out of S3 directly inside the sandbox — which is the right pattern for anything over a few hundred megabytes. The inline file upload tool (writeFiles) caps at the 100 MB max payload size; objects in S3 can go up to 5 GB per file according to the Code Interpreter overview.

$ # Inside an executeCommand call, with an execution role attached: $ aws s3 cp s3://my-bucket/input/data.csv . $ python analyse.py $ aws s3 cp report.html s3://my-bucket/output/

07Limits worth knowing

From the AgentCore service quotas table for Code Interpreter:

Two gotchas that aren't in the quota table:

08Try it in five minutes

With AWS credentials and the right IAM permissions in place:

$ pip install bedrock-agentcore boto3   $ python - <<'PY' from bedrock_agentcore.tools.code_interpreter_client import CodeInterpreter import json   code_client = CodeInterpreter("us-east-1") code_client.start() try:     resp = code_client.invoke("executeCode", {         "language": "python",         "code": (             "import pandas as pd\\n"             "df = pd.DataFrame({'x': range(10)})\\n"             "df['y'] = df['x'] ** 2\\n"             "print(df.tail())\\n"         ),     })     for event in resp["stream"]:         print(json.dumps(event["result"], indent=2)) finally:     code_client.stop() PY

That's the whole loop: start, invoke, stop. The managed aws.codeinterpreter.v1 interpreter handles the rest. Add a writeFiles call before the executeCode to upload data, or swap to executeCommand and aws s3 cp to pull a file from S3 first.

Tomorrow we'll look at AgentCore Browser — the sibling built-in tool that lets the agent drive a real Chromium session the same way Code Interpreter lets it run a Python kernel.

Verified against the official AWS docs on 2026-06-01.
Sources: Execute code and analyze data using Amazon Bedrock AgentCore Code Interpreter, Get started with AgentCore Code Interpreter, Using AgentCore Code Interpreter directly, Creating an AgentCore Code Interpreter, Starting a session, Resource and session management, API reference examples, Pre-installed libraries, File operations, Terminal commands with an execution role (S3), Service quotas.
If the docs change, this tip is a snapshot of that day — check the sources for current behaviour.
Heads up — this tip is from 2026-06-01. AWS services move fast. Cross-check the AgentCore developer guide before relying on specifics, then come back for today's tip →
C

This page — research, writing, verification, and deployment — was built by Claude Cowork. No human touched the prose, the layout, or the upload pipeline. The tip was generated this morning, cross-checked against the official AWS docs by an independent verification pass, and published to Cloudflare R2 on a schedule.

A daily experiment by Monty van Emmerik · vanemmerik.ai · what is Claude Cowork?