Toolkit for working with AWS code interpreter environment.
This toolkit provides a set of tools for working with a remote code interpreter environment:
The toolkit lazily initializes the code interpreter session on first use. It supports multiple threads by maintaining separate code interpreter sessions for each thread ID.
Example:
import asyncio
from langchain.agents import create_agent
from langchain_aws.tools import create_code_interpreter_toolkit
async def main():
# Create and setup the code interpreter toolkit (default interpreter)
toolkit, code_tools = await create_code_interpreter_toolkit(region="us-west-2")
# Or use a custom code interpreter (e.g. VPC-configured)
# toolkit, code_tools = await create_code_interpreter_toolkit(
# region="us-west-2",
# code_interpreter_identifier="my-interpreter-abc123",
# )
# Create a ReAct agent using the code interpreter tools
agent = create_agent(
"bedrock_converse:us.anthropic.claude-haiku-4-5-20251001-v1:0",
tools=code_tools
)
# Create runnable config with thread ID
config = {
"configurable": {
"thread_id": "session123"
}
}
# Invoke the agent with a specific task using thread ID
result = await agent.ainvoke(
"Create a simple Python function that calculates the factorial of a number.",
config=config
)
# Cleanup when done
await toolkit.cleanup()
return result
# Run the example
asyncio.run(main())AWS region for the code interpreter
Optional identifier for the code interpreter.
Use the default system interpreter (e.g. aws.codeinterpreter.v1)
when None. Set to a custom interpreter ID (from
create_code_interpreter) to use a custom interpreter, e.g. one
with VPC configuration.
Get the list of code interpreter tools
Get a dictionary of tools mapped by their names
Clean up resources