---
title: "Self-host n8n in France over MCP, with while.sh"
url: https://while.sh/en/guides/self-host-n8n/
author: "Aloïs Oddon, co-founder of Nextmap"
updated: 2026-11-03
---

# Self-host n8n in France, with its PostgreSQL database, from your AI agent

Self-hosted n8n, with no server to maintain. Connected to while over MCP, your AI agent deploys your instance in France, with its workflows in a PostgreSQL database backed up every day and its webhooks over HTTPS.

## Prerequisites

- A new instance, or your workflows exported from your current n8n.
- Your AI agent: Claude Code, Codex, Cursor or Gemini CLI.

## Step 1: Ask your agent for n8n

> You, to your agent: Connect to while with my account (while.sh/agents), then deploy n8n with its PostgreSQL database.

Your agent adds while's MCP server itself. If it asks you to, restart it. On the first call to while, a page opens in your browser. In Claude Code, if it doesn't open, type /mcp, choose while, then Authenticate. On that page, choose "A new app", then click Authorize.

## Step 2: Create your n8n account

Your agent gives you your instance's address, for example `https://n8n.while.cloud`. Open it right away: the first visitor creates the owner account. You then create your first workflows there.

## What your agent does

n8n doesn't read its database address as a single URL: it expects the host, port, name, user and password in its own variables (source 1). So your agent writes a Dockerfile on the official n8n image, and a small startup script that derives those variables from the database's:

```dockerfile titre="Dockerfile"
FROM docker.io/n8nio/n8n:latest
USER root
COPY --chmod=755 entry.sh /entry.sh
USER 1000:1000
ENTRYPOINT ["/entry.sh"]
```

```shellscript titre="entry.sh"
#!/bin/sh
# Gives n8n while's PostgreSQL database, variable by variable.
set -e
u="${DB_MAIN_URL#*://}"
rest="${u#*@}"
hostport="${rest%%/*}"
db="${rest#*/}"
db="${db%%\?*}"
host="${hostport%%:*}"
port="${hostport##*:}"
[ "$port" = "$hostport" ] && port=5432
export DB_TYPE=postgresdb
export DB_POSTGRESDB_HOST="$host"
export DB_POSTGRESDB_PORT="$port"
export DB_POSTGRESDB_DATABASE="$db"
export DB_POSTGRESDB_USER="$DB_MAIN_USER"
export DB_POSTGRESDB_PASSWORD="$DB_MAIN_PASSWORD"
export N8N_PORT="${PORT:-5678}"
exec /docker-entrypoint.sh "$@"
```

Then while.yaml:

```yaml titre="while.yaml"
apiVersion: while/v1
project: n8n
services:
  - name: n8n
    dockerfile: Dockerfile
    port: 5678
    health:
      path: /healthz
      initial_delay_seconds: 20
    resources:
      cpu: 500m
      memory: 768Mi
    scale:
      min: 1
      max: 1
    sleep: never
    env:
      N8N_ENCRYPTION_KEY: { secret: N8N_ENCRYPTION_KEY }
      N8N_PROXY_HOPS: 1
      N8N_PROTOCOL: https
      N8N_HOST: n8n.while.cloud
      WEBHOOK_URL: https://n8n.while.cloud/
      N8N_EDITOR_BASE_URL: https://n8n.while.cloud/
network:
  egress: all
databases:
  - name: main
```

n8n keeps its workflows, its encrypted credentials and its executions in the PostgreSQL database. It runs as a single instance, always awake, to start its scheduled workflows and receive its webhooks at the public address your agent gives it (source 2). The key that encrypts your credentials is a secret your agent sets in while (source 3). `N8N_PROXY_HOPS` tells n8n it answers behind while's HTTPS entry point, and the `/healthz` route tells while that n8n is ready (source 4).

`egress: all` opens the internet to n8n: its workflows call your tools and your APIs, and n8n reaches its own services, like api.n8n.io. A person in your organization approves that opening on the first deployment.

## Bring over your workflows

> You, to your agent: Import our workflows from our old n8n.

Your agent imports your exported workflows. You enter your credentials again in n8n: they stay encrypted by your key.

## Put n8n on your domain

> You, to your agent: Put n8n on n8n.acme.com.

Your agent declares the domain and updates the webhook address. You add the DNS records it gives you, and the HTTPS certificate follows.

## Put your workflows back the way they were yesterday

> You, to your agent: Restore n8n's database to yesterday at 6 pm.

Your agent prepares the restore, and you approve it: a safety backup is taken first.

## Upgrade to the latest version of n8n

> You, to your agent: Upgrade n8n to the latest version.

Your agent deploys the latest n8n image. If the new version disappoints, it rolls back to the previous one.

## Next steps

- [Restore your database to a precise moment](/en/guides/restore-postgresql/)
- [Put your app on your own domain](/en/guides/custom-domain/)
- [Deploy a Docker container](/en/guides/deploy-docker-container/)

## Sources

1. [n8n, database environment variables](https://docs.n8n.io/deploy/host-n8n/configure-n8n/basic-configuration/use-environment-variables/database), 2026-11-02
2. [n8n, the webhook URL](https://docs.n8n.io/deploy/host-n8n/configure-n8n/basic-configuration/configuration-examples/configure-webhook-urls-with-reverse-proxy), 2026-11-02
3. [n8n, the encryption key](https://docs.n8n.io/deploy/host-n8n/configure-n8n/basic-configuration/configuration-examples/set-a-custom-encryption-key), 2026-11-02
4. [n8n, the health check (/healthz)](https://docs.n8n.io/deploy/host-n8n/keep-n8n-running/monitor-n8n), 2026-11-02

## Questions

### Are my workflows backed up?

Yes: they live in the PostgreSQL database, with their executions, which is backed up every day and can go back to a precise moment.

### Can n8n call my tools and my APIs?

Yes: your agent opens the internet to n8n in while.yaml, and a person in your organization approves that opening.

### What about the files n8n writes to its disk?

They start from scratch when n8n restarts. Your workflows, your encrypted credentials and your executions are in the database.

### Where is my instance hosted?

In France, by Nextmap, a French company.
