# Install and run

Prepare a Linux host, install the licensed agent and run it as a service

Source: https://zerocopy.sh/docs/swqos/agent/install-and-run

The ZeroCopy Agent runs beside your application and accepts signed transactions and bundles over local HTTP, QUIC or shared memory IPC. It selects a metro automatically and reconnects when a connection fails. Your application still owns [confirmation and retries](/docs/swqos/confirmation).

<Callout type="warn" title="Protect local access">
The listeners do not authenticate callers. Anyone who can reach them can submit transactions and incur charges on your account. Keep HTTP and QUIC on loopback and restrict access to the IPC socket.
</Callout>

## Prepare the host [#requirements]

### Platform [#platform]

Use Linux on x86_64 with glibc 2.39 or newer and the standard loader at `/lib64/ld-linux-x86-64.so.2`. Ubuntu 24.04, Debian 13 and RHEL 10 have it. Run [`--check`](#check) on each host before relying on it.

### License [#license]

The executable contains your organization's license. Do not put an API key in the configuration. Keep the executable private. If the associated [API key](/docs/api-keys) changes or is revoked, request a replacement through [Requests in the console](https://console.zerocopy.sh).

### Network [#network]

The agent uses IPv4 and needs no public inbound port. Allow these outbound connections:

| Protocol | Destination | Purpose |
| --- | --- | --- |
| DNS | Your resolver | Resolve metro hostnames |
| QUIC on UDP 443 | Metro hosts under `sol.zerocopy.sh` | Connect to SWQoS |
| QUIC on UDP | Validator TPU addresses on varying ports | Send transactions directly from your host |

Validator destinations change. If your firewall allows only metro hosts, the agent can still send through an edge but cannot send directly to validators. Keep the system clock correct for TLS checks. An HTTP proxy cannot carry the agent's UDP connections.

### Host resources [#host]

Use a dedicated account with a writable executable directory and, for IPC, a writable socket directory. These instructions use the user and group `zerocopy`.

IPC busy polling uses one CPU core while any client is connected. Set `ipc_busy_poll = false` for lower idle CPU use; see [busy polling](/docs/swqos/agent/configuration#busy-poll).

## Obtain the executable [#obtain]

Use [Requests in the console](https://console.zerocopy.sh) to ask for your organization's licensed `zerocopy-agent` executable and SHA-256 checksum.

## Create the user and directories [#user]

```sh title="Create the agent user and directories"
sudo useradd --system --user-group --no-create-home --home-dir /opt/zerocopy --shell /usr/sbin/nologin zerocopy
sudo install -d -o zerocopy -g zerocopy -m 0700 /opt/zerocopy
sudo install -d -m 0755 /etc/zerocopy
```

## Install the executable [#executable]

Set `delivered` to the path of the file you received:

```sh title="Install the delivered executable"
delivered=/path/to/zerocopy-agent
sudo install -o zerocopy -g zerocopy -m 0700 "$delivered" /opt/zerocopy/zerocopy-agent
```

### Verify the checksum [#checksum]

Set `expected` to the SHA-256 value ZeroCopy provided, then check the installed file:

```sh title="Check the installed executable"
expected=PASTE_DELIVERED_SHA256
printf '%s  %s\n' "$expected" /opt/zerocopy/zerocopy-agent | sudo sha256sum --check
```

Continue only if the command prints `/opt/zerocopy/zerocopy-agent: OK`. Otherwise, contact support before running the file.

### Keep the executable directory writable [#location]

The `zerocopy` account must be able to write `/opt/zerocopy` for [automatic updates](/docs/swqos/agent/operations#process), including under service sandboxing. If you launch through a symbolic link, the target file's directory must be writable. Updates retain owner access and remove group and other permissions from the executable.

## Create the configuration [#configuration]

Create `/etc/zerocopy/agent.toml` as root and make it readable by `zerocopy`. This example keeps network listeners on loopback and uses an explicit IPC path. See [Configuration](/docs/swqos/agent/configuration) for all options.

```toml title="/etc/zerocopy/agent.toml"
[listen]
http = "127.0.0.1:8080"
quic = "127.0.0.1:4433"
ipc = "/run/zerocopy/agent.sock"
ipc_busy_poll = true
```

### Give IPC clients access [#ipc-access]

The agent creates its IPC socket with mode `0660`, owned by `zerocopy`. Add each application account to the group, then restart the application so its processes pick up the change:

```sh title="Allow an application account to use IPC"
sudo usermod --append --groups zerocopy app-user
```

Replace `app-user` with your application account. HTTP and QUIC clients need no group membership.

## Check startup and connectivity [#check]

### Command arguments [#arguments]

Always pass `--config <path>`. Add `--check` to load the configuration and license, check that an edge answers, print the release number and exit:

```sh title="Check the agent before starting"
sudo -u zerocopy /opt/zerocopy/zerocopy-agent --config /etc/zerocopy/agent.toml --check
```

Success exits with status 0 and prints:

```text title="Passing check"
check passed: release <number>
```

If no edge answers in time, the command exits with status 1. See [check failures](/docs/swqos/agent/operations#check). It opens no local listener, so you can run it while the service is running.

## Run in the foreground [#foreground]

The agent does not create its IPC socket directory. Create it before a terminal run:

```sh title="Run in a terminal"
sudo install -d -o zerocopy -g zerocopy -m 0750 /run/zerocopy
sudo -u zerocopy /opt/zerocopy/zerocopy-agent --config /etc/zerocopy/agent.toml
```

Logs go to standard output. Wait for the listeners to open before connecting a local client. Stop the process with Ctrl-C.

## Run as a systemd service [#service]

This unit runs as `zerocopy`, creates the IPC directory and keeps the executable directory writable for updates. Its sandbox options require systemd 248 or later.

```ini title="/etc/systemd/system/zerocopy-agent.service"
[Unit]
Description=ZeroCopy Agent
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=zerocopy
Group=zerocopy
ExecStart=/opt/zerocopy/zerocopy-agent --config /etc/zerocopy/agent.toml
Restart=on-failure
RestartSec=5
RuntimeDirectory=zerocopy
RuntimeDirectoryMode=0750
UMask=0077

# Automatic updates write the executable's directory.
ProtectSystem=strict
ReadWritePaths=/opt/zerocopy
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
PrivateIPC=yes
PrivateUsers=yes
ProtectProc=invisible
ProcSubset=pid
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectKernelLogs=yes
ProtectControlGroups=yes
ProtectClock=yes
ProtectHostname=yes

NoNewPrivileges=yes
CapabilityBoundingSet=
RestrictSUIDSGID=yes
RestrictNamespaces=yes
RestrictRealtime=yes
LockPersonality=yes
MemoryDenyWriteExecute=yes
RemoveIPC=yes
KeyringMode=private

RestrictAddressFamilies=AF_INET AF_UNIX

SystemCallArchitectures=native
SystemCallFilter=@system-service
SystemCallFilter=~@privileged @resources
SystemCallErrorNumber=EPERM

[Install]
WantedBy=multi-user.target
```

Keep `listen.ipc` under `/run/zerocopy`. The service has a private `/tmp`, so clients cannot reach a socket there. The sandbox allows IPv4 and Unix sockets, not IPv6, and has no capabilities for listening on ports below 1024.

```sh title="Enable and start the service"
sudo systemctl daemon-reload
sudo systemctl enable --now zerocopy-agent
systemctl status zerocopy-agent
journalctl -u zerocopy-agent -f
```

Once listeners open, check local health. Rust and Go use the
[example project](/docs/reference/json-rpc#example-project); TypeScript uses `fetch`.
No API key is needed.

```rust title="src/bin/check_agent_health.rs" tab="Rust" tab-group="language"
use swqos_examples::swqos::Result;

#[tokio::main]
async fn main() -> Result<()> {
    let response = reqwest::get("http://127.0.0.1:8080/health").await?;
    let status = response.status();
    let body = response.text().await?;
    if !status.is_success() {
        return Err(format!("HTTP {status}: {}", body.trim()).into());
    }
    println!("HTTP {status}: {}", body.trim());
    Ok(())
}
```

```go title="check-agent-health/main.go" tab="Go" tab-group="language"
package main

import (
	"fmt"
	"io"
	"log"
	"net/http"
	"strings"
)

func main() {
	if err := run(); err != nil {
		log.Fatal(err)
	}
}

func run() error {
	response, err := http.Get("http://127.0.0.1:8080/health")
	if err != nil {
		return err
	}
	defer response.Body.Close()
	body, err := io.ReadAll(response.Body)
	if err != nil {
		return fmt.Errorf("HTTP %d: %w", response.StatusCode, err)
	}
	message := strings.TrimSpace(string(body))
	if response.StatusCode < 200 || response.StatusCode >= 300 {
		return fmt.Errorf("HTTP %d: %s", response.StatusCode, message)
	}
	fmt.Printf("HTTP %d: %s\n", response.StatusCode, message)
	return nil
}
```

```ts title="check-agent-health.ts" tab="TypeScript" tab-group="language"
const response = await fetch('http://127.0.0.1:8080/health')
const body = (await response.text()).trim()
if (!response.ok) {
  throw new Error(`HTTP ${response.status}: ${body}`)
}
console.log(`HTTP ${response.status}: ${body}`)

export {}
```

```sh title="Check local health" tab="cURL" tab-group="language"
curl --fail-with-body -sS http://127.0.0.1:8080/health
```

HTTP status 200 with `ok` means the agent has an edge connection or current routing information. Status 503 with `unhealthy` means it is not ready. Health does not confirm a transaction's outcome.

### Restrict listening ports [#ports]

On systemd 256 or later, when `systemctl --version` lists `+BPF_FRAMEWORK`, add this drop in file:

```ini title="/etc/systemd/system/zerocopy-agent.service.d/ports.conf"
[Service]
# Match listen.http and listen.quic. Port 0 is for outgoing QUIC sockets.
SocketBindAllow=ipv4:tcp:8080
SocketBindAllow=ipv4:udp:4433
SocketBindAllow=ipv4:udp:0
SocketBindDeny=any
```

```sh title="Apply the port restrictions"
sudo systemctl daemon-reload
sudo systemctl restart zerocopy-agent
```

If you change `listen.http` or `listen.quic`, change the matching line. Otherwise startup fails with `bind <address>: Operation not permitted`. Keep the UDP port 0 rule for outgoing QUIC sockets.

## Stop and restart [#stop]

Use `systemctl stop zerocopy-agent` to stop the service or `systemctl restart zerocopy-agent` to apply configuration changes.

A stop or [automatic update](/docs/swqos/agent/operations#restart) closes local connections. HTTP and QUIC clients must reconnect. IPC clients must open a new session and repeat the handshake.

## Diagnose a failed start [#failures]

A failed start prints `error: <reason>` to standard error, sometimes followed by `caused by: <reason>`, and exits with status 1. Read the service log with `journalctl -u zerocopy-agent` and follow [startup troubleshooting](/docs/swqos/agent/operations#startup).

When the agent is running, connect your application through [local interfaces](/docs/swqos/agent/local-interfaces).
