# CodeInterpreterToolkit

> **Class** in `langchain_aws`

📖 [View in docs](https://reference.langchain.com/python/langchain-aws/tools/code_interpreter_toolkit/CodeInterpreterToolkit)

Toolkit for working with AWS code interpreter environment.

This toolkit provides a set of tools for working with a remote code interpreter environment:

* execute_code - Run code in various languages (primarily Python)
* execute_command - Run shell commands
* read_files - Read content of files in the environment
* list_files - List files in directories
* delete_files - Remove files from the environment
* write_files - Create or update files
* start_command_execution - Start long-running commands asynchronously
* get_task - Check status of async tasks
* stop_task - Stop running tasks
* upload_file - Upload files with semantic descriptions
* install_packages - Install Python packages

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.

## Signature

```python
CodeInterpreterToolkit(
    self,
    region: str = 'us-west-2',
    *,
    code_interpreter_identifier: Optional[str] = None,
)
```

## Description

**Example:**

```python
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())
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `region` | `str` | No | AWS region for the code interpreter (default: `'us-west-2'`) |
| `code_interpreter_identifier` | `Optional[str]` | No | 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. (default: `None`) |

## Constructors

```python
__init__(
    self,
    region: str = 'us-west-2',
    *,
    code_interpreter_identifier: Optional[str] = None,
)
```

| Name | Type |
|------|------|
| `region` | `str` |
| `code_interpreter_identifier` | `Optional[str]` |


## Properties

- `region`
- `tools`

## Methods

- [`get_tools()`](https://reference.langchain.com/python/langchain-aws/tools/code_interpreter_toolkit/CodeInterpreterToolkit/get_tools)
- [`get_tools_by_name()`](https://reference.langchain.com/python/langchain-aws/tools/code_interpreter_toolkit/CodeInterpreterToolkit/get_tools_by_name)
- [`cleanup()`](https://reference.langchain.com/python/langchain-aws/tools/code_interpreter_toolkit/CodeInterpreterToolkit/cleanup)

---

[View source on GitHub](https://github.com/langchain-ai/langchain-aws/blob/285069d4f44907e10aaf7743888689ea39c98fe3/libs/aws/langchain_aws/tools/code_interpreter_toolkit.py#L108)