agent_with_code_execution

command
v0.3.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2026 License: Apache-2.0 Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package main implements a CodeTool that lets the LLM write and execute code inside an agent run. The tool contract (name, parameters, SandboxRuntime interface) is sandbox-agnostic — execution is handled by whatever SandboxRuntime is wired in main.go.

local_runner.go — default runner using os/exec (needs Python or Node installed locally) docker_runner.go — isolated runner using Docker (SANDBOX_ENV=docker)

Package main — SandboxRuntime backed by Docker.

This file is the Docker-specific execution layer for the agent_with_code_execution example. It satisfies the SandboxRuntime interface defined in code_tool.go.

To use a different sandbox (AWS Lambda, Modal, E2B, Firecracker, etc.), add a sibling file implementing SandboxRuntime and wire it in main.go instead of newDockerRunner.

Requires: Docker daemon running and internet access to pull language images on first run.

agent_with_code_execution demonstrates sandboxed code execution inside an agent.

The goal: the LLM writes code to answer a user question; the code runs in an isolated sandbox and returns the output. The LLM reads the output and replies. The sandbox is pluggable — swap the runtime without changing the tool contract.

code_tool.go — CodeTool and SandboxRuntime interface (sandbox-agnostic) local_runner.go — default runtime using os/exec (needs Python or Node on host) docker_runner.go — isolated runtime using Docker; activate with SANDBOX_ENV=docker

Run (local sandbox — needs Python or Node installed):

go run ./agent_with_code_execution "Write a Python script that prints the first 10 Fibonacci numbers"

Run (Docker sandbox — needs Docker daemon):

SANDBOX_ENV=docker go run ./agent_with_code_execution "Write a Python script that prints the first 10 Fibonacci numbers"

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL