Appearance
Code interpretation
Optional extra for code_interpreter:
bash
pip install --extra-index-url https://elsai-agents.elsai.ai/root/ "elsai-agents-tools[agent-core-code-interpreter]==0.3.0"Tools
python_repl
Execute Python in a persistent REPL session where variables and imports carry over between calls
Gate code with execution_permissions on AgentConfig (tools=("python_repl",)).
Notes: Not supported on Windows (fcntl unavailable). On A2A servers, PER_CONTEXT — see Stateful tools on A2A.
Environment variables
| Variable | Required | Default | Description |
|---|---|---|---|
PYTHON_REPL_PERSISTENCE_DIR | optional | ./repl_state/ | Where standalone (non-A2A) REPL state is saved |
PYTHON_REPL_BINARY_MAX_LEN | optional | 100 | Max length shown for binary output |
Also respects BYPASS_TOOL_CONSENT (see Tool consent).
On A2A servers, REPL state is under $ELSAI_A2A_SESSION_DIR/<context_id>/repl/.
code_interpreter
Run Python or other languages in an isolated Bedrock AgentCore sandbox with no local machine access
Extra: agent-core-code-interpreter
Notes: On A2A servers, PER_CONTEXT via AgentCoreCodeInterpreter.
Environment variables
No dedicated environment variables.
Configured via AgentCoreCodeInterpreter(...) constructor args (for example region), not env vars.
Examples
python_repl
Requires OPENAI_API_KEY. For demos set BYPASS_TOOL_CONSENT=true (see Tool consent). Not supported on Windows.
bash
pip install --extra-index-url https://elsai-agents.elsai.ai/root/ elsai-agents==0.3.1
pip install --extra-index-url https://core-packages.elsai.ai/root/ "elsai-model[openai]==2.1.0"
pip install --extra-index-url https://elsai-agents.elsai.ai/root/ elsai-agents-tools==0.3.0python
import os
from elsai import Agent
from elsai.agent import AgentConfig
from elsai_model.openai import OpenAIModel
from elsai_tools.python_repl import python_repl
agent = Agent(
model=OpenAIModel(
model_id="gpt-4o-mini",
client_args={"api_key": os.environ["OPENAI_API_KEY"]},
),
tools=[python_repl],
system_prompt=(
"Use python_repl to run Python code. "
"After using tools, answer the user clearly in plain text."
),
config=AgentConfig(name="repl_assistant"),
)
result = agent("Use the REPL to compute the sum of squares from 1 to 10, then tell me the result.")
print(result)code_interpreter
Requires AWS credentials and the AgentCore extra. The agent model below uses OpenAI; the sandbox runs on Bedrock AgentCore.
bash
pip install --extra-index-url https://elsai-agents.elsai.ai/root/ elsai-agents==0.3.1
pip install --extra-index-url https://core-packages.elsai.ai/root/ "elsai-model[openai]==2.1.0"
pip install --extra-index-url https://elsai-agents.elsai.ai/root/ "elsai-agents-tools[agent-core-code-interpreter]==0.3.0"python
import os
from elsai import Agent
from elsai.agent import AgentConfig
from elsai_model.openai import OpenAIModel
from elsai_tools.code_interpreter import AgentCoreCodeInterpreter
interpreter = AgentCoreCodeInterpreter(region="us-west-2")
agent = Agent(
model=OpenAIModel(
model_id="gpt-4o-mini",
client_args={"api_key": os.environ["OPENAI_API_KEY"]},
),
tools=[interpreter.code_interpreter],
system_prompt=(
"Use code_interpreter to run code in the sandbox. "
"After using tools, answer the user clearly in plain text."
),
config=AgentConfig(name="sandbox_assistant"),
)
result = agent("In the sandbox, print 'Hello, World!' and return the output.")
print(result)Parameter reference: Code interpretation API.