← All tools
Run Python code
Codecode.run_python
in: anyout: text
Execute Python in a sandboxed runtime.
Pricing
- Price
- 6.25 cr / second
Prices in credits (1 credit = $0.01).
Run Python Code
Execute a Python snippet in an isolated sandbox and return the value of result.
When to use
- Data transformation — reshape, filter, or aggregate structured data before passing it downstream.
- Calculations — run numerical or statistical computations without a separate service.
- Scripted automation — generate or manipulate text, JSON, or binary payloads inline.
Inputs & outputs
| Input modality | Any (named variable bindings via vars) |
| Output modality | Text / JSON (the value of result after execution) |
| Max source length | 50 000 characters |
| Max timeout | 30 seconds |
Parameters
| Param | Required | Description |
|---|---|---|
source | yes | Python source code (1–50 000 chars). Must assign to result. |
timeout_seconds | no | Execution time limit in seconds (1–30). Default: 5 |
Input
| Field | Description |
|---|---|
vars | Dictionary of named bindings injected as local variables before execution. Values can be any JSON-serialisable type. |
Examples
Add 1 to an input variable
{
"type": "code.run_python",
"input": { "vars": { "x": 5 } },
"params": { "source": "result = x + 1", "timeout_seconds": 5 }
}
Parse and summarise JSON
{
"type": "code.run_python",
"input": { "vars": { "data": [1, 2, 3, 4, 5] } },
"params": { "source": "result = {'sum': sum(data), 'count': len(data)}", "timeout_seconds": 5 }
}
Pricing
Billed per second of sandbox execution time (rounded up to the nearest second). See pricing dashboard for current rates.
Related capabilities
code.run_node— execute Node.js code in a sandboxweb.search— retrieve live data to process with this capability
Examples
Add 1 to x
{
"source": "result = x + 1",
"timeout_seconds": 5
}