AMAZON BEDROCK / SERVICE DETAIL S06 (TOOLS)
AGENTCORE CODE INTERPRETER
CHAPTER 15 / 36
IN ONE LINE a safe computer for the agent to run code
REV 2026.07
AI models are weak at exact math and data work, and you should never let them run code on your own machines. Code Interpreter gives the agent a safe, throwaway computer in the cloud to run code, so it can calculate, analyze data, and check its own answers, with no risk to your systems.
New to these words? Read chapter 02 "Key terms" (sandbox, session, microVM).
[ 1 ] WHAT IT IS
Code Interpreter is a secure, fully managed sandbox (a locked-down computer) where the agent writes and runs real code. It is built in to AgentCore, so there is nothing for you to host. The agent uses it for precise work: math, data analysis, charts, file processing, and double-checking an answer by actually running it.
THE AGENT GETS
A real computer to run Python, JavaScript, or TypeScript, with common libraries ready.
YOU ARE PROTECTED
The code runs isolated in the cloud, never on your systems, and the session is thrown away afterward.
[ 2 ] HOW A RUN WORKS
STEP 01
CREATE
Use the built-in interpreter (aws.codeinterpreter.v1) or make your own.
==>
STEP 02
START SESSION
Open a session. It stays alive for a set time (15 minutes by default).
==>
STEP 03
EXECUTE
Send code. It runs, and keeps its state (variables, files) for the next run in the same session.
==>
STEP 04
RESULT
The output streams back to your code.
==>
STEP 05
STOP
Close the session to free resources. You pay only while it runs.
[ 3 ] THREE NETWORK MODES, PICK THE SAFE ONE (THE THIRD, VPC, CONNECTS TO YOUR PRIVATE NETWORK)
SANDBOX most restricted
The code cannot reach the public internet; only limited access to AWS services (Amazon S3). Safest.
Use it for pure computation and data you provide.
The right default for almost everything.
PUBLIC internet allowed
The code can reach the internet.
Use only when a task truly needs it (download a dataset, call a public API).
It widens the risk of data leaving, so turn it off when not needed.
[ 4 ] WHAT YOU CAN DO IN IT
LANGUAGES
Python, JavaScript, TypeScript, with common libraries ready.
KEEP STATE
Variables and files persist across runs in the same session.
FILES
Up to 100 MB inline, or 5 GB through Amazon S3.
SHELL + AWS CLI
Run shell commands and the AWS CLI inside the sandbox.
A custom interpreter can be given an execution role that decides which AWS resources it may touch, and you can watch its activity in CloudWatch. Reminder: keep it in Sandbox mode unless a task truly needs the internet.