---
title: "Code Mode"
description: "Let an agent write a short script against the Lookio API in a sandbox, with two tools, search and execute, the same scopes and strict limits."
canonical: "https://lookio.app/docs/mcp/code-mode"
updated: "2026-11-03"
---

# Code Mode

Code Mode is a second MCP server for agents that work better by writing code than by chaining many tool calls.

```text
https://mcp.lookio.app/mcp/code
```

It has two tools. The standard server at `/mcp` is unchanged and stays the default.

| Tool      | What it does                                                                                                                                                                                                                      |
| --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `search`  | Finds API operations. The agent sends a JavaScript filter, which runs against Lookio's API description inside the sandbox. Without a filter it returns every operation in a compact form, a few hundred tokens for the whole API. |
| `execute` | Runs a JavaScript program with a `request()` function that calls the API.                                                                                                                                                         |

The API description stays in the sandbox, so it never fills the agent's context, and the two tool descriptions have a fixed size whatever the API grows into.

## Calling the API

Inside `execute`, `request({ method, path, query, body })` calls an endpoint and returns the parsed response: `{ data, request_id }` and, for a list, `has_more` and `next_cursor`. A failed call throws an `Error` carrying the API's message.

```js title="Re-index every failed resource"
const failed = [];
let cursor;

do {
  const page = await request({
    method: "GET",
    path: "/v1/resources",
    query: { limit: 100, ...(cursor ? { cursor } : {}) },
  });
  for (const resource of page.data) {
    if (resource.status === "failed") {
      await request({ method: "POST", path: `/v1/resources/${resource.id}/reindex` });
      failed.push({ id: resource.id, title: resource.title });
    }
  }
  cursor = page.next_cursor;
} while (cursor);

return { reindexed: failed.length, failed };
```

Only what the script returns, and what it logs with `console.log`, goes back to the agent. The script should filter and summarise inside the sandbox rather than return raw rows.

## Limits

| Limit                           | Value                                                              |
| ------------------------------- | ------------------------------------------------------------------ |
| Time for one execution          | 30 seconds                                                         |
| Size of a program               | 64 KB                                                              |
| Size of the result              | 256 KB. A longer result is cut and marked `[truncated by Lookio]`. |
| Log output                      | 200 lines and 32 KB                                                |
| `request()` calls per execution | 100. Going over fails the whole run.                               |

Every `request()` counts against the credential's [rate limit](/docs/api/rate-limits), exactly like the matching HTTP call.

## Same permissions, same costs

Code Mode goes through the same routes, validation and scope checks as an HTTP request. A path the connection has no scope for fails with `insufficient_scope`. A script cannot do more than the connection already may.

Costs are the same too, and a loop multiplies them. A script that calls `POST /v1/assistants/{assistant_id}/query` 100 times asks 100 questions and spends the credits of 100 answers. Limit the `query` scope on connections you give to Code Mode, and tell the agent to ask before it loops over questions.

## What a script cannot do

- Open a network connection. There is no `fetch` and no file system. `request()` is the only way out.
- Upload a file, which needs a streamed body, or stream an answer.
- Set headers, including `Idempotency-Key`.
- Reach the engine, the database or another workspace.

## Connecting

Connect to the Code Mode URL the same way as the standard server. See [Connect an AI client](/docs/mcp/connect). A token requested for the standard server only is refused here, and the reverse. A token requested with no `resource` works for both.

The sandbox is a boundary against the code, not against the content. Text from your resources flows back to the agent and can try to influence the next script. What bounds that is the reach of the connection, so give it narrow scopes. See [Safety and permissions](/docs/mcp/safety-and-permissions#content-is-untrusted).
