Python REPL
Runs model-generated Python through the agent’s sandbox by calling sandbox.execute_code(code, "python3") (sandbox.executeCode(code, 'python3') in TypeScript). It returns output (stdout), error (stderr, including tracebacks), and exit_code. Each call runs in a fresh interpreter, so variables, imports, and definitions do not persist across calls. Files written to the sandbox filesystem do persist, so the model can checkpoint intermediate results to disk and load them in a later call.
Supported in: Node.js on Unix/Linux/macOS (TypeScript), Python.
import { Agent } from '@strands-agents/sdk'import { pythonRepl } from '@strands-agents/sdk/vended-tools/python-repl'
const agent = new Agent({ tools: [pythonRepl] })await agent.invoke( 'Use python_repl to compute the first 10 Fibonacci numbers and print them.')from strands import Agentfrom strands.vended_tools import python_repl
agent = Agent(tools=[python_repl])agent("Use python_repl to compute the first 10 Fibonacci numbers and print them.")Bound sandbox or custom interpreter:
import { Agent } from '@strands-agents/sdk'import { DockerSandbox } from '@strands-agents/sdk/sandbox/docker'import { makePythonRepl } from '@strands-agents/sdk/vended-tools/python-repl'
const pythonRepl = makePythonRepl(new DockerSandbox({ container: 'my-container' }), { language: 'python3.12',})const agent = new Agent({ tools: [pythonRepl] })from strands import Agentfrom strands.sandbox.docker import DockerSandboxfrom strands.vended_tools import make_python_repl
python_repl = make_python_repl( sandbox=DockerSandbox("my-container"), # bind at creation instead of reading agent.sandbox language="python3.12", # interpreter on the sandbox's PATH)agent = Agent(tools=[python_repl])