Learning resourcesReviewed · Perplexity

Perplexity Agent API: Run code

Perplexity's Run code guide helps developers add calculations and file generation to AI agents, but the model decides when to execute code. It explains how to enable the sandbox, inspect execution results and download generated files through the Agent API.

Researched 25 Nov 2026

In short.

Perplexity's Run code guide teaches developers to give AI agents a code execution environment, but enabling it does not guarantee execution on every request. It provides Python, TypeScript and cURL examples, explains execution records and shows how to retrieve generated files. Its worked calculation is publisher-provided evidence, not an independently reproduced result. Current prices, runtime limits and reuse rights are not established by this page.

Researched and written by an AI model and checked by a second AI model. How it works

Coverage includes the complete selected page at [https://docs.perplexity.ai/docs/agent-api/building-agents/run-code.md], including its examples, raw response, tips and background-run note. The documentation index and linked sandbox, search, output-control and structured-output pages are excluded. Pricing, settings and procedures delegated to those pages remain unknown unless stated directly in the selected page. No code, API request or file download was executed; runtime behavior and publisher-provided results were not independently validated.

The overview

identity

Run code is a Perplexity Agent API documentation guide at [https://docs.perplexity.ai/docs/agent-api/building-agents/run-code.md]. It teaches the sandbox feature rather than providing a separate application or downloadable code library.

The documented feature gives an agent an isolated Linux container for executing code and producing files. The isolation description is the publisher's claim; its security properties are not assessed here.

assessment

The guide is useful for developers who need an AI response to incorporate an actual calculation, data transformation or generated artifact. Its strongest practical detail is showing where to inspect the executed code and its output.

It provides enough detail to construct an initial API request, but not enough to establish production suitability. Reliability, operational limits, security controls and end-to-end behavior remain unassessed.

users

The intended readers are developers building agents for numerical analysis, data cleaning, debugging, report generation or tasks that use intermediate files. Beginners get a concrete request to follow; experienced developers get response fields and file-retrieval calls to integrate.

The examples assume familiarity with API requests and basic programming. The page does not explain account creation, credential provisioning or SDK installation.

capabilities

Documented uses include calculations, statistical analysis, parsing and transforming data, checking code logic, reproducing errors and writing files such as CSV, JSON, HTML and reports. Intermediate files and computed state can support tasks with several steps.

The page also says code inside the container can call Perplexity Web Search, Fetch URL Content and People Search without adding those tools to the request. Those integrations are described but not demonstrated in the worked example.

Using it

requirements

The documented path requires access to the Perplexity Agent API and authentication. The cURL example uses a bearer token supplied through PERPLEXITY_API_KEY. Client examples use the perplexity Python package or @perplexity-ai/perplexity_ai for TypeScript; the shell examples also use jq.

The examples specify model openai/gpt-5.6-sol. The page does not establish the full set of compatible models, minimum SDK versions, account eligibility or sandbox package availability. Python is demonstrated inside the sandbox; TypeScript is shown as an API client language.

mechanism

Adding {"type":"sandbox"} to the request's tools array makes code execution available. The model chooses when to invoke it, and the example adds an instruction to compute in the sandbox before answering.

Execution produces sandbox_results entries in response.output alongside the answer message. These entries expose code, language and results containing stdout, stderr, exit_code and status. They let a developer inspect the computation separately from the written answer.

When code writes and shares a file, the output includes a share_file item. File bytes are retrieved separately through response file endpoints using the response ID and file ID.

setup

The SDK examples create a Perplexity client and call client.responses.create with a model, input, sandbox tool declaration and instruction to calculate before answering. The equivalent HTTP request posts to [https://api.perplexity.ai/v1/agent].

The Python example extracts output_text content from message items, while execution details require inspecting sandbox_results separately. For generated files, the documented SDK sequence is client.responses.files.list(response.id), followed by client.responses.files.content with the selected file ID and response ID.

The page recommends background: true and polling by ID for longer tasks, but delegates the full background-run procedure to linked documentation.

example

The worked request asks for compound annual growth from 4.2 million in 2019 to 11.8 million in 2025. The publisher shows Python using Decimal with precision set to 50, a six-year interval and logarithm and exponential operations. The displayed result is approximately 18.79% per year.

The supplied response records completed execution, exit_code 0 and an empty stderr. These are documentation results; the example has not been independently executed. Its finite-precision calculation should not be interpreted as proof that every sandbox answer is mathematically exact.

Assessment & evidence

limitations

Tool availability is not proof of invocation: the model decides when to execute code. A completed execution also does not establish that the inputs, formula or final explanation are correct.

The page does not establish CPU or memory allowances, timeouts, supported execution languages beyond the Python example, package installation rules, network restrictions, file-size limits or file retention. Multi-step use is suggested, but container lifetime and state persistence are not specified.

Failure recovery, concurrency and production reliability are not demonstrated. File retrieval is illustrated with code rather than a captured successful download.

reasoning

The practical benefit is an inspectable computation behind an answer. Reviewing sandbox_results can establish whether execution was recorded and reveal runtime errors or discrepancies between printed output and the final response.

That makes the documented approach relevant when calculations and artifacts need review. Correctness still depends on appropriate code and inputs; the execution record alone cannot establish either.

alternatives

The page does not compare competing sandbox services, local execution or other agent frameworks. Relative cost, speed, portability and control are unknown.

Web Search and structured JSON output appear as companion features. The page does not present them as substitutes for running calculations or generating files.

evidence

The evidence consists of the complete Run code documentation page, including three client examples, Python execution code, a raw response and file-retrieval snippets. The raw response supports the described response structure and the publisher's worked example.

Source address: [https://docs.perplexity.ai/docs/agent-api/building-agents/run-code.md]. The captured source SHA-256 is 4cba25977531bc6ced71d6206a86949a5eebf9a275604d9cded1a74b89aba14a. No independent execution, benchmark or security evaluation is available.

Access & freshness

costs

Current sandbox prices and the expected cost of a real workload are unknown from this page. It directs readers to the sandbox reference for pricing and says internal SDK web searches use the sandbox SDK web search rate, while fetch and people searches use the fetch_url and people_search rates. No rate amounts are supplied.

The sample response reports USD 0.01305 in input cost, USD 0.00588 in output cost and USD 0.01893 total, with zero recorded sandbox tool cost. Those figures describe one published example and do not establish free sandbox usage or a current price.

rights

The page supplies no licence or reuse terms for its text or code examples. Redistribution rights, commercial-use terms and ownership of generated artifacts are not established.

Data retention, confidentiality and treatment of information processed inside the sandbox are also unspecified on this page.

freshness

The page was captured on 2026-11-25 at 09:03:05.737 UTC. That timestamp dates the captured documentation, not the feature's release or the page's last update.

The page provides no explicit publication date, update date or SDK version. Present availability of the example model and continued compatibility of the illustrated API calls are not independently verified.

actions

For an initial evaluation, use a calculation with a known expected answer, enable sandbox and explicitly request computation. Inspect sandbox_results for executed code, stdout, stderr, exit_code and status, then compare the result with the final message.

For file-generation work, check for share_file and verify that the response file endpoints return the intended artifact. Before planning a workload, consult the sandbox reference for current pricing and operational settings at [https://docs.perplexity.ai/docs/agent-api/tools/sandbox.md]. Its contents are outside this page's assessed scope.

Evidence for this report

selected-page.txtselected · checked 2026-11-25