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

# code

> Inline transform — aggregate, reshape, derive. The escape hatch when rules and decision tables don't fit.

`code` nodes run a small inline transform against the run context. Used when the logic is too compact to merit a vendor call but too compositional for rules.

## Configuration

```jsonc theme={null}
{
  "id": "cd-aggregate",
  "type": "code",
  "data": {
    "label": "Aggregate AML Results",
    "language": "python",
    "code": "high_risk = sum(1 for r in beneficiary_results if r and r.sanctions_check and r.sanctions_check.match_score >= 80)\nreturn { 'high_risk_count': high_risk, 'total_screened': len(beneficiary_results or []) }",
    "outputVariable": "aml_aggregate",
    "timeout": 2000,
  },
}
```

| Field            | Notes                                                                                                                  |
| ---------------- | ---------------------------------------------------------------------------------------------------------------------- |
| `language`       | `python` in production. Sandbox-restricted.                                                                            |
| `code`           | The transform. Run context is bound in scope (no `input` prefix needed in code; just `data`, the variable names, etc). |
| `outputVariable` | Where the return value lands.                                                                                          |
| `timeout`        | Milliseconds. Defaults small (2s) because code is local.                                                               |

## Sandboxing

The Python sandbox restricts:

* No filesystem access.
* No network calls (use `customApi` for that).
* No imports beyond a whitelist: `math`, `statistics`, `json`, `re`, `datetime`, `decimal`.
* CPU and memory limits enforced.

## When to use code

<Check>
  Aggregation across array variables (`sum`, `len`, `any`, `all`, `max_by`).
</Check>

<Check>
  Reshape arrays into a different schema before passing to AI synthesis.
</Check>

<Check>
  Compute a derived field that's too small for a vendor call (e.g. distance
  between two coordinates).
</Check>

## When NOT to use code

<Warning>
  If the transform is a single comparison or boolean — use `rule` or `condition`
  instead. Code nodes are harder to reason about in a regulator walk-through.
</Warning>

<Warning>
  If the transform calls an external service — use `customApi`. Code nodes can't
  reach the network.
</Warning>
