sandbox tool gives the agent an isolated Linux container to run real code and use the output in its answer — for results that must be exact, like a computed number, a transformed dataset, or a generated report. From inside the container the agent can also call Perplexity’s Web Search, Fetch URL Content, and People Search without adding them to the request, then compute on what they return — each billed at its standard rate. The Sandbox tool reference has the full settings, response shape, and pricing.
Enable the sandbox
Add{"type": "sandbox"} to the tools array. The model decides when to run code based on your prompt.
When to reach for it
- Numeric calculations and statistical analysis where an estimate won’t do
- Data cleaning, parsing, and transformation
- Executing code to check logic or reproduce an error
- Generating files and artifacts — CSV, JSON, HTML, reports, or any other file the code writes
- Multi-step workflows that need intermediate files or computed state
Read the computed result
When the agent runs code, the responseoutput array includes one or more sandbox_results items alongside the message. Each carries the executed code, the language, and a results array with stdout, stderr, exit_code, and status. That’s how you verify the agent computed the answer rather than guessing it. See the response shape reference for every field.
Read that item back off the response (response here is from the Enable the sandbox example above):
Python
Response
Response
- Formatted code
- Raw response
Output
Return files
When code in the sandbox writes a file and shares it, the responseoutput includes a share_file item. The bytes aren’t inline — list and download them with the response files endpoints, keyed by the response id:
Long-running sandbox work pairs well with background runs: submit with
background: true and poll by ID. See Shape the output → Streaming and the Sandbox reference.Next steps
Sandbox reference
Full sandbox settings, response shape, file retrieval, and pricing.
Shape the output
Stream output as it arrives and enforce structured JSON.