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

# Code Node

> Run Python as a workflow step — the code handler class and its process object

A code node (`"type": "code"`) runs Python as a deterministic step. It has a single handler class, `code`, so `handler_class` and `process` are never ambiguous.

Use this page when building `nodes` for [Create a Workflow](/api-reference/v1-workflow-generation/create-workflow) or [Update a Workflow](/api-reference/v1-workflow-generation/update-workflow).

Reach for a code node when the work is exact and repeatable — parsing, arithmetic, reshaping data, calling a library. Where the work needs judgement, use an [Agent Node](/api-reference/v1-workflow-generation/agent-node) instead.

## Process Fields

<ParamField body="code" type="string" required>
  The Python source to run.

  Your code reads the node's inputs and returns its outputs; the variable names come from the node's `input_schema` and `output_schema`. See [Variable Schemas](/api-reference/v1-workflow-generation/variable-schemas).
</ParamField>

<ParamField body="description" type="string" required>
  What the code does. Keep it accurate — this is the field most likely to go stale once the code is edited, and it is what teammates read first.
</ParamField>

<ParamField body="objective" type="string">
  What the step is meant to achieve, as distinct from how `code` achieves it. Defaults to an empty string.
</ParamField>

<ParamField body="libraries_used" type="string[]">
  Python packages the code imports. Defaults to empty.

  Only packages available in the Opus Code runtime can be imported — see [Available Packages](/opus-sdk/available-packages).
</ParamField>

<Note>
  For reading and writing files from inside a code node, and the file formats Opus supports, see the [Opus SDK](/opus-sdk/overview).
</Note>

## Example

```json code node theme={null}
{
  "id": "{NODE_ID}",
  "name": "Normalize Invoice Totals",
  "type": "code",
  "handler_class": "code",
  "process": {
    "code": "def run(invoice_lines):\n    total = sum(line['amount'] for line in invoice_lines)\n    return {'total': round(total, 2)}\n",
    "description": "Sums invoice line amounts and rounds the total to two decimal places",
    "objective": "Produce a single reconciled invoice total",
    "libraries_used": []
  }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.