Perplexity has introduced a new architecture called "Search as Code" (SaC) that allows AI models to write their own search pipelines as Python code instead of relying on fixed search APIs. The company claims this approach leads to more precise results and reduces token usage significantly.
Traditional AI agents follow a repetitive loop: they write a query, a search API returns results, the model reads them, and then writes the next query. This process is rigid and inefficient for complex research tasks because the agent can only tweak the search term, while the rest of the API remains a black box. SaC changes this by letting the model generate a custom Python script that runs in a secure sandbox, using basic search primitives from Perplexity's backend.
The architecture consists of three layers: the model, the sandbox, and the Agentic Search SDK. The model decides on a search strategy, the sandbox executes the code safely, and the SDK provides individual functions for retrieving, filtering, deduplicating, and reranking results. For quick queries, standard search APIs are still available, but for complex research, the model can run parallel queries, programmatically filter noise, and pull only relevant information into its context window.
To demonstrate the effectiveness, Perplexity tested SaC on a cybersecurity task involving 200 critical software vulnerabilities (CVEs) from 2023 to 2025. The agent needed to find official vendor advisories, affected software, and patched versions. With SaC, the model wrote a three-stage script that ran parallel searches tailored to each vendor, identified gaps, and verified results using a schema. The agent completed the task using 85% fewer tokens than Perplexity's standard pipeline, while competing systems got less than a quarter of the data correct.
Perplexity claims SaC outperformed rivals like OpenAI's Responses API and Anthropic's Managed Agents on four out of five benchmarks, with the largest gap on their own "WANDR" benchmark for broad research tasks. While self-reported benchmarks should be taken with caution, the comparison against Perplexity's older architecture shows a clear performance leap.
This approach aligns with a broader trend of using code as an operational layer for AI, combining models for strategy with deterministic runtimes for efficient data handling. SaC is now rolling out in Perplexity Computer and the Agent API.