# Secure an n8n agent workflow

Register an n8n workflow as an SMA agent, lock down the n8n host, and run the heartbeat from a Schedule trigger.

n8n agents hold credentials for many services and call tools from inputs you do not control. Secure the host first, then the workflow.

## Register from the host

Run on the machine or container that runs n8n:

```bash
npx -y securemyagent register --name my-n8n
npx -y securemyagent checkup --upload
```

## Lock the host

```bash
# n8n default port is 5678
ss -ltnp | grep 5678
```

- Bind n8n to localhost and put an authenticating reverse proxy in front.
- Set a strong `N8N_ENCRYPTION_KEY`. It encrypts stored credentials. Back it up.
- Set `N8N_BLOCK_ENV_ACCESS_IN_NODE=true` so workflows cannot read host env vars.
- Keep the Execute Command node disabled unless you need it:

```bash
export NODES_EXCLUDE='["n8n-nodes-base.executeCommand"]'
```

See [fix network exposure](https://securemyagent.ai/articles/fix-network-exposure).

## Lock the workflow

- Give each workflow its own credential with minimum scopes.
- Add a manual approval step before send, delete and payment nodes.
- Pin the version of every MCP Client Tool server.
- Treat webhook input as untrusted. Do not pass it into an AI Agent node that also holds credentials and an HTTP tool. See [prompt-injection exfiltration](https://securemyagent.ai/articles/prompt-injection-exfiltration).

## Heartbeat in n8n

Create a workflow with a Schedule Trigger (every 6 hours) and an HTTP Request node:

- Method: `POST`
- URL: `https://api.securemyagent.ai/v1/heartbeat`
- Authentication: Header Auth. Name `Authorization`. Value `Bearer ` plus your SMA key. Store it as an n8n credential.

Send the key only to `api.securemyagent.ai`. Branch on `whatsNew` and `advisories` in the response.

## Sources

- [OWASP Top 10 for Agentic Applications 2026](https://genai.owasp.org/2025/12/09/owasp-top-10-for-agentic-applications/)
- [OWASP MCP Top 10](https://owasp.org/projects/mcp-top-10)
