Appearance
Code Interpretation
Run Python locally or in a remote sandbox. Gate python_repl with execution_permissions.
| Tool | Extra | Description |
|---|---|---|
python_repl | base | Persistent local Python REPL. Not supported on Windows. |
code_interpreter | agent-core-code-interpreter | Sandboxed execution on Bedrock AgentCore. Register AgentCoreCodeInterpreter(...).code_interpreter. |
python_repl
Persistent local Python REPL. Not supported on Windows.
python
from elsai_tools.python_repl import python_repl| Parameter | Type | Required | Description |
|---|---|---|---|
code | str | Yes | Python code to execute |
interactive | bool | No | Interactive REPL mode |
reset_state | bool | No | Reset REPL state before running |
Persistence and A2A isolation
python_repl keeps a persistent namespace between calls. Where that state is stored depends on context:
| Scenario | Persistence path |
|---|---|
Standalone agent (no A2A context_id) | ./repl_state/ in the working directory, or $PYTHON_REPL_PERSISTENCE_DIR/repl_state/ when set |
A2A server (context_id present) | $ELSAI_A2A_SESSION_DIR/<context_id>/repl/ (default base: {tempdir}/elsai-a2a-sessions) |
On A2A servers, python_repl declares PER_CONTEXT session scope. Each context_id receives its own REPL namespace and pickle file, so variables from one conversation cannot leak into another.
Requires elsai-agents-tools==0.3.0 with elsai-agents>=0.3.1 (A2A session store and PrefixedTemplateSessionsStore).
Using on an A2A server
python
from elsai import Agent
# Register the tool on the template agent; PER_CONTEXT cloning is automatic.
agent = Agent(tools=[...]) # e.g. tools=[python_repl], tools=[graph], …Full A2AServer + session-manager wiring lives in Concepts — see Stateful prebuilt tools — examples.
- PER_CONTEXT is built in — register
python_replon the template agent; cloning happens automatically percontext_id. - State path:
$ELSAI_A2A_SESSION_DIR/<context_id>/repl/repl_state.pkl - See Stateful prebuilt tools — examples for a shared server pattern and multi-tool setup.
code_interpreter
Sandboxed execution on Bedrock AgentCore. Register AgentCoreCodeInterpreter(...).code_interpreter.
python
from elsai_tools.code_interpreter import AgentCoreCodeInterpreter
interpreter = AgentCoreCodeInterpreter(region="us-west-2")
agent = Agent(tools=[interpreter.code_interpreter])Extra: agent-core-code-interpreter
| Parameter | Type | Required | Description |
|---|---|---|---|
code_interpreter_input.action | str | Yes | Action type (executeCode, etc.) |
code_interpreter_input.code | str | Yes | Code to run |
code_interpreter_input.language | str | No | python, javascript, or typescript |
code_interpreter_input.session_name | str | No | Sandbox session name |
A2A isolation
On A2A servers, code_interpreter (via AgentCoreCodeInterpreter) declares PER_CONTEXT scope. Each context_id receives a cloned interpreter instance. Sandbox session names are prefixed with the context_id so remote sessions cannot collide across concurrent A2A conversations.
Using on an A2A server
python
from elsai import Agent
# Register the tool on the template agent; PER_CONTEXT cloning is automatic.
agent = Agent(tools=[...]) # e.g. tools=[python_repl], tools=[graph], …Full A2AServer + session-manager wiring lives in Concepts — see Stateful prebuilt tools — examples.
- Requires
elsai-agents-tools[agent-core-code-interpreter]and AWS credentials for Bedrock AgentCore. - Remote sandbox session names are prefixed with
context_idautomatically.
See Stateful tools on A2A and Stateful prebuilt tools — examples.