> For the complete documentation index, see [llms.txt](https://docs.n8n.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.n8n.io/build/code-in-n8n/use-built-in-shortcuts/n8n-metadata.md).

# n8n metadata

Methods for working with n8n metadata.

This includes:

* Access to n8n environment variables for self-hosted n8n.
* Metadata about workflows, executions, and nodes.
* Information about instance [Variables](/build/code-in-n8n/define-custom-variables.md) and [External secrets](/administer/manage-credentials/use-external-secret-stores.md).

{% hint style="info" %}
**Python support**

You can use Python in the Code node. It isn't available in expressions.
{% endhint %}

{% tabs %}
{% tab title="JavaScript" %}

| Method                         | Description                                                                                                                                                                                                                                                                                             | Available in Code node? |
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------: |
| `$env`                         | Contains n8n instance configuration [environment variables](/deploy/host-n8n/configure-n8n/basic-configuration/use-environment-variables.md).                                                                                                                                                           |            ✅            |
| `$execution.customData`        | Set and get custom execution data. Refer to [Custom executions data](/build/understand-workflows/understand-executions/customize-executions-data.md) for more information.                                                                                                                              |            ✅            |
| `$execution.id`                | The unique ID of the current workflow execution.                                                                                                                                                                                                                                                        |            ✅            |
| `$execution.mode`              | Whether the execution was triggered automatically, or by manually running the workflow. Possible values are `test` and `production`.                                                                                                                                                                    |            ✅            |
| `$execution.resumeUrl`         | The webhook URL to call to resume a workflow waiting at a [Wait node](/integrations/builtin/core-nodes/n8n-nodes-base.wait.md).                                                                                                                                                                         |            ✅            |
| `$getWorkflowStaticData(type)` | View an [example](/build/code-in-n8n/cookbook/built-in-methods-and-variables-examples/getworkflowstaticdata.md). Static data doesn't persist when testing workflows. The workflow must be active and called by a trigger or webhook to save static data. This gives access to the static workflow data. |            ✅            |
| `$("<node-name>").isExecuted`  | Check whether a node has already executed.                                                                                                                                                                                                                                                              |            ✅            |
| `$itemIndex`                   | The index of an item in a list of items.                                                                                                                                                                                                                                                                |            ❌            |
| `$nodeVersion`                 | Get the version of the current node.                                                                                                                                                                                                                                                                    |            ✅            |
| `$prevNode.name`               | The name of the node that the current input came from. When using the Merge node, note that `$prevNode` always uses the first input connector.                                                                                                                                                          |            ✅            |
| `$prevNode.outputIndex`        | The index of the output connector that the current input came from. Use this when the previous node had multiple outputs (such as an If or Switch node). When using the Merge node, note that `$prevNode` always uses the first input connector.                                                        |            ✅            |
| `$prevNode.runIndex`           | The run of the previous node that generated the current input. When using the Merge node, note that `$prevNode` always uses the first input connector.                                                                                                                                                  |            ✅            |
| `$runIndex`                    | How many times n8n has executed the current node. Zero-based (the first run is 0, the second is 1, and so on).                                                                                                                                                                                          |            ✅            |
| `$secrets`                     | Contains information about your [External secrets](/administer/manage-credentials/use-external-secret-stores.md) setup.                                                                                                                                                                                 |            ❌            |
| `$vars`                        | Contains the [Variables](/build/code-in-n8n/define-custom-variables.md) available in the active environment.                                                                                                                                                                                            |            ✅            |
| `$version`                     | The node version.                                                                                                                                                                                                                                                                                       |            ❌            |
| `$workflow.active`             | Whether the workflow is active (true) or not (false).                                                                                                                                                                                                                                                   |            ✅            |
| `$workflow.id`                 | The workflow ID.                                                                                                                                                                                                                                                                                        |            ✅            |
| `$workflow.name`               | The workflow name.                                                                                                                                                                                                                                                                                      |            ✅            |
| {% endtab %}                   |                                                                                                                                                                                                                                                                                                         |                         |

{% tab title="Python (native)" %}

| Method       | Description                                                           |
| ------------ | --------------------------------------------------------------------- |
| `_items`     | Contains incoming items in "Run once for all items" mode.             |
| `_item`      | Contains the item being iterated on in "Run once for each item" mode. |
| {% endtab %} |                                                                       |

{% tab title="Python (Pyodide, deprecated)" %}

| Method                         | Description                                                                                                                                                                                                                                                                                             |
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `_env`                         | Contains n8n instance configuration [environment variables](/deploy/host-n8n/configure-n8n/basic-configuration/use-environment-variables.md).                                                                                                                                                           |
| `_execution.customData`        | Set and get custom execution data. Refer to [Custom executions data](/build/understand-workflows/understand-executions/customize-executions-data.md) for more information.                                                                                                                              |
| `_execution.id`                | The unique ID of the current workflow execution.                                                                                                                                                                                                                                                        |
| `_execution.mode`              | Whether the execution was triggered automatically, or by manually running the workflow. Possible values are `test` and `production`.                                                                                                                                                                    |
| `_execution.resumeUrl`         | The webhook URL to call to resume a workflow waiting at a [Wait node](/integrations/builtin/core-nodes/n8n-nodes-base.wait.md).                                                                                                                                                                         |
| `_getWorkflowStaticData(type)` | View an [example](/build/code-in-n8n/cookbook/built-in-methods-and-variables-examples/getworkflowstaticdata.md). Static data doesn't persist when testing workflows. The workflow must be active and called by a trigger or webhook to save static data. This gives access to the static workflow data. |
| `_("<node-name>").isExecuted`  | Check whether a node has already executed.                                                                                                                                                                                                                                                              |
| `_nodeVersion`                 | Get the version of the current node.                                                                                                                                                                                                                                                                    |
| `_prevNode.name`               | The name of the node that the current input came from. When using the Merge node, note that `_prevNode` always uses the first input connector.                                                                                                                                                          |
| `_prevNode.outputIndex`        | The index of the output connector that the current input came from. Use this when the previous node had multiple outputs (such as an If or Switch node). When using the Merge node, note that `_prevNode` always uses the first input connector.                                                        |
| `_prevNode.runIndex`           | The run of the previous node that generated the current input. When using the Merge node, note that `_prevNode` always uses the first input connector.                                                                                                                                                  |
| `_runIndex`                    | How many times n8n has executed the current node. Zero-based (the first run is 0, the second is 1, and so on).                                                                                                                                                                                          |
| `_secrets`                     | Contains information about your [External secrets](/administer/manage-credentials/use-external-secret-stores.md) setup.                                                                                                                                                                                 |
| `_vars`                        | Contains the [Variables](/build/code-in-n8n/define-custom-variables.md) available in the active environment.                                                                                                                                                                                            |
| `_workflow.active`             | Whether the workflow is active (true) or not (false).                                                                                                                                                                                                                                                   |
| `_workflow.id`                 | The workflow ID.                                                                                                                                                                                                                                                                                        |
| `_workflow.name`               | The workflow name.                                                                                                                                                                                                                                                                                      |
| {% endtab %}                   |                                                                                                                                                                                                                                                                                                         |
| {% endtabs %}                  |                                                                                                                                                                                                                                                                                                         |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.n8n.io/build/code-in-n8n/use-built-in-shortcuts/n8n-metadata.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
