Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Container stack secrets — only *.example files are committed
.env
.env.*
*.env
!.env.example
!*.env.example
!.env.*.example
Expand Down
2 changes: 2 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ Applied to: cloudflared, mailflow frontend + backend, n8n runner. `headscale` is
**Containers exempt from `cap_drop`** (do not add):
- `watchtower` — requires Docker socket management
- `authentik worker` — runs as `root` with Docker socket for blueprint management
- `sandbox-runner-1` (web3 n8n stack) — `privileged: true` Docker-in-Docker that runs n8n Assistant's sandboxes;
`no-new-privileges` would be inherited by the sandboxes it starts. Never publish its ports
- Any init container whose sole job is `chown` (needs `CAP_CHOWN`; dropping all caps breaks it)
- **All data store images** (PostgreSQL, MySQL, Redis, KeyDB, Valkey, OpenSearch, Meilisearch) — their entrypoints start as `root` and use `gosu` to drop to the database user, which requires `CAP_SETUID`/`CAP_SETGID`. Both `cap_drop: [ALL]` and `no-new-privileges:true` break this pattern and prevent the container from starting.

Expand Down
18 changes: 18 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@
"groupName": "n8n",
"separateMajorMinor": false
},
{
"description": "Group the n8n sandbox service images in one PR: the API, runner and sandbox images ship as one release and are only supported together.",
"matchDatasources": ["docker"],
"matchPackageNames": [
"ghcr.io/n8n-io/n8n-sandbox-service-api",
"ghcr.io/n8n-io/n8n-sandbox-service-runner-dind",
"ghcr.io/n8n-io/n8n-sandbox-service-sandbox"
],
"groupName": "n8n sandbox service",
"separateMajorMinor": false
},
{
"matchDatasources": ["terraform-provider"],
"registryUrls": ["https://registry.opentofu.org"]
Expand Down Expand Up @@ -110,6 +121,13 @@
"depNameTemplate": "opentofu/opentofu",
"packageNameTemplate": "opentofu/opentofu",
"versioningTemplate": "semver"
},
{
"customType": "regex",
"description": "Track the sandbox image the n8n sandbox runner pulls. It is set through SANDBOX_RUNNER_DOCKER_SANDBOX_IMAGE, which the docker-compose manager does not read, and must stay on the same release as the sandbox API and runner images.",
"managerFilePatterns": ["/(^|/)docker-compose\\.ya?ml$/"],
"matchStrings": ["SANDBOX_RUNNER_DOCKER_SANDBOX_IMAGE:\\s*(?<depName>[^:\\s]+):(?<currentValue>[^@\\s]+)@(?<currentDigest>sha256:[a-f0-9]+)"],
"datasourceTemplate": "docker"
}
],
"hostRules": [
Expand Down
16 changes: 16 additions & 0 deletions web3/containers/n8n/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,19 @@ N8N_NATIVE_PYTHON_RUNNER=true

# Concurrency
N8N_CONCURRENCY_PRODUCTION_LIMIT=20

# n8n Assistant - self-hosted sandbox (sandbox-api / sandbox-runner-1 services)
N8N_INSTANCE_AI_SANDBOX_ENABLED=true
N8N_INSTANCE_AI_SANDBOX_PROVIDER=n8n-sandbox
N8N_SANDBOX_SERVICE_URL=http://sandbox-api:8080
# Must be one of SANDBOX_API_KEYS in .sandbox-api.env
N8N_SANDBOX_SERVICE_API_KEY=

# n8n Assistant - model (provider/model). The key can also be set in the
# editor's AI settings instead.
# N8N_INSTANCE_AI_MODEL=anthropic/claude-opus-4-8
N8N_INSTANCE_AI_MODEL_API_KEY=
# Optional base URL for the model provider, e.g. a gateway or proxy. The
# provider prefix above picks the API spoken there (anthropic, openai); a bare
# model name means a custom OpenAI-compatible endpoint.
# N8N_INSTANCE_AI_MODEL_URL=
7 changes: 7 additions & 0 deletions web3/containers/n8n/.sandbox-api.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Keys n8n uses to call the sandbox API (comma-separated). n8n's
# N8N_SANDBOX_SERVICE_API_KEY in .env must be one of them.
SANDBOX_API_KEYS=
# Must match SANDBOX_RUNNER_REGISTRATION_TOKEN in .sandbox-runner.env
SANDBOX_API_RUNNER_REGISTRATION_TOKEN=
# Must be one of SANDBOX_RUNNER_API_KEYS in .sandbox-runner.env
SANDBOX_API_RUNNER_API_KEY=
5 changes: 5 additions & 0 deletions web3/containers/n8n/.sandbox-runner.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Must match SANDBOX_API_RUNNER_REGISTRATION_TOKEN in .sandbox-api.env
SANDBOX_RUNNER_REGISTRATION_TOKEN=
# Keys the sandbox API uses to call this runner (comma-separated); must
# include SANDBOX_API_RUNNER_API_KEY from .sandbox-api.env
SANDBOX_RUNNER_API_KEYS=
99 changes: 99 additions & 0 deletions web3/containers/n8n/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,109 @@ services:
networks:
- n8n

# n8n Assistant sandbox (self-hosted n8n-sandbox provider). The API, runner and
# sandbox images ship as one release and are only supported together: keep all
# three tags in step. The certificates are issued for the service names
# sandbox-api and sandbox-runner-1, so do not rename these services.
sandbox-certs:
image: ghcr.io/n8n-io/n8n-sandbox-service-api:1.14.0@sha256:bca5e76d828306c0e319e946cfd0f4ff22941ce9e61bb5fcc118a1cce59c180d # yamllint disable-line rule:line-length
user: "0:0"
restart: "no"
cap_drop:
- ALL
cap_add:
- CHOWN
security_opt:
- no-new-privileges:true
read_only: true
tmpfs:
- /tmp
network_mode: none
# Generates the mTLS material once (it skips when the volume already holds a
# full set). Keys stay 0600: the API's are handed to its user, the runner
# reads its own as root.
entrypoint: ["sh", "-c"]
command:
- >-
bootstrap-mtls.sh --out-dir /tls --api-san sandbox-api
--control-san-prefix sandbox-runner --runners 1 &&
chown -R sandbox-api:sandbox-api /tls/api
volumes:
- sandbox_tls:/tls

sandbox-api:
image: ghcr.io/n8n-io/n8n-sandbox-service-api:1.14.0@sha256:bca5e76d828306c0e319e946cfd0f4ff22941ce9e61bb5fcc118a1cce59c180d # yamllint disable-line rule:line-length
restart: unless-stopped
cap_drop:
- ALL
security_opt:
- no-new-privileges:true
depends_on:
sandbox-certs:
condition: service_completed_successfully
env_file:
- .sandbox-api.env
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
environment:
SANDBOX_API_GRPC_TLS_CERT_FILE: /tls/api/grpc-server.crt
SANDBOX_API_GRPC_TLS_KEY_FILE: /tls/api/grpc-server.key
SANDBOX_API_GRPC_TLS_CLIENT_CA_FILE: /tls/api/ca.crt
SANDBOX_API_RUNNER_CONTROL_GRPC_TLS_CA_FILE: /tls/api/ca.crt
SANDBOX_API_RUNNER_CONTROL_GRPC_TLS_CERT_FILE: /tls/api/control-grpc-api-client.crt
SANDBOX_API_RUNNER_CONTROL_GRPC_TLS_KEY_FILE: /tls/api/control-grpc-api-client.key
SANDBOX_API_RUNNER_CONTROL_GRPC_TLS_SERVER_NAME: sandbox-runner-1
volumes:
- sandbox_tls:/tls:ro
- sandbox_api_data:/var/lib/n8n-sandbox-api
healthcheck:
test: ["CMD", "wget", "-qO-", "http://localhost:8080/healthz"]
interval: 10s
timeout: 3s
retries: 5
start_period: 10s
# No published ports: n8n reaches it as http://sandbox-api:8080.
networks:
- n8n

# Privileged Docker-in-Docker: equivalent to root on the host. Never publish
# its ports. Exempt from cap_drop/no-new-privileges (see CLAUDE.md).
sandbox-runner-1:
image: ghcr.io/n8n-io/n8n-sandbox-service-runner-dind:1.14.0@sha256:e7ffb6dbfaa831861fe03b66ff9ae7d4f8c8541fa60738c58c12c059c806f6a4 # yamllint disable-line rule:line-length
restart: unless-stopped
privileged: true
depends_on:
sandbox-api:
condition: service_healthy
env_file:
- .sandbox-runner.env
environment:
SANDBOX_RUNNER_ID: runner-1
SANDBOX_RUNNER_API_GRPC_ADDR: sandbox-api:9090
SANDBOX_RUNNER_HTTP_BASE_URL: https://sandbox-runner-1:8080
SANDBOX_RUNNER_CONTROL_GRPC_LISTEN_ADDR: ":9091"
SANDBOX_RUNNER_CONTROL_GRPC_ADVERTISE_ADDR: sandbox-runner-1:9091
SANDBOX_RUNNER_DOCKER_SANDBOX_IMAGE: ghcr.io/n8n-io/n8n-sandbox-service-sandbox:1.14.0@sha256:f138f039255b60802778beb274ece7b72bdd30b0ec22c943136736866f61dccb # yamllint disable-line rule:line-length
SANDBOX_RUNNER_REGISTRATION_GRPC_CA_FILE: /tls/runner/ca.crt
SANDBOX_RUNNER_REGISTRATION_GRPC_CERT_FILE: /tls/runner/grpc-client.crt
SANDBOX_RUNNER_REGISTRATION_GRPC_KEY_FILE: /tls/runner/grpc-client.key
SANDBOX_RUNNER_REGISTRATION_GRPC_SERVER_NAME: sandbox-api
SANDBOX_RUNNER_CONTROL_GRPC_TLS_CERT_FILE: /tls/runner/control-grpc-server.crt
SANDBOX_RUNNER_CONTROL_GRPC_TLS_KEY_FILE: /tls/runner/control-grpc-server.key
SANDBOX_RUNNER_CONTROL_GRPC_TLS_CLIENT_CA_FILE: /tls/runner/ca.crt
volumes:
- sandbox_tls:/tls:ro
# Inner dockerd storage: keeps the pulled sandbox image across restarts
# instead of leaving an anonymous volume behind on every recreate.
- sandbox_runner_docker:/var/lib/docker
networks:
- n8n

volumes:
postgres:
valkey:
n8n_data:
sandbox_tls:
sandbox_api_data:
sandbox_runner_docker:
networks:
n8n:
app-infra:
Expand Down