trowelCode Interpreter — Usage Guide

The gllm_tools code interpreter lets a language model execute Python code inside a secure sandbox. It supports three sandbox backends:

  • E2B — Cloud-based sandbox via E2Barrow-up-right

  • AWS Bedrock AgentCore — Managed sandbox via AWS Bedrock

  • Pydantic MCP — Local WebAssembly sandbox via Pydantic's MCP server (Pyodide)


Architecture Overview

SandboxCodeInterpreter
├── BaseLMInvoker          ← language model (generates code)
└── BaseSandbox            ← executes code
    ├── E2BSandbox
    ├── BedrockAgentCoreSandbox
    └── PydanticExecutorSandbox

The SandboxCodeInterpreter orchestrates a multi-turn conversation where the LM generates Python code, the sandbox executes it, and results are fed back to the LM until it produces a final answer.


Installation

Install gllm-tools with the extras matching the sandbox(es) you want to use:

# E2B sandbox
pip install "gllm-tools[e2b]"

# AWS Bedrock sandbox
pip install "gllm-tools[bedrock]"

# Pydantic MCP sandbox (requires deno in PATH)
pip install "gllm-tools[pydantic-mcp]"

Common Imports


Using SandboxCodeInterpreter (High-Level)

SandboxCodeInterpreter is the main entry point. It pairs a sandbox with a language model invoker and handles the full tool-calling loop automatically.

Passing Files

You can pass files as Attachment objects. They are uploaded to the sandbox at /files/<filename> before execution.

Downloading Output Files

If the LM creates files during execution, it will include download links in its response using the format:

These files are automatically downloaded and returned as Attachment objects inside result.code_exec_results[-1].output.


Using Sandboxes Directly (Low-Level)

You can also use the sandboxes directly without SandboxCodeInterpreter for raw code execution.

For each implementation guide, you can check:


ExecutionResult Reference

All sandboxes return an ExecutionResult object from execute_code().

Field
Type
Description

status

ExecutionStatus

SUCCESS, ERROR, or TIMEOUT

code

str

The code that was executed

stdout

str

Standard output

stderr

str

Standard error

text

str

Combined output/error, suitable for display

error

str

Error message (populated on failure)

exit_code

int

0 on success, 1 on error

duration_ms

int | None

Execution time in milliseconds

Checking Results


Sandbox Comparison

Feature
E2B
Bedrock AgentCore
Pydantic MCP

Execution environment

Cloud VM

AWS managed

Local WASM (Pyodide)

API key required

Yes (E2B)

AWS credentials

No

State persists between calls

Yes

Partial

No

File upload

Yes (/files/)

Yes

Yes (/files/)

File download

Yes

Yes

No

Custom packages

additional_packages

Not configurable

Not supported

Requires network

Yes

Yes

No

Deno required

No

No

Yes

Initialization style

await E2BSandbox.create(...)

BedrockAgentCoreSandbox(...)

PydanticExecutorSandbox()


Error Handling

All sandboxes return structured ExecutionResult objects instead of raising exceptions on code errors. Unexpected infrastructure failures (network, credentials, process crashes) do raise exceptions.

Always Terminate

Always call await sandbox.terminate() when done, ideally inside a finally block:

Last updated

Was this helpful?