# Run it offline

URL: https://docs.hanzo.ai/docs/guides/private-ai/offline

> Move a model to a machine with no network, serve it there, back it up, and prove it works with every interface but loopback gone.

Start with [Private AI on your own machine](https://docs.hanzo.ai/docs/guides/private-ai). This page
takes the same setup off the network.

## The rule

Two variables and one flag keep everything on the machine:

```bash
export HANZO_TELEMETRY=0     # the CLI sends no usage events
export HF_HUB_OFFLINE=1      # the engine reads the model cache only
hanzo engine serve zen-nano -- --serve-ip 127.0.0.1
```

With all three, the CLI and the engine made no outbound connection in our test,
and the server listened on loopback only.

## Move a model to an offline machine

A model is one folder in the Hugging Face cache. Copying that folder is the whole
"offline bundle".

**On a machine with network**, after `hanzo pull zen-nano`:

```bash
tar -C ~/.cache/huggingface/hub -czf zen-nano-bundle.tar.gz models--zenlm--zen-nano-0.6b
```

The archive for `zen-nano` is about 5.3 GiB. If you set `HF_HUB_CACHE` or
`HF_HOME`, use that folder in place of `~/.cache/huggingface/hub`, here and below.

**On the offline machine**, the CLI and engine must already be installed. While
it is still online, run `npm i -g hanzo`, restore the bundle as below, and start
`hanzo engine serve zen-nano -- --serve-ip 127.0.0.1` once, so the engine binary
is downloaded. Then take it offline.

```bash
mkdir -p ~/.cache/huggingface/hub
tar -C ~/.cache/huggingface/hub -xzf zen-nano-bundle.tar.gz
hanzo engine list
```

Then serve it with the rule above.

## Back up and restore

The same two `tar` commands are the backup and the restore. The model cache holds
the only files this setup needs. The engine wrote no conversation or other data
to disk in our test, so there is nothing else to back up.

## Update a model

Connect, then run `hanzo pull zen-nano` again. It looks up the model's current
revision and, if that revision is new, downloads the whole model again (about
6 GiB for `zen-nano`) into a new folder next to the old one, then points the cache
at it. The old folder stays until you delete it. Make a new bundle afterwards if
you move models by archive.

## Prove it works with no network

On Linux, `unshare -n` runs a command in a network namespace that has no
interfaces except a loopback that starts down. A script run that way cannot
reach any other machine, so if the model answers, it answered offline.

Save this as `offline-check.sh`:

```bash
#!/bin/sh
python3 - <<'EOF'
import fcntl, socket, struct
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
ifr = struct.pack('16sH14s', b'lo', 0, b'\0' * 14)
flags = struct.unpack('16sH14s', fcntl.ioctl(s, 0x8913, ifr))[1]
fcntl.ioctl(s, 0x8914, struct.pack('16sH14s', b'lo', flags | 1, b'\0' * 14))
print("interfaces:", [n for _, n in socket.if_nameindex()])
EOF
export HANZO_TELEMETRY=0 HF_HUB_OFFLINE=1
hanzo engine serve zen-nano -- --serve-ip 127.0.0.1 > serve.log 2>&1 &
for i in $(seq 1 180); do curl -s 127.0.0.1:1234/v1/models > /dev/null && break; sleep 2; done
curl -s 127.0.0.1:1234/v1/chat/completions -H 'Content-Type: application/json' \
  -d '{"model":"zenlm/zen-nano-0.6b","messages":[{"role":"user","content":"What is 2+2?"}],"max_tokens":60}'
echo
curl -s -m 5 https://huggingface.co > /dev/null && echo "network: REACHABLE" || echo "network: none"
pkill -f 'hanzoai --port'
```

The Python block brings loopback up, so the script needs no extra tools. Run it:

```bash
sudo env "HOME=$HOME" "PATH=$PATH" unshare -n sh offline-check.sh
```

`sudo` normally resets `HOME` and `PATH`. Passing yours keeps the engine on
your model cache and `hanzo` on the path.

You should see `interfaces: ['lo']`, a chat reply, and `network: none`.

macOS has no `unshare`. There, turn off Wi-Fi and unplug Ethernet, then run the
`curl` commands from the quickstart.

## Troubleshooting

| You see                                                                                                                             | It means                                                            | Do                                                                                                      |
| ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| `Error: engine not found. Set HANZO_ENGINE_BIN=...`                                                                                 | `hanzo` was installed without npm, so nothing downloaded the engine | `npm i -g hanzo`, and run one `hanzo engine serve` while online                                         |
| `` `HF_HUB_OFFLINE` is set and no local Hugging Face cache was found for `zenlm/zen-nano-0.6b` `` followed by `missing config.json` | The model is not in this user's cache                               | `hanzo engine list`; restore the bundle into `~/.cache/huggingface/hub` of the user who runs the engine |
| `error: unexpected argument '--host' found`                                                                                         | You used the flags of the source-built engine                       | Use `-- --serve-ip 127.0.0.1`                                                                           |
| `WARN hanzo_server: hanzo-server is deprecated`                                                                                     | A warning printed by the released engine binary                     | Nothing; serving still works                                                                            |
| `lsof` shows `*:1234`                                                                                                               | `--serve-ip 127.0.0.1` is missing                                   | Stop it and start again with the flag                                                                   |

## What was checked

On 2026-11-29, on Linux x86-64 with 4 CPU cores and 16 GB RAM, with the same
builds as the [quickstart's checks](https://docs.hanzo.ai/docs/guides/private-ai#what-was-checked):

| Claim                                                                  | How it was checked                                                                                                                       |
| ---------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| A cached model serves and answers with no network                      | `unshare -n`: interfaces `['lo']`, `/v1/chat/completions` replied "2 + 2 = 4.", `huggingface.co` unreachable                             |
| The `tar` bundle restores into an empty home and serves offline        | Archived, extracted into a new home, `hanzo engine list` showed the model, served inside `unshare -n`                                    |
| With the rule, no outbound connection                                  | A logging proxy recorded none while serving; the default command recorded `CONNECT api.hanzo.ai:443`                                     |
| Error messages above                                                   | Copied from real runs: an empty cache with `HF_HUB_OFFLINE=1`, and `hanzo` with no engine on `PATH`                                      |
| `hanzo pull` downloads the current revision into a new snapshot folder | Read: `cli: src/commands/engine.rs` `pull_native_hf` writes `snapshots/<sha>` and `refs/main`. Not re-run against a newer revision       |
| `sudo env "HOME=$HOME" "PATH=$PATH" unshare -n` keeps the cache        | Ran `sudo env "HOME=$HOME" "PATH=$PATH" unshare -n sh offline-check.sh` as root: chat reply, `network: none`. Not run as a non-root user |
| macOS steps                                                            | Not run. The macOS engine targets are read from `cli: npm/install.js`                                                                    |
