Overview
Thesandbox tool lets the model run code during an Agent API request. The agent can execute code in an isolated container, inspect the output, and use the result in its final answer.
You don’t supply the code. You enable the tool, and the model writes and runs the code itself based on your prompt and instructions - then reads its own stdout/stderr back and uses it in the answer. The exact code the model ran is returned to you in the response (see Response shape), so you can verify what executed.
Enable the tool by adding it to the tools array. The model decides when to call it based on your prompt and instructions.
Use cases
- Web search
- Numeric calculations and statistical analysis
- Data cleaning, parsing, and transformation
- Code execution to check logic or reproduce an error
- Structured artifact generation, such as CSV, JSON, or reports
- Multi-step workflows that need intermediate files or computed state
How the container works
The sandbox is an isolated Linux container. Knowing what it can and can’t do helps you predict when the model will reach for it and what to expect back.Calling other tools from inside the sandbox
The container ships with a preinstalled Perplexity SDK, so code the model runs inside the sandbox can call Web Search, Fetch URL Content, and People Search directly - without you adding those tools to the request - then compute on what they return. Each such call is billed at its standard per-invocation rate (see Pricing).Use connectors in the sandbox
Some connectors make their credentials available to sandbox commands.Preview: Connectors are in preview. Supported services and behavior may change.
GitHub connector
The GitHub connector lets the model use your connected GitHub credentials in sandbox commands. Enable bothsandbox and the GitHub connector in the request.
The model can then use git and gh to clone private repositories, change code, commit changes, and create or update pull requests.
It can access only repositories and perform only actions that your connected GitHub account permits.
For the request shape and a GitHub example, see Connectors.
Running in the background
For long-running sandbox calls, submit the request withbackground: true and poll the response by ID until it completes.
Error handling
Sandbox errors are returned through the normal Agent API response.Limits and quotas
Sandbox runs inside Agent API requests and is subject to Agent API rate limits. See Rate Limits & Usage Tiers for tier-based request limits.Response shape
When the model calls the sandbox tool, the Agent API response includes asandbox_results item in its output array alongside any message items. A single response can contain multiple sandbox_results items if the model makes more than one sandbox call.
Each sandbox_results item describes one sandbox invocation and nests the per-execution output inside a results array.
Each entry in
results has the following fields:
Example:
Retrieving generated files
When code in the sandbox writes a file and delivers it with theshare_file tool, the response output array includes a share_file item. The file content is not returned inline — retrieve it with the response files endpoints, using the response id.
List the files a response produced:
Download a file’s content by its
id. The endpoint returns the raw file bytes (not JSON), with a Content-Type matching the file and a Content-Disposition: attachment header carrying the original filename.
Pricing
sandbox is billed on three axes:
Sandbox invocations are counted under
usage.tool_calls_details.sandbox.invocation.
See Pricing for the full Agent API tool pricing table.