Skip to main content
Give a model a calculation task and let it use a Cloud box as its tool. The model generates Python, your application runs it in an isolated box, and the execution result goes back to the model for its answer. Use this pattern when an agent needs to calculate an answer or transform data with code. This first task has a known result so you can verify the entire tool loop before substituting your own data. Ask it to calculate the sum of the squares of integers 1 through 100. Your terminal will show 338350, and the temporary box will be removed automatically. Five-step loop from model tool call through Cloud execution and cleanup to the final answer This is box as an agent’s tool: the model and orchestration run outside the box. For an agent that lives inside a persistent workspace, see Host an agent runtime.

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:
Set your model provider’s base URL and model ID, then read its key. The URL below is Anthropic’s endpoint; replace it with your provider’s Anthropic-compatible base URL when using another provider. Use the base URL, without /v1/messages.
Both keys stay in your local application. Only the generated Python code enters the box. No model credentials, Cloud credentials, host directories, or Secrets are supplied to the guest.

2. Run the complete tool loop

Choose one client. Each example makes a real model request, handles its run_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.
Use Python 3.10 or later:
Save as interpreter.py:
interpreter.py

3. Check the result and cleanup

A successful run looks like this:
The model’s final wording can vary. 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 supplies code, 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.

Troubleshooting