---
name: "code_run"
area: "code"
title: "Run Python or Node.js code"
price: "$0.0001 per started second of run time, at least $0.005 a run ($0.005 for a run under 50 seconds), up to $0.031"
method: "POST"
url: "https://api.conecto.chat/v1/tools/code_run"
mcp_server: "https://api.conecto.chat/mcp/code"
auth: "Authorization: Bearer <conecto_sk_ key>"
docs_url: "https://conecto.chat/tools/code/code_run"
---

# Run Python or Node.js code (`code_run`)

Runs a short Python 3.12 or Node.js 22 program in a fresh sandbox, with store files in /input; files it writes come back to the store.

Run a short program in a fresh sandbox: Python 3.12 (pandas, numpy, scipy, matplotlib, openpyxl, xlsxwriter, pillow, pypdf, python-docx) or Node.js 22 (date-fns, csv-parse, csv-stringify, lodash). Files from the store are in /input (by their names); anything the program writes in its working folder comes back as new files in the store. One CPU, 1 GB of memory, no network (fetch data first with web_read or files_upload). The reply has stdout, stderr (each up to 64 KB), the exit code and the saved files.

Price: $0.0001 per started second of run time, at least $0.005 a run ($0.005 for a run under 50 seconds), up to $0.031. A call that fails costs nothing.

## Use it when

A job needs real computation: sums over a CSV, a chart, reshaping a spreadsheet.

- For rows of a table filtered and sorted, use [rows_query](https://conecto.chat/tools/tables/rows_query.md).
- For a chart for a person to look at, use [view_show](https://conecto.chat/tools/views/view_show.md).

## Say this to your agent

> Take the orders export and work out which fabrics sold best last quarter, with a chart.

## Inputs

| Name | Type | Required | Description | Allowed values | Default |
|---|---|---|---|---|---|
| `language` | string | yes |  | `"python"`, `"node"` |  |
| `code` | string | yes | The whole program. 1 to 200,000 characters. |  |  |
| `files` | array of strings | no | file_ids to put in /input. Up to 10 items. |  |  |
| `stdin` | string | no | Up to 1,048,576 characters. |  |  |
| `timeout_seconds` | integer | no | 1 to 300. |  | `60` |

## Example

Written for Halverson Cycle & Repair, a bike shop with a repair workshop in Portland, Oregon.

MCP: call `code_run` on the MCP server `https://api.conecto.chat/mcp/code` with these arguments:

```json
{
  "language": "python",
  "files": [
    "4e6a8c0e-2a4c-4e8a-9c2e-6a8c0e2a4c7e"
  ],
  "code": "import pandas as pd\n\norders = pd.read_csv(\"/input/orders-q3.csv\")\nby_fabric = orders.groupby(\"fabric\")[\"total\"].sum().sort_values(ascending=False)\nby_fabric.to_csv(\"fabrics-q3.csv\")\nby_fabric.head(8).plot.barh().get_figure().savefig(\"fabrics-q3.png\")\nprint(by_fabric.head(5))"
}
```

REST:

```bash
curl https://api.conecto.chat/v1/tools/code_run \
  -H "Authorization: Bearer $CONECTO_KEY" \
  -H "Content-Type: application/json" \
  -d '{"language": "python", "files": ["4e6a8c0e-2a4c-4e8a-9c2e-6a8c0e2a4c7e"], "code": "import pandas as pd\n\norders = pd.read_csv(\"/input/orders-q3.csv\")\nby_fabric = orders.groupby(\"fabric\")[\"total\"].sum().sort_values(ascending=False)\nby_fabric.to_csv(\"fabrics-q3.csv\")\nby_fabric.head(8).plot.barh().get_figure().savefig(\"fabrics-q3.png\")\nprint(by_fabric.head(5))"}'
```

## Response

```json
{
  "call_id": "5f0c8a2e-3b7d-4c1e-9a64-2d8e1f7b0c93",
  "tool": "code_run",
  "status": "succeeded",
  "replayed": false,
  "cost_usd": "$0.005",
  "balance_usd": "$19.75",
  "result": {
    "exit_code": 0,
    "timed_out": false,
    "duration_ms": 2400,
    "stdout": "fabric\nBoucle Rust    14280\nVelvet Moss    11340\nLinen Sand      6400\nName: total, dtype: int64\n",
    "stderr": "",
    "files": [
      {
        "file_id": "12e74e0e-1ce8-494c-b378-08486a1a9bf1",
        "name": "fabrics-q3.csv",
        "content_type": "text/csv",
        "size": "65 bytes",
        "size_bytes": 65,
        "sha256": "7e62ce9e39088dbade5e32cea77bfaec1fb1c1a78ad63bbbbec04a5df8332710",
        "created_at": "2026-10-14T08:00:00+00:00",
        "download_url": "https://cncto.co/d/12e74e0e-1ce8-494c-b378-08486a1a9bf1?t=eyJmIjoiMTJlNzRlMGUtMWNlOC00OTRjLWIzNzgtMDg0ODZhMWE5YmYxIiwiZXhwIjoxNzkyMDIzMTUzfQ:1xGmbh:r530kLRgRi9orjUJ0sO9zSVOUgbbtH6xdXUWzjRp57g",
        "link_expires_in_hours": 24
      },
      {
        "file_id": "513a788c-0fb6-449b-b290-4f7c14de3170",
        "name": "fabrics-q3.png",
        "content_type": "image/png",
        "size": "1.5 KB",
        "size_bytes": 1487,
        "sha256": "c000989c12dfc6d82675a704e909a7543bdea1fa3a93307a97fb69620e87ffc2",
        "created_at": "2026-10-14T08:00:00+00:00",
        "download_url": "https://cncto.co/d/513a788c-0fb6-449b-b290-4f7c14de3170?t=eyJmIjoiNTEzYTc4OGMtMGZiNi00NDliLWIyOTAtNGY3YzE0ZGUzMTcwIiwiZXhwIjoxNzkyMDIzMTUzfQ:1xGmbh:J4qQ5XS11u7Zt2rhz2K9sIKetkNWsYSD37fAeiER1SA",
        "link_expires_in_hours": 24
      }
    ]
  }
}
```

`result`: exit_code, timed_out, duration_ms, stdout and stderr (each up to 64 KB), and files: the new files in the store with their file_ids and download links.

## Errors

| Code | Status | When | Fix |
|---|---|---|---|
| `invalid_input` | 400 | language is not python or node, the code or stdin is too long, more than 10 files go in, or the sandbox refused the job. | Fix what the message names. |
| `not_found` | 404 | A file_id is not a file in the store. | Find the files with files_list. |
| `too_large` | 413 | The files that go in are over 20 MB together, or a file written is over 25 MB. | Send fewer or smaller files. |
| `storage_full` | 409 | The file store has no room for the files the program wrote. | Delete files with files_delete, or add room with files_add_storage. |
| `not_switched_on` | 503 | Running code is not switched on yet. | Try again later; nothing was charged. |
| `busy` | 503 | The sandbox is busy. | Try again in a minute; nothing was charged. |
| `sandbox_unavailable` | 503 | The sandbox is not available or did not answer. | Try again later; nothing was charged. |

The refusals every tool can give (401 key, 402 balance, 429 limits) are on the errors page: https://conecto.chat/docs/errors.md

## Related
