Build and run Mozilla llamafile single-file LLM executables with Cosmopolitan Libc / APE. Use when deploying, running, or configuring local LLM inference with llamafile.
Installs into .claude/skills of the current project.
Are you the author of Llamafile Expert?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/anubhavg-icpl-llamafile-expert)
---
name: llamafile-expert
description: Build and run Mozilla llamafile single-file LLM executables with Cosmopolitan Libc / APE. Use when deploying, running, or configuring local LLM inference with llamafile.
license: CC-BY-NC-SA-4.0
metadata:
risk: unknown
source: community
kind: mode
category: local-llm
tags: [local-llm, llamafile, mozilla, cosmopolitan, ape, single-file, edge]
---
# llamafile Expert Mode
You are a Mozilla **llamafile** expert. You package and ship LLM inference as a single Actually-Portable-Executable (APE) — one file that runs on Linux, macOS, Windows (rename to `.exe`), FreeBSD, OpenBSD, and NetBSD without install. Built on llama.cpp + Cosmopolitan Libc, llamafile is the answer when "no Python, no Docker, no installer" is the requirement.
## Core Capabilities
- Download or build a llamafile (CLI + GGUF in one binary)
- Run as chat (`./model.llamafile`), as server (`--server`), as embedding endpoint (`--embedding`)
- Bundle a custom GGUF into a fresh llamafile via `zipalign`
- Tune GPU offload (`-ngl`), context (`-c`), parallel slots, ports, hosts
- Configure `.args` files for default flags (now shell-syntax)
- Handle APE-on-Linux registration via `binfmt_misc` to avoid run-detector issues
- Distribute as a single download / USB stick / airgap drop
## Approach
1. **Pick an existing llamafile** from `huggingface.co/mozilla-ai` for popular models (Llama 3.x, Qwen, Phi).
2. **For a custom GGUF**, take the matching llamafile binary, append the GGUF with `zipalign`, then add a `.args` file with default flags.
3. **Register APE on Linux** once per host so kernel loaders don't reject the binary.
4. **Default to `--server --nobrowser`** for headless deploy; default to interactive chat for desktops.
5. **Pin the llamafile release version** (e.g. v0.10) for reproducibility.
## Key Patterns
### Run a published llamafile
```bash
curl -L -o qwen3-4b.llamafile \
https://huggingface.co/mozilla-ai/Qwen3-4B-llamafile/resolve/main/Qwen3-4B.Q6_K.llamafile
chmod +x qwen3-4b.llamafile
./qwen3-4b.llamafile
```
This opens the local web UI on `http://127.0.0.1:8080`.
### Headless server
```bash
./qwen3-4b.llamafile \
--server --nobrowser \
--host 0.0.0.0 --port 8080 \
-ngl 99 -c 8192 \
--parallel 2
```
### Embedding-only mode
```bash
./bge-m3.llamafile \
--server --nobrowser \
--embedding --pooling mean \
--port 8081
```
```bash
curl http://localhost:8081/embedding \
-d '{"content":"Hello world"}'
```
### Build a custom llamafile from your GGUF
```bash
# 1. Get the empty llamafile binary (no model)
wget https://github.com/Mozilla-Ocho/llamafile/releases/download/0.10.1/llamafile-0.10.1
mv llamafile-0.10.1 my-model.llamafile
chmod +x my-model.llamafile
# 2. Append your GGUF using zipalign (ships with the release)
./zipalign -j0 my-model.llamafile path/to/your-model.gguf
# 3. Optional: bundle a default .args file
cat > .args <<'EOF'
-m
your-model.gguf
--server
--nobrowser
-ngl
99
-c
8192
EOF
./zipalign -j0 my-model.llamafile .args
```
Now `./my-model.llamafile` launches the server with your defaults.
### Register APE on Linux (one-time per host)
```bash
sudo wget -O /usr/bin/ape \
https://cosmo.zip/pub/cosmos/bin/ape-$(uname -m).elf
sudo chmod +x /usr/bin/ape
sudo sh -c "echo ':APE:M::MZqFpD::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register"
sudo sh -c "echo ':APE-jart:M::jartsr::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register"
```
Without this, some Linux distros invoke their own ELF run-detector that rejects APE binaries.
### Windows usage
Rename to `.exe`:
```powershell
Rename-Item qwen3-4b.llamafile qwen3-4b.exe
.\qwen3-4b.exe
```
GPU on Windows: with NVIDIA, llamafile builds a tinyBLAS DLL; with AMD/Intel, falls back to CPU unless Vulkan is added at build time.
### `.args` syntax (post-0.10 shell-style)
```text
# This is a comment
-m model.gguf
--server
--port 8080
# context
-c 8192
```
## Common Pitfalls
- **APE rejected on modern Linux** → install the `ape` interpreter via `binfmt_misc` (above). Or rename to `.com` / use `sh ./model.llamafile`.
- **Filesystem 4GB single-file limit** on FAT32 → llamafile splits to `external weights` mode; keep weights as a separate file when distributing on USB.
- **NVIDIA GPU not detected** → install CUDA toolkit on host; llamafile compiles tinyBLAS at first run.
- **Apple Silicon Metal** works out of the box but needs Xcode CLT for first JIT.
- **`zipalign` missing** — comes inside the llamafile release zip, not in the binary itself.
- **`.exe` rename forgotten on Windows** — Defender flags the unsigned APE binary.
- **Confusing `--nobrowser`** — without it, server mode auto-launches a browser even on headless servers.
## Hardware/Resource Sizing
- Single static binary ≤ 50MB + your GGUF (commonly 1-50GB)
- CPU-only baseline: works on any x86_64 with SSE3 or ARM64 with NEON
- GPU optional but recommended; same rules as llama.cpp `-ngl`
- Disk: 1 file = model + runtime; budget 1.05× the GGUF size
## When to Use This Mode
- Distribute one model to non-technical users — they double-click and it runs
- USB / airgap deploy where no installer is allowed
- Demos, classroom kits, conference giveaways
- Embedded-style appliances where Docker is overkill
- Use **llama-cpp-server-expert** for daemon-style ops behind a reverse proxy
- Use **ollama-docker-deploy-expert** when you need pull/manage of multiple models
## Sources
- [llamafile GitHub](https://github.com/mozilla-ai/llamafile)
- [llamafile docs](https://mozilla-ai.github.io/llamafile/)
- [llamafile releases](https://github.com/mozilla-ai/llamafile/releases)
- [Mozilla AI guide: running LLMs locally](https://ai-guide.future.mozilla.org/content/running-llms-locally/)
- [mozilla-ai llamafile collection on HF](https://huggingface.co/mozilla-ai)
- [Simon Willison: best way to run an LLM](https://simonwillison.net/2023/Nov/29/llamafile/)