1. Configure your credentials
You need a BoxLite Cloud account with available capacity and a model provider supporting the Anthropic Messages API and tool calls. Create a Cloud key under API Keys in the console. In your local Bash or Zsh terminal, set the Cloud endpoint and read the key:/v1/messages.
2. Run the complete tool loop
Choose one client. Each example makes a real model request, handles itsrun_python tool call, returns the result, and prints the model’s answer.
The box uses the python:alpine image with one CPU and 256 MiB memory. Guest networking is disabled; the generated code uses Python’s standard library. The SDK examples set a 3-second execution timeout and stop waiting for its result after 15 seconds.
- Python
- TypeScript
- CLI
Use Python 3.10 or later:Save as
interpreter.py:interpreter.py
3. Check the result and cleanup
A successful run looks like this:Result comes from executing its generated code in the box. The application returns that output using the model’s tool-call ID, so the final answer can use the computation.
Check the console’s Boxes list: the printed box ID should no longer exist. The example removes it before requesting the final answer, so the box also stays deleted if that last model request fails.
The SDK examples use finally; the CLI uses an exit trap. A Python error also triggers cleanup and a nonzero local exit code. The SDK examples apply the same cleanup when execution or result collection times out. Cleanup briefly retries if Cloud reports a state transition in progress. If you forcibly terminate the local process, check the console for a leftover box and remove it there.
Adapt it to your agent
Change the task prompt to another calculation or standard-library data-processing task. Keep the same tool interface: the model suppliescode, and your application returns the execution output.
In an existing agent loop, register run_python as a tool handler. You can choose whether to return execution errors as tool results for the model to correct; this walkthrough stops on an execution error.
Keep model and Cloud credentials in the trusted caller. Use Secrets when code inside a box needs an external credential; this example’s model calls happen outside it.

