SAFEVEIL
Safeveil documentation

Run your own gateway.Give every agent a boundary.

Everything you need to deploy a Safeveil gateway, connect your devices, create allowlisted tunnels for AI agents, and run the service responsibly.

i
Self-hosted software, not a hosted VPN service.

A tunnel exists only after you install the gateway on a Linux server you control. Safeveil is built on WireGuard and standard Linux tools but has not had an independent security audit yet. Read Security before you offer it to people you don't know.

01 / Overview

What Safeveil is.

Safeveil is self-hosted VPN gateway software. You install it on a Linux server, and it turns that server into a WireGuard gateway with a small control API. A web console manages who can connect: people's devices, and AI agents that should only reach specific services.

Your server01

Gateway

A WireGuard interface, the control API, a policy DNS resolver for agent tunnels and an nftables rule set. Installed by one script on Debian 12 or Ubuntu 24.04.

Any browser02

Console

A static web app that manages a gateway over HTTPS. It also has a preview mode that runs entirely in the browser, so you can try it before deploying anything.

WireGuard apps03

Device access

Standard WireGuard configurations for the official apps on Windows, macOS, iOS, Android and Linux. Device traffic is never logged.

New04

Agent tunnels

WireGuard access for AI agents that can only reach allowlisted domains, expires on its own, and keeps an activity log.

It isOne WireGuard gateway per server, managed from a console you control. Traffic goes from your device to your gateway, then to the internet.
It isn'tA hosted VPN subscription, a multi-hop or peer-to-peer network, or an anonymity tool. The exit address belongs to your server, and your hosting provider can see the gateway's traffic.
02 / Architecture

Control path and data path.

Two separate paths keep management and traffic apart. The console only ever talks to the control API; VPN traffic only ever flows through WireGuard.

Device or agentOfficial WireGuard client or wg-quick
→
Your gatewayWireGuard on UDP 51820, NAT to the public interface, agent rules in nftables
→
InternetSites see the gateway's IP address

The console reaches the gateway at https://your-domain/api/. nginx terminates TLS and forwards to the API, which listens on 127.0.0.1:8787 only.

Control path

Browser → HTTPS → nginx → control API. Every request except the health check needs the admin bearer token. The API changes WireGuard peers, firewall sets and the peer database.

Data path

Device → encrypted WireGuard tunnel → gateway → internet. The console, the website and Vercel never carry VPN traffic.

03 / Deploy

Deploy to a clean server.

Requirements

Debian 12 or Ubuntu 24.04 (Ubuntu 22.04 needs Node.js 18 or newer installed first)
A public IPv4 address and root access
A DNS A record pointing your domain at the server
Ports 80/tcp, 443/tcp and 51820/udp reachable from the internet

Run the installer

Copy this repository to the server, then run the installer as root from the repository folder. Use the two-letter country code of the server's location as the location ID; it must match an entry in dist/locations.json.

export UNTRACE_DOMAIN="vpn.example.com"
export UNTRACE_ADMIN_EMAIL="admin@example.com"
export UNTRACE_ADMIN_TOKEN="$(openssl rand -base64 48)"
export UNTRACE_LOCATION_ID="de"
export UNTRACE_LOCATION_NAME="Germany · Frankfurt"
echo "$UNTRACE_ADMIN_TOKEN"   # store this in a password manager now

sudo --preserve-env=UNTRACE_DOMAIN,UNTRACE_ADMIN_EMAIL,UNTRACE_ADMIN_TOKEN,UNTRACE_LOCATION_ID,UNTRACE_LOCATION_NAME \
  bash gateway/bootstrap.sh

What the installer does

Installs packages

WireGuard, nftables, nginx, certbot and Node.js from the distribution's repositories.

Creates the tunnel interface

Generates the server key once, writes wg0 on 10.70.0.1/24, and enables IPv4 forwarding and NAT.

Starts the control service

Writes /etc/untrace/control.env (readable by root only) and starts untrace-control, which runs the API and the agent policy resolver.

Publishes the console over HTTPS

Copies the website to nginx, requests a Let's Encrypt certificate and redirects HTTP to HTTPS. If ufw is active, it opens the required ports and DNS on wg0.

Keep the admin token safe

The installer never prints the token. Anyone with it can create and revoke access. Don't put it in source control, screenshots or support messages.

04 / Devices

Connect a device.

Connect the console

Open https://vpn.example.com/console.html, choose the gateway's location, switch to Live gateway, and enter the gateway URL and admin token.

Add the device

Select + Device and give it a name. The gateway generates a key pair and returns a configuration with the private key. It is shown once.

Import it

Download the .conf file and import it into the official WireGuard app, or scan it from another device. Turn the tunnel on.

Revoke when needed

Revoke removes the key from the live interface and the database at once. The configuration stops working immediately.

Device configurations use the DNS servers from UNTRACE_DNS (Cloudflare by default) and route all traffic through the tunnel. IPv6 is routed into the tunnel and dropped, so it can't leak around it, but the gateway doesn't provide IPv6 internet access.

05 / Agent tunnels

Agent tunnels.

An agent tunnel is a WireGuard peer for an AI agent or automated job. It has three rules the gateway enforces: an allowlist of domains, an expiry time, and an activity log. The goal is to limit what an agent can reach even if it is tricked by content it reads (prompt injection) or misbehaves.

Create one

Open the dialog

In the console, select + Agent tunnel, name it, and list the domains it needs, one per line. Presets add the usual hosts for GitHub, PyPI, npm, the Anthropic API and the OpenAI API.

Choose an expiry

From 5 minutes to 7 days. Pick the shortest time the job needs.

Start the tunnel where the agent runs

Copy the configuration to that machine or container and run sudo wg-quick up ./research-agent.conf. Leave the DNS line unchanged: it points at the gateway's policy resolver.

For the strongest isolation, run the agent in its own container or virtual machine with the tunnel as its only route, so nothing else on the host shares it.

How enforcement works

Layer 1Policy resolver

Agent configurations use 10.70.0.1 as their DNS server. The gateway answers only for allowlisted names and returns NXDOMAIN for everything else. Blocked lookups never leave the gateway, which also stops data from being smuggled out inside DNS queries.

Layer 2Kernel firewall

Each address the resolver returns is added to an nftables set for that agent only. New connections from the agent to any other address are dropped, so connecting to a raw IP address doesn't work either.

  • Allowed addresses stay open for the record's DNS lifetime, clamped between 5 minutes and 1 hour, and are refreshed on each lookup.
  • Connections that are already open continue until they close, even after an allowlist change.
  • IPv6 (AAAA) and HTTPS/SVCB lookups get empty answers, because IPv6 isn't routed and those records can carry address hints.
  • The resolver only answers agent tunnels. Other sources get REFUSED, so it is never an open resolver.

Allowlist rules

EntryMatches
api.github.comExactly api.github.com. Not github.com and not other subdomains.
*.pypi.orgAny subdomain, such as upload.pypi.org. Not pypi.org itself; add it separately if needed.
https://pypi.org/simple/Pasted URLs are reduced to the host name, pypi.org.
203.0.113.7Rejected. Allowlists accept domain names only.

An allowlist can hold up to 64 entries. Edit it at any time from the console or with PUT /api/peers/:id/allowlist. Saving clears the agent's previously resolved addresses, so removed domains stop working for new connections right away.

Expiry

When a tunnel expires, the resolver stops answering it immediately, and within 15 seconds the gateway removes its WireGuard key, clears its firewall entries and deletes its activity log. Expired tunnels are also cleaned up when the service restarts.

Activity log

For agent tunnels only, the gateway records each domain lookup with its result and the addresses returned, plus allowlist changes. Repeated identical lookups within a minute are combined into one entry. The last 500 entries are kept in /var/lib/untrace/activity/. The console also lists blocked direct-IP connections from the last hour, read live from the firewall.

Limits to know
  • Enforcement works on domain names and IP addresses, not on the content of requests. An agent can still send data to a service you allowed, such as a repository or an API.
  • Some providers serve many sites from shared addresses. A site that shares an IP address with an allowed domain may be reachable while that address is allowed.
  • Pair agent tunnels with narrowly scoped API keys, short expiry times and short allowlists.
06 / Domain check

Check a link first.

Domain check is a separate tool at check.html. Paste any link or domain, and Safeveil's agent runs a security check and gives a score from 0 to 100 with a verdict: Looks safe, Be careful or Likely dangerous. A safe result can be sent straight to a new agent tunnel's allowlist.

CheckWhat it looks for
LookalikeImitations of about 40 well-known brands: swapped characters (g1thub), near-miss spellings, brand names with words like "login" or "verify", foreign alphabets, and a brand placed in front of another domain (github.com.account-check.io).
Link structureHidden credentials (user@host), raw IP addresses, plain http, unusual ports, very long or deeply nested names.
Domain endingEndings that are often used for throwaway sites.
DNSWhether the domain exists, its public addresses, and mail setup (SPF and DMARC). Addresses in private networks are refused.
Domain ageThe registration date from RDAP. Domains younger than 30 days fail; most phishing domains are brand new.
CertificateA trusted TLS certificate that matches the domain, its issuer and days until expiry.
Headers and redirectsFive common security headers, and whether the site immediately sends visitors to a different domain.

Use it from code

# On the website (no token; 20 checks a minute per address)
curl "https://safeveil.pro/api/check?url=g1thub-login.com"

# On your gateway, for agents (admin token required)
curl -X POST https://vpn.example.com/api/check \
  -H "Authorization: Bearer $UNTRACE_ADMIN_TOKEN" \
  -H "Content-Type: application/json" -d '{"url":"https://example.com/login"}'

Both return the same JSON report: score, verdict, summary and a checks list where each entry has a status of pass, warn, fail or info.

Limits and privacy
  • These are automated, heuristic checks, not a guarantee. A site can pass every check and still be malicious, and the brand list is not exhaustive.
  • The check doesn't use paid reputation feeds or blocklists.
  • Checking a link makes requests to that site and to public registries from Safeveil's servers (or your gateway), never from your device. Nothing you check is stored.
  • Safeveil never connects to private or reserved network addresses, and never follows redirects. It only reports where they go.
07 / Locations

Add country gateways.

Each gateway serves one exit location. To offer several countries, deploy one server per country, each with its own domain and a unique UNTRACE_LOCATION_ID. Then mark it live in dist/locations.json and redeploy the website:

{"id":"de","country":"Germany","flag":"🇩🇪","city":"Frankfurt",
 "region":"Europe, Middle East & Africa",
 "available":true,"controlUrl":"https://de.vpn.example.com"}

The locations page then shows the country as deployed, and the console fills in the gateway URL automatically. The console refuses to connect if a gateway reports a different location from the one selected.

08 / Console

Using the console.

Preview modeRuns in the browser only. Devices and agent tunnels are saved in local storage and produce placeholder configurations that can't connect to anything.
Live modeTalks to a deployed gateway. Peers, handshakes and expiry times refresh every 20 seconds.
Token storageThe admin token is kept in session storage for the current tab and sent only to the gateway URL you entered. The gateway URL is remembered in local storage.
Where to open itThe installer serves the console from the gateway itself at /console.html, which works with no extra setup. To use a console hosted elsewhere, such as on Vercel, set UNTRACE_ALLOWED_ORIGIN on the gateway to that site's exact origin.
09 / API

Control API reference.

All endpoints are under /api/ and return JSON. Send the admin token as Authorization: Bearer <token> on every request except /api/health.

EndpointDescription
GET /api/healthService status, location and supported features. No token needed.
GET /api/statusInterface, endpoint, and every peer with its latest handshake and transfer counters.
GET /api/peersSaved peers without live WireGuard data.
POST /api/peersCreate a device or agent tunnel. Returns the client configuration once.
DELETE /api/peers/:idRevoke a peer immediately.
PUT /api/peers/:id/allowlistReplace an agent tunnel's allowlist.
GET /api/peers/:id/activityAn agent tunnel's activity log and blocked direct connections.
POST /api/checkRun a domain check on a link. See Domain check.

Create an agent tunnel

curl -X POST https://vpn.example.com/api/peers \
  -H "Authorization: Bearer $UNTRACE_ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name":"research-agent","type":"agent",
       "allowlist":["api.github.com","*.pypi.org"],
       "expiresInMinutes":60}'

Response (201)

{
  "peer": {
    "id": "4f6c…", "name": "research-agent", "type": "agent",
    "address": "10.70.0.12", "allowlist": ["api.github.com", "*.pypi.org"],
    "expiresAt": "2026-11-08T16:02:11.000Z", …
  },
  "clientConfig": "[Interface]\nPrivateKey = …\nDNS = 10.70.0.1\n…",
  "notice": "This configuration contains the private key and is returned only once."
}

type is "device" (default) or "agent". For agents, allowlist is required and expiresInMinutes must be from 5 to 10080 (default 60). Errors return {"error": "…"} with status 400 (invalid input), 401 (missing or wrong token), 404, 409 (duplicate name, wrong location or full subnet), 413 or 429 (more than 90 requests a minute from one address).

10 / Configuration

Gateway settings.

The installer writes these to /etc/untrace/control.env. Restart untrace-control after changing them.

VariableDefaultPurpose
UNTRACE_ADMIN_TOKENrequiredBearer token for the API, at least 32 characters.
UNTRACE_WG_ENDPOINTrequiredPublic host:port written into client configurations.
UNTRACE_LOCATION_IDcustomLocation code the console checks before connecting.
UNTRACE_LOCATION_NAMEPrivate gatewayHuman-readable location name.
UNTRACE_WG_SUBNET_PREFIX10.70.0Tunnel subnet. Peers get addresses .2 to .254.
UNTRACE_DNS1.1.1.1, 1.0.0.1DNS servers for device configurations.
UNTRACE_ALLOWED_ORIGINyour siteThe one browser origin allowed to call the API (CORS).
UNTRACE_AGENT_ENFORCEMENT1Runs the policy resolver and nftables rules. Set to 0 only for testing.
UNTRACE_AGENT_DNS_BIND10.70.0.1Address the policy resolver listens on, inside the tunnel.
UNTRACE_AGENT_UPSTREAM_DNS1.1.1.1, 1.0.0.1Resolvers the gateway asks on behalf of agents. IP addresses only.
UNTRACE_ACTIVITY_DIR/var/lib/untrace/activityWhere agent activity logs are kept.
UNTRACE_PEER_DB/var/lib/untrace/peers.jsonPeer database.
UNTRACE_DRY_RUN0Set to 1 to exercise the API without touching WireGuard or the firewall.
11 / Data

What's stored.

Device peersName, tunnel address, public key, location and creation time. No traffic, DNS or connection logs.
Agent tunnelsThe same, plus the allowlist, expiry time and activity log. Everything is deleted when the tunnel is revoked or expires.
Private keysGenerated during creation, returned once in the configuration, and never written to disk.
WireGuardKeeps the latest handshake time and transfer counters in memory, which the console shows. They reset when the interface restarts.
Web servernginx keeps standard access logs of requests to the website and API, not of VPN traffic. Rotate or turn them off to match your own policy.
BrowserThe console stores your selected location and gateway URL in local storage, the admin token in session storage, and preview peers in local storage.
12 / Operations

Run and maintain.

sudo systemctl status untrace-control wg-quick@wg0
sudo journalctl -u untrace-control --since today
sudo wg show wg0
sudo nft list table inet safeveil_agents    # agent rules and sets

Upgrade

Pull the new version of the repository and run the installer again with the same variables. The server key, peer database and activity logs are kept, and existing configurations keep working.

Back up

/etc/wireguard/server_private.key, /var/lib/untrace/peers.json and /etc/untrace/control.env. Store backups encrypted; they contain the server's private key and the admin token.

Test

# Unit and API tests (no root needed)
node --test gateway/tests/*.test.mjs

# Real-kernel firewall test in a throwaway network namespace
sudo gateway/tests/run-netns-test.sh

# Run the API locally without WireGuard
UNTRACE_DRY_RUN=1 UNTRACE_ADMIN_TOKEN="development-token-with-at-least-32-chars" \
UNTRACE_WG_ENDPOINT="localhost:51820" UNTRACE_PEER_DB="./work/peers.json" \
node gateway/bin/untrace-api.mjs

Dry-run mode stores agent tunnels but doesn't enforce them, and its keys are synthetic. Never import a dry-run configuration into a real client.

13 / Security

Security model.

In place

WireGuard for all tunnel encryption
API bound to localhost, reachable only through HTTPS
32+ character admin token, compared in constant time
90 requests per minute per address on the API
Private keys returned once and never stored
Strict security headers on every API response
systemd sandboxing: read-only system, private temp, no new privileges
Agent tunnels enforced by both the resolver and the kernel firewall

Before you serve people you don't know

  • Replace the single admin token with real sign-in and per-user permissions.
  • Rotate the admin token regularly and whenever someone leaves.
  • Add monitoring and alerts for the service, certificate expiry and disk space.
  • Decide on a logging policy, including nginx, and check the laws where your server is hosted.
  • Write terms of use and a way to handle abuse reports.
  • Get an independent security review of the gateway and your server setup.