> ## Documentation Index
> Fetch the complete documentation index at: https://docs.akua.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Code Mode in Action

> See how agents compose complex multi-step operations in a single tool call

<Frame>
  <img className="block dark:hidden" src="https://mintcdn.com/akua-1dce587a/AEEz0U2s7Do2sYaM/images/heros/code-mode-in-action-light.svg?fit=max&auto=format&n=AEEz0U2s7Do2sYaM&q=85&s=ac9befd31a374b5e0b67f60e70995116" alt="A single execute call fans out into many parallel API requests, the results gather and aggregate inside the sandbox, and only a compact summary returns to the model's context window" width="1536" height="864" data-path="images/heros/code-mode-in-action-light.svg" />

  <img className="hidden dark:block" src="https://mintcdn.com/akua-1dce587a/AEEz0U2s7Do2sYaM/images/heros/code-mode-in-action-dark.svg?fit=max&auto=format&n=AEEz0U2s7Do2sYaM&q=85&s=12b8c557a7db1f0f0e014594b6c111d3" alt="A single execute call fans out into many parallel API requests, the results gather and aggregate inside the sandbox, and only a compact summary returns to the model's context window" width="1536" height="864" data-path="images/heros/code-mode-in-action-dark.svg" />
</Frame>

[Code Mode](/ai/platform-mcp#why-code-mode) replaces hundreds of individual MCP tools with just two: `search` and `execute`. The agent writes JavaScript that runs in a sandboxed V8 isolate. That code can fan out dozens of internal API calls, run them in parallel, aggregate results, and return a summary. All in one tool invocation.

## Why it works

LLMs have seen millions of lines of real-world JavaScript but only contrived tool-calling examples. Writing `Promise.all()` with a `.map()` is natural for them; chaining individual tool calls is not.

The sandbox provides:

* **`platform.request()`**: typed API client with auth injected server-side
* **Full JavaScript**: `Promise.all`, `Array.map`, `Date.now()`, error handling, any logic the agent needs
* **Up to 50 API calls** per execution, enough for complex multi-step workflows
* **No network escape**: requests only reach the Akua API, never the open internet

The agent's code filters, aggregates, and formats data inside the sandbox before returning, so only the summary hits the context window, not raw API responses.

## Examples

<CardGroup cols={3}>
  <Card title="Parallel Log Analysis" icon="file-lines" href="/ai/examples/parallel-log-analysis">
    35,000 lines across 11 pods in 506ms. Parallel fan-out with in-sandbox aggregation.
  </Card>

  <Card title="Resource Audit" icon="gauge" href="/ai/examples/resource-audit">
    CPU/memory capacity report in 56ms. Unit parsing and computation from a single API call.
  </Card>

  <Card title="Security Audit" icon="shield-halved" href="/ai/examples/security-audit">
    9 security checks across 7 parallel API calls, then auto-remediates with network policies.
  </Card>

  <Card title="Incident Debugging" icon="bug" href="/ai/examples/incident-debugging">
    Full SRE triage (pod health, events, error logs, rollout history), adapting at each step.
  </Card>

  <Card title="Database Operations" icon="database" href="/ai/examples/database-operations">
    Run SQL queries, check Redis memory, and chain diagnostics, all through exec.
  </Card>

  <Card title="Cross-Cluster Comparison" icon="code-compare" href="/ai/examples/cross-cluster-comparison">
    Compare versions, images, and CRDs across your entire fleet in one call
  </Card>

  <Card title="CRD Discovery" icon="magnifying-glass-chart" href="/ai/examples/crd-discovery">
    Discover, inspect, and interact with custom resources the agent has never seen
  </Card>
</CardGroup>

## What agents can do

| Prompt                                    | What happens                                                  |
| ----------------------------------------- | ------------------------------------------------------------- |
| "Count log lines across all pods"         | Parallel log fetches, line counting, sorted summary (506ms)   |
| "Audit resource requests and limits"      | CPU/memory unit parsing, per-pod aggregation (56ms)           |
| "Audit the cluster for security"          | 9 checks across pods, RBAC, secrets, network policies         |
| "Create network policies for my installs" | Discovers ports, generates and applies policies per namespace |
| "Why is my app returning 500s?"           | Adaptive triage: pod health → events → logs → rollout history |
| "What's the largest table in Postgres?"   | Runs `psql` inside the container via exec                     |
| "Are my clusters on the same version?"    | Parallel fan-out across all clusters, drift detection         |
| "What CRDs are installed?"                | Discovers custom APIs, reads schemas, queries instances       |

Each row is one or two tool calls. The agent writes the code, the sandbox executes it, and only the results reach the context window.

## Related topics

<CardGroup cols={2}>
  <Card title="Platform MCP" icon="server" href="/ai/platform-mcp">
    How Code Mode works and the two tools it exposes.
  </Card>

  <Card title="Kubernetes access" icon="dharmachakra" href="/ai/kubernetes-access">
    Kube API proxy, pod logs, and command execution.
  </Card>

  <Card title="Dashboard generation" icon="gauge" href="/ai/dashboard-generation">
    Use the same sandbox to build live operational dashboards.
  </Card>

  <Card title="Hosted agents" icon="robot" href="/agents">
    The embedded dashboard agent and full agent product model.
  </Card>
</CardGroup>
