> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-5e9cc07a-preview-opensw-1781706951-9d0138e.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# AgentCoreSandbox integration

> Integrate with the AgentCoreSandbox sandbox backend using LangChain Python.

[Amazon Bedrock AgentCore Code Interpreter](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/code-interpreter-tool.html) is a sandbox backend for [Deep Agents](https://github.com/langchain-ai/deepagents), enabling secure code execution in isolated MicroVM environments.

## Installation

<CodeGroup>
  ```bash pip theme={null}
  pip install langchain-agentcore-codeinterpreter
  ```

  ```bash uv theme={null}
  uv add langchain-agentcore-codeinterpreter
  ```
</CodeGroup>

## Create a sandbox backend

See the [sandboxes guide](/oss/python/deepagents/sandboxes) for usage, file operations, and lifecycle details.

```python theme={null}
from bedrock_agentcore.tools.code_interpreter_client import CodeInterpreter
from langchain_agentcore_codeinterpreter import AgentCoreSandbox

interpreter = CodeInterpreter(region="us-west-2")
interpreter.start()

backend = AgentCoreSandbox(interpreter=interpreter)
result = backend.execute("echo hello")
print(result.output)

interpreter.stop()
```

## Use with Deep Agents

```python theme={null}
from bedrock_agentcore.tools.code_interpreter_client import CodeInterpreter
from langchain_agentcore_codeinterpreter import AgentCoreSandbox
from langchain_anthropic import ChatAnthropic

from deepagents import create_deep_agent

interpreter = CodeInterpreter(region="us-west-2")
interpreter.start()

backend = AgentCoreSandbox(interpreter=interpreter)

agent = create_deep_agent(
    model=ChatAnthropic(model="claude-sonnet-4-20250514"),
    system_prompt="You are a coding assistant with sandbox access.",
    backend=backend,
)

try:
    result = agent.invoke(
        {"messages": [{"role": "user", "content": "Write and run a Python script"}]}
    )
finally:
    interpreter.stop()
```

## Cleanup

Always stop the interpreter when you are done to release resources.

See also: [Sandboxes](/oss/python/deepagents/sandboxes).

***

<div className="source-links">
  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>

  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/sandboxes/aws.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
