Run code - Perplexity
Summary
Perplexity's "sandbox" tool provides language model agents with an isolated Linux container to execute real code, ensuring exact results for tasks like numerical computations, data transformations, or report generation. Unlike language models that approximate, the sandbox delivers precise outputs, crucial for scenarios such as calculating compound annual growth rates (e.g., from 4.2M in 2019 to 11.8M in 2025, yielding approximately 18.79%). Agents can also leverage Perplexity's Web Search, Fetch URL Content, and People Search tools from within the container. Enabling the sandbox involves adding {"type": "sandbox"} to the "tools" array. Its applications span numeric calculations, data cleaning, code logic verification, and generating various file types like CSV or JSON. The tool's output includes "sandbox_results" with executed code, language, and standard output/error, allowing verification of computed answers. It also supports returning generated files and long-running background processes.
Key takeaway
For AI Engineers building agents that require verifiable, exact computations or complex data transformations, Perplexity's "sandbox" tool is essential. It addresses the inherent approximation of language models by providing a secure, isolated environment for code execution. You should integrate "sandbox" for tasks like financial calculations, data cleaning, or generating structured reports, ensuring accuracy and reproducibility in your agent's outputs. This capability allows your agents to move beyond estimations to deliver precise, auditable results.
Key insights
The "sandbox" tool provides language model agents with an isolated environment for precise code execution, overcoming inherent approximation.
Principles
- Language models approximate exact arithmetic and data manipulation.
- Isolated execution environments ensure precise, verifiable results.
- Agents can integrate external tools within the sandbox for enhanced workflows.
Method
To enable, add {"type": "sandbox"} to the "tools" array; the model decides execution. Verify results by parsing "sandbox_results" from the response "output" array, checking "stdout" and "exit_code".
In practice
- Perform precise numeric calculations like CAGR.
- Clean and transform datasets for analysis.
- Generate structured files such as CSV or JSON reports.
Topics
- Perplexity Sandbox
- Language Model Agents
- Code Execution
- Exact Computation
- Data Transformation
- Tool Integration
Best for: AI Engineer, Machine Learning Engineer, Software Engineer
Related on AIssential
Editorial summary, takeaway, and curation by AIssential. Original article published by perplexity.ai via Google News.