Skip to main content

Overview

Python tool allows you to execute Python code from your AI agents. The user sends code; the agent runs it in a sandbox and returns stdout and results.

Installation

Quick Start

1

Simple Usage

2

With Configuration

Use the same tool with an agent — see Usage with Agent below, or pass env vars and options from the sections above.

Usage with Agent

Available Methods

execute(code)

Execute Python code.

Security Warning

⚠️ Use with caution! Executing arbitrary code can be dangerous.

How It Works


Best Practices

Only execute code generated from trusted instructions. Treat all output as untrusted.
Wrap execution so tracebacks are returned to the agent instead of terminating the run.
Pass all inputs explicitly — don’t rely on state persisting between executions.

Shell

Shell commands

Calculator

Math calculations