langchain-agentcore-codeinterpreter 0.0.5__tar.gz → 0.0.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (21) hide show
  1. {langchain_agentcore_codeinterpreter-0.0.5 → langchain_agentcore_codeinterpreter-0.0.6}/.gitignore +5 -0
  2. {langchain_agentcore_codeinterpreter-0.0.5 → langchain_agentcore_codeinterpreter-0.0.6}/PKG-INFO +46 -35
  3. {langchain_agentcore_codeinterpreter-0.0.5 → langchain_agentcore_codeinterpreter-0.0.6}/README.md +42 -31
  4. {langchain_agentcore_codeinterpreter-0.0.5 → langchain_agentcore_codeinterpreter-0.0.6}/langchain_agentcore_codeinterpreter/sandbox.py +227 -32
  5. {langchain_agentcore_codeinterpreter-0.0.5 → langchain_agentcore_codeinterpreter-0.0.6}/pyproject.toml +3 -3
  6. {langchain_agentcore_codeinterpreter-0.0.5 → langchain_agentcore_codeinterpreter-0.0.6}/tests/integration_tests/sandbox/test_sandbox.py +40 -0
  7. langchain_agentcore_codeinterpreter-0.0.6/tests/integration_tests/sandbox/test_standard.py +143 -0
  8. {langchain_agentcore_codeinterpreter-0.0.5 → langchain_agentcore_codeinterpreter-0.0.6}/tests/unit_tests/test_sandbox.py +402 -10
  9. langchain_agentcore_codeinterpreter-0.0.6/uv.lock +3016 -0
  10. langchain_agentcore_codeinterpreter-0.0.5/uv.lock +0 -2585
  11. {langchain_agentcore_codeinterpreter-0.0.5 → langchain_agentcore_codeinterpreter-0.0.6}/LICENSE +0 -0
  12. {langchain_agentcore_codeinterpreter-0.0.5 → langchain_agentcore_codeinterpreter-0.0.6}/Makefile +0 -0
  13. {langchain_agentcore_codeinterpreter-0.0.5 → langchain_agentcore_codeinterpreter-0.0.6}/langchain_agentcore_codeinterpreter/__init__.py +0 -0
  14. {langchain_agentcore_codeinterpreter-0.0.5 → langchain_agentcore_codeinterpreter-0.0.6}/scripts/check_imports.py +0 -0
  15. {langchain_agentcore_codeinterpreter-0.0.5 → langchain_agentcore_codeinterpreter-0.0.6}/tests/__init__.py +0 -0
  16. {langchain_agentcore_codeinterpreter-0.0.5 → langchain_agentcore_codeinterpreter-0.0.6}/tests/integration_tests/__init__.py +0 -0
  17. {langchain_agentcore_codeinterpreter-0.0.5 → langchain_agentcore_codeinterpreter-0.0.6}/tests/integration_tests/sandbox/__init__.py +0 -0
  18. {langchain_agentcore_codeinterpreter-0.0.5 → langchain_agentcore_codeinterpreter-0.0.6}/tests/integration_tests/test_compile.py +0 -0
  19. {langchain_agentcore_codeinterpreter-0.0.5 → langchain_agentcore_codeinterpreter-0.0.6}/tests/unit_tests/__init__.py +0 -0
  20. {langchain_agentcore_codeinterpreter-0.0.5 → langchain_agentcore_codeinterpreter-0.0.6}/tests/unit_tests/test_imports.py +0 -0
  21. {langchain_agentcore_codeinterpreter-0.0.5 → langchain_agentcore_codeinterpreter-0.0.6}/tests/unit_tests/test_stream_parsing.py +0 -0
@@ -117,6 +117,11 @@ celerybeat.pid
117
117
  # Environments
118
118
  .env
119
119
  .envrc
120
+ .env.*
121
+ *.pem
122
+ *.key
123
+ *.crt
124
+ credentials.json
120
125
  .venv*
121
126
  venv*
122
127
  env/
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: langchain-agentcore-codeinterpreter
3
- Version: 0.0.5
3
+ Version: 0.0.6
4
4
  Summary: Amazon Bedrock AgentCore Code Interpreter sandbox integration for Deep Agents
5
5
  Project-URL: Source Code, https://github.com/langchain-ai/langchain-aws/tree/main/libs/agentcore-codeinterpreter
6
6
  Project-URL: Repository, https://github.com/langchain-ai/langchain-aws
@@ -8,9 +8,9 @@ License-Expression: MIT
8
8
  License-File: LICENSE
9
9
  Keywords: agentcore,aws,bedrock,code-interpreter,deepagents,langchain,sandbox
10
10
  Requires-Python: <4.0,>=3.11
11
- Requires-Dist: bedrock-agentcore>=1.1.4
11
+ Requires-Dist: bedrock-agentcore>=1.1.5
12
12
  Requires-Dist: boto3>=1.42.42
13
- Requires-Dist: deepagents>=0.1.0
13
+ Requires-Dist: deepagents>=0.5.6
14
14
  Description-Content-Type: text/markdown
15
15
 
16
16
  # langchain-agentcore-codeinterpreter
@@ -21,7 +21,7 @@ Description-Content-Type: text/markdown
21
21
 
22
22
  Amazon Bedrock AgentCore Code Interpreter sandbox integration for [Deep Agents](https://github.com/langchain-ai/deepagents).
23
23
 
24
- This package provides `AgentCoreSandbox` — a [`SandboxBackendProtocol`](https://docs.langchain.com/oss/deepagents/sandboxes) implementation that wraps AgentCore's [Code Interpreter](https://docs.aws.amazon.com/bedrock/latest/userguide/agentcore-code-interpreter.html), a secure, isolated MicroVM environment for executing code. The caller manages the interpreter lifecycle (`start()` / `stop()`); the sandbox backend handles command execution and file operations.
24
+ This package provides `AgentCoreSandbox` — a [`SandboxBackendProtocol`](https://docs.langchain.com/oss/deepagents/sandboxes) implementation that wraps AgentCore's [Code Interpreter](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/code-interpreter-tool.html), a secure, isolated MicroVM environment for executing code. `AgentCoreSandbox.create()` starts a session and stops it when you close the sandbox or leave a `with` block.
25
25
 
26
26
  > **Note:** For the LangChain `BaseTool` integration (used with `create_react_agent` and LangGraph agents), see [`langchain-aws[tools]`](https://github.com/langchain-ai/langchain-aws). This package is specifically for the Deep Agents `BaseSandbox` protocol.
27
27
 
@@ -50,9 +50,9 @@ aws sso login --profile your-profile
50
50
 
51
51
  Any method supported by the [boto3 credential chain](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html) works, including EC2 instance profiles, ECS task roles, and environment variables.
52
52
 
53
- **2. IAM permissions** — your credentials must allow `bedrock-agentcore:InvokeCodeInterpreter` (or the equivalent action for your region). See the [AgentCore Code Interpreter docs](https://docs.aws.amazon.com/bedrock/latest/userguide/agentcore-code-interpreter.html) for the required IAM policy.
53
+ **2. IAM permissions** — your credentials must allow `bedrock-agentcore:InvokeCodeInterpreter` (or the equivalent action for your region). See the [AgentCore Code Interpreter docs](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/code-interpreter-tool.html) for the required IAM policy.
54
54
 
55
- **3. Region availability** — Code Interpreter is available in select AWS regions. `us-west-2` is a safe default. Pass the region to `CodeInterpreter(region=...)`.
55
+ **3. Region availability** — Code Interpreter is available in select AWS regions. `us-west-2` is a safe default. Pass the region to `AgentCoreSandbox.create(region=...)`.
56
56
 
57
57
  ## Quick Install
58
58
 
@@ -65,45 +65,52 @@ pip install langchain-agentcore-codeinterpreter
65
65
  ### Standalone
66
66
 
67
67
  ```python
68
- from bedrock_agentcore.tools.code_interpreter_client import CodeInterpreter
69
-
70
68
  from langchain_agentcore_codeinterpreter import AgentCoreSandbox
71
69
 
72
- interpreter = CodeInterpreter(region="us-west-2")
73
- interpreter.start()
70
+ with AgentCoreSandbox.create(region="us-west-2") as backend:
71
+ result = backend.execute("echo hello")
72
+ print(result.output, result.exit_code) # "hello" 0
73
+ ```
74
+
75
+ Sessions last 15 minutes by default. Pass `session_timeout_seconds` (up to 28,800, or 8 hours) for longer agent runs, and `identifier` to use a custom code interpreter with VPC networking or an execution role.
74
76
 
75
- backend = AgentCoreSandbox(interpreter=interpreter)
77
+ To configure the `CodeInterpreter` client yourself, pass a started one to the constructor instead. You then own its lifecycle:
76
78
 
77
- result = backend.execute("echo hello")
78
- print(result.output) # "hello"
79
+ ```python
80
+ from bedrock_agentcore.tools.code_interpreter_client import CodeInterpreter
79
81
 
80
- interpreter.stop()
82
+ interpreter = CodeInterpreter(
83
+ region="us-west-2", integration_source="langchain-deepagents"
84
+ )
85
+ interpreter.start()
86
+ try:
87
+ backend = AgentCoreSandbox(interpreter=interpreter)
88
+ ...
89
+ finally:
90
+ interpreter.stop()
81
91
  ```
82
92
 
83
93
  ### With Deep Agents
84
94
 
85
95
  ```python
86
- from bedrock_agentcore.tools.code_interpreter_client import CodeInterpreter
87
96
  from deepagents import create_deep_agent
88
97
 
89
98
  from langchain_agentcore_codeinterpreter import AgentCoreSandbox
90
99
  from langchain_aws import ChatBedrockConverse
91
100
 
92
- interpreter = CodeInterpreter(region="us-west-2")
93
- interpreter.start()
94
-
95
101
  model = ChatBedrockConverse(
96
- model="us.anthropic.claude-sonnet-4-6",
97
- region_name="us-west-2",
98
- )
99
- backend = AgentCoreSandbox(interpreter=interpreter)
100
- agent = create_deep_agent(
101
- model=model,
102
- backend=backend,
103
- system_prompt="You are a coding assistant with sandbox access.",
102
+ model="us.anthropic.claude-sonnet-4-6",
103
+ region_name="us-west-2",
104
104
  )
105
105
 
106
- try:
106
+ with AgentCoreSandbox.create(
107
+ region="us-west-2", session_timeout_seconds=3600
108
+ ) as backend:
109
+ agent = create_deep_agent(
110
+ model=model,
111
+ backend=backend,
112
+ system_prompt="You are a coding assistant with sandbox access.",
113
+ )
107
114
  result = agent.invoke(
108
115
  {
109
116
  "messages": [
@@ -112,18 +119,18 @@ try:
112
119
  }
113
120
  )
114
121
  print(result["messages"][-1].content)
115
- finally:
116
- interpreter.stop()
117
122
  ```
118
123
 
119
124
  ### File operations
120
125
 
121
126
  ```python
122
127
  # Upload files
123
- backend.upload_files([
124
- ("data.csv", b"name,value\nalice,42\nbob,17"),
125
- ("analyze.py", b"import csv\nprint('ready')"),
126
- ])
128
+ backend.upload_files(
129
+ [
130
+ ("data.csv", b"name,value\nalice,42\nbob,17"),
131
+ ("analyze.py", b"import csv\nprint('ready')"),
132
+ ]
133
+ )
127
134
 
128
135
  # Download files
129
136
  results = backend.download_files(["data.csv"])
@@ -136,7 +143,11 @@ for r in results:
136
143
 
137
144
  ## Session behavior
138
145
 
139
- AgentCore sessions cannot be reconnected after `interpreter.stop()` is called. Each `start()` creates a fresh, isolated MicroVM. Sessions auto-expire after a configurable timeout (default 15 minutes, maximum 8 hours).
146
+ AgentCore sessions cannot be reconnected once stopped. Each session is a fresh, isolated MicroVM, and its files are gone when it ends. Sessions auto-expire after `session_timeout_seconds` (default 15 minutes, maximum 8 hours); calls after that return a session-expired error.
147
+
148
+ `execute()` honors `timeout` by running the command under GNU `timeout` inside the sandbox. A command stopped this way returns exit code 124.
149
+
150
+ AgentCore caps each request and response at 100 MB and gives each session 10 GB of disk. See [AgentCore quotas](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/bedrock-agentcore-limits.html).
140
151
 
141
152
  ## Contributing
142
153
 
@@ -6,7 +6,7 @@
6
6
 
7
7
  Amazon Bedrock AgentCore Code Interpreter sandbox integration for [Deep Agents](https://github.com/langchain-ai/deepagents).
8
8
 
9
- This package provides `AgentCoreSandbox` — a [`SandboxBackendProtocol`](https://docs.langchain.com/oss/deepagents/sandboxes) implementation that wraps AgentCore's [Code Interpreter](https://docs.aws.amazon.com/bedrock/latest/userguide/agentcore-code-interpreter.html), a secure, isolated MicroVM environment for executing code. The caller manages the interpreter lifecycle (`start()` / `stop()`); the sandbox backend handles command execution and file operations.
9
+ This package provides `AgentCoreSandbox` — a [`SandboxBackendProtocol`](https://docs.langchain.com/oss/deepagents/sandboxes) implementation that wraps AgentCore's [Code Interpreter](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/code-interpreter-tool.html), a secure, isolated MicroVM environment for executing code. `AgentCoreSandbox.create()` starts a session and stops it when you close the sandbox or leave a `with` block.
10
10
 
11
11
  > **Note:** For the LangChain `BaseTool` integration (used with `create_react_agent` and LangGraph agents), see [`langchain-aws[tools]`](https://github.com/langchain-ai/langchain-aws). This package is specifically for the Deep Agents `BaseSandbox` protocol.
12
12
 
@@ -35,9 +35,9 @@ aws sso login --profile your-profile
35
35
 
36
36
  Any method supported by the [boto3 credential chain](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html) works, including EC2 instance profiles, ECS task roles, and environment variables.
37
37
 
38
- **2. IAM permissions** — your credentials must allow `bedrock-agentcore:InvokeCodeInterpreter` (or the equivalent action for your region). See the [AgentCore Code Interpreter docs](https://docs.aws.amazon.com/bedrock/latest/userguide/agentcore-code-interpreter.html) for the required IAM policy.
38
+ **2. IAM permissions** — your credentials must allow `bedrock-agentcore:InvokeCodeInterpreter` (or the equivalent action for your region). See the [AgentCore Code Interpreter docs](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/code-interpreter-tool.html) for the required IAM policy.
39
39
 
40
- **3. Region availability** — Code Interpreter is available in select AWS regions. `us-west-2` is a safe default. Pass the region to `CodeInterpreter(region=...)`.
40
+ **3. Region availability** — Code Interpreter is available in select AWS regions. `us-west-2` is a safe default. Pass the region to `AgentCoreSandbox.create(region=...)`.
41
41
 
42
42
  ## Quick Install
43
43
 
@@ -50,45 +50,52 @@ pip install langchain-agentcore-codeinterpreter
50
50
  ### Standalone
51
51
 
52
52
  ```python
53
- from bedrock_agentcore.tools.code_interpreter_client import CodeInterpreter
54
-
55
53
  from langchain_agentcore_codeinterpreter import AgentCoreSandbox
56
54
 
57
- interpreter = CodeInterpreter(region="us-west-2")
58
- interpreter.start()
55
+ with AgentCoreSandbox.create(region="us-west-2") as backend:
56
+ result = backend.execute("echo hello")
57
+ print(result.output, result.exit_code) # "hello" 0
58
+ ```
59
+
60
+ Sessions last 15 minutes by default. Pass `session_timeout_seconds` (up to 28,800, or 8 hours) for longer agent runs, and `identifier` to use a custom code interpreter with VPC networking or an execution role.
59
61
 
60
- backend = AgentCoreSandbox(interpreter=interpreter)
62
+ To configure the `CodeInterpreter` client yourself, pass a started one to the constructor instead. You then own its lifecycle:
61
63
 
62
- result = backend.execute("echo hello")
63
- print(result.output) # "hello"
64
+ ```python
65
+ from bedrock_agentcore.tools.code_interpreter_client import CodeInterpreter
64
66
 
65
- interpreter.stop()
67
+ interpreter = CodeInterpreter(
68
+ region="us-west-2", integration_source="langchain-deepagents"
69
+ )
70
+ interpreter.start()
71
+ try:
72
+ backend = AgentCoreSandbox(interpreter=interpreter)
73
+ ...
74
+ finally:
75
+ interpreter.stop()
66
76
  ```
67
77
 
68
78
  ### With Deep Agents
69
79
 
70
80
  ```python
71
- from bedrock_agentcore.tools.code_interpreter_client import CodeInterpreter
72
81
  from deepagents import create_deep_agent
73
82
 
74
83
  from langchain_agentcore_codeinterpreter import AgentCoreSandbox
75
84
  from langchain_aws import ChatBedrockConverse
76
85
 
77
- interpreter = CodeInterpreter(region="us-west-2")
78
- interpreter.start()
79
-
80
86
  model = ChatBedrockConverse(
81
- model="us.anthropic.claude-sonnet-4-6",
82
- region_name="us-west-2",
83
- )
84
- backend = AgentCoreSandbox(interpreter=interpreter)
85
- agent = create_deep_agent(
86
- model=model,
87
- backend=backend,
88
- system_prompt="You are a coding assistant with sandbox access.",
87
+ model="us.anthropic.claude-sonnet-4-6",
88
+ region_name="us-west-2",
89
89
  )
90
90
 
91
- try:
91
+ with AgentCoreSandbox.create(
92
+ region="us-west-2", session_timeout_seconds=3600
93
+ ) as backend:
94
+ agent = create_deep_agent(
95
+ model=model,
96
+ backend=backend,
97
+ system_prompt="You are a coding assistant with sandbox access.",
98
+ )
92
99
  result = agent.invoke(
93
100
  {
94
101
  "messages": [
@@ -97,18 +104,18 @@ try:
97
104
  }
98
105
  )
99
106
  print(result["messages"][-1].content)
100
- finally:
101
- interpreter.stop()
102
107
  ```
103
108
 
104
109
  ### File operations
105
110
 
106
111
  ```python
107
112
  # Upload files
108
- backend.upload_files([
109
- ("data.csv", b"name,value\nalice,42\nbob,17"),
110
- ("analyze.py", b"import csv\nprint('ready')"),
111
- ])
113
+ backend.upload_files(
114
+ [
115
+ ("data.csv", b"name,value\nalice,42\nbob,17"),
116
+ ("analyze.py", b"import csv\nprint('ready')"),
117
+ ]
118
+ )
112
119
 
113
120
  # Download files
114
121
  results = backend.download_files(["data.csv"])
@@ -121,7 +128,11 @@ for r in results:
121
128
 
122
129
  ## Session behavior
123
130
 
124
- AgentCore sessions cannot be reconnected after `interpreter.stop()` is called. Each `start()` creates a fresh, isolated MicroVM. Sessions auto-expire after a configurable timeout (default 15 minutes, maximum 8 hours).
131
+ AgentCore sessions cannot be reconnected once stopped. Each session is a fresh, isolated MicroVM, and its files are gone when it ends. Sessions auto-expire after `session_timeout_seconds` (default 15 minutes, maximum 8 hours); calls after that return a session-expired error.
132
+
133
+ `execute()` honors `timeout` by running the command under GNU `timeout` inside the sandbox. A command stopped this way returns exit code 124.
134
+
135
+ AgentCore caps each request and response at 100 MB and gives each session 10 GB of disk. See [AgentCore quotas](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/bedrock-agentcore-limits.html).
125
136
 
126
137
  ## Contributing
127
138