How fscarmen/sing-box works
1. Repository type and purpose
This is not an application server in the usual sense; it is a deployment and lifecycle automation repo for a “sing-box full bundle” on VPS or inside Docker. The core job is to install, configure, start, update, and expose a multi-protocol sing-box setup, plus generate client-facing node/subscription outputs.
2. Primary entrypoint
The main control surface is sing-box.sh, which acts as the interactive CLI and non-interactive installer/manager. The README shows it being invoked directly from GitHub raw content, and later reused as the local sb command. It is the central orchestrator for install, modify, export, stop/start, upgrade, and uninstall flows.
3. Configuration input paths
There are three supported configuration paths:
• interactive menu-driven setup,
• KV-style command-line flags,
• config.conf for file-based unattended install.
In Docker mode, the same parameters are supplied via environment variables. Architecturally, this means the repo has a single logical configuration model with multiple input adapters.
4. Runtime target and service boundary
The deployed system runs on a VPS or inside a container and manages the real runtime under /etc/sing-box/. That directory is the main boundary between “installer” and “running system.” It contains:
• sing-box server config fragments,
• certificates,
• logs,
• generated node lists,
• subscription artifacts,
• tunnel metadata,
• helper binaries and launch scripts.
5. Core runtime components
The runtime is composed of three main processes:
• sing-box itself as the proxy core,
• nginx for subscription delivery when enabled,
• cloudflared for Argo Tunnel when external ingress is needed without opening ports or when websocket-based protocols need CDN-style exposure.
The installer decides which of these are present and how they connect.
6. Configuration assembly model
The conf/ directory is split into many numbered JSON fragments such as logging, outbounds, DNS, route, experimental settings, NTP, HTTP clients, and protocol-specific inbound definitions. This indicates a modular config assembly pipeline: the script composes final sing-box behavior from reusable fragments instead of keeping one monolithic config file.
7. Protocol family as pluggable subsystems
The bundle supports many protocol modules, each mapped to its own inbound config:
• Reality / XTLS
• Hysteria2
• Tuic
• ShadowTLS
• Shadowsocks
• Trojan
• VMess over WebSocket
• VLESS over WebSocket + TLS
• H2 Reality
• gRPC Reality
• AnyTLS
• NaiveProxy
These are treated as feature switches, not separate apps. The installer allocates ports, certificates, and client outputs per selected protocol set.
8. Subscription and client export pipeline
The subscribe/ directory is the artifact layer for client consumption. It contains multiple output formats for different client families such as:
• Clash / Mihomo
• V2rayN
• NekoBox / Nekoray
• Shadowrocket
• sing-box mobile/desktop variants
• QR and proxy-provider formats
This shows a second major data flow: server-side config → client-specific subscription/link exports.
9. CDN / Argo / origin exposure layer
The repo supports three exposure strategies:
• direct origin access,
• Cloudflare Argo Tunnel temporary mode,
• Argo Tunnel with JSON/Token/API-backed fixed domains.
For websocket-oriented protocols, it can also use CDN/origin-rule style routing. This boundary is important because the deployment can run with or without an exposed inbound port, and the chosen exposure mode affects subscription URLs and connection parameters.
10. Network and security plumbing
The installer manages system-level networking concerns such as UFW vs iptables selection, certificate generation/usage, and WARP-assisted routing for certain outbound or hole-punch scenarios. It also supports certificate fingerprint/pin behavior that differs by client family, which affects how generated client configs are validated and trusted.
11. Docker packaging path
The Dockerfile and docker_init.sh provide a containerized variant of the same bundle. In Docker, host networking is used, and the runtime is driven by environment variables instead of shell prompts. The architecture remains the same, but the service manager boundary shifts from host init systems to container startup scripts.
12. Version pinning and release control
The force_version file implies explicit sing-box version pinning to avoid breaking upgrades. That fits the repo’s role as a compatibility layer over a fast-moving upstream core. The installer therefore manages not only deployment but also upstream version selection and upgrade safety.
13. CI/CD and distribution
The GitHub Actions workflows (build.yml, mirror.yml) indicate automated build and mirroring of the Docker image or release artifacts. This repo is therefore split into:
• source-of-truth scripts and templates,
• generated runtime artifacts,
• CI-produced distribution assets.
14. External dependencies and operating-system adapters
The implementation is designed to adapt across Linux distributions and service managers, including Ubuntu/Debian/CentOS/Alpine/Arch/Armbian, with Alpine using OpenRC where needed. External services that materially affect behavior include Cloudflare APIs/Argo, GitHub raw/CDN hosting, and whatever package manager or init system is present on the host.
15. High-level data flow
A useful architecture diagram would show:
User input or env vars → sing-box.sh / docker_init.sh → generated /etc/sing-box configs and secrets → sing-box + optional nginx/cloudflared services → exported subscriptions/QR/link files → client apps.
A parallel path is CI → Docker image publish / mirrored artifacts → deployment.
Main entry points: sing-box.sh sing-box.sh · docker_init.sh docker_init.sh · build.yml build.yml · Dockerfile Dockerfile
Components 17
Deployment Control
Installer and container entrypoints that orchestrate setup, updates, and lifecycle management.
- sing-box.sh · Main interactive and non-interactive CLI for install, configure, modify, export, start, stop, upgrade, and uninstall flows.
sing-box.sh - docker_init.sh · Container startup script that adapts the same logical bundle to Docker runtime and env-based configuration.
docker_init.sh - config.conf · File-based configuration input for scripted installation and repeatable deployment.
config.conf - force_version · Pinned upstream sing-box version selection used to control upgrade compatibility.
force_version
Runtime System
The installed sing-box bundle and its supporting services under the target host boundary.
- /etc/sing-box · Installed system boundary holding generated configs, secrets, logs, helpers, and service metadata.
- Config assembly · Composes final sing-box behavior from reusable fragments rather than a monolithic config.
- Protocol modules · Feature-selected inbound definitions for Reality, Hysteria2, Tuic, ShadowTLS, Shadowsocks, Trojan, VMess/VLESS variants, AnyTLS, and NaiveProxy.
- sing-box core · Primary proxy process that serves the deployed bundle.
- nginx · Optional HTTP delivery layer for subscriptions and related client-facing artifacts.
- cloudflared · Optional Argo Tunnel process used for external exposure without open inbound ports.
- Exposure mode · Direct origin, Argo tunnel, or CDN/websocket-oriented exposure strategy chosen during deployment.
- Net and TLS · Firewall selection, certificate handling, fingerprint behavior, and WARP-assisted routing decisions.
Client Artifacts
Generated subscription, link, and QR outputs for downstream clients.
- export artifacts · Artifact layer for client-specific subscriptions, links, QR codes, and proxy-provider formats.
- Client apps · Downstream clients such as Clash/Mihomo, V2rayN, NekoBox/Nekoray, Shadowrocket, and sing-box variants.
Build and Release
Automation used to build, mirror, and distribute the bundle.
- build.yml · Automation for building distributable artifacts and images.
.github/workflows/build.yml - mirror.yml · Automation for mirroring releases or images to alternate distribution targets.
.github/workflows/mirror.yml - Dockerfile · Container build definition for the packaged deployment path.
Dockerfile
Connections 20
- config.conf → sing-box.sh: file input · Provides unattended configuration to the installer.
- force_version → sing-box.sh: pins · Constrains upstream version selection during install and upgrade flows.
- sing-box.sh → /etc/sing-box: installs · Creates and manages the host runtime boundary and its contents.
- docker_init.sh → /etc/sing-box: starts · Initializes the same runtime model inside a container.
- sing-box.sh → Config assembly: generates · Builds runtime configuration from modular fragments.
- docker_init.sh → Config assembly: feeds env · Maps container environment variables into the same logical config model.
- Config assembly → Protocol modules: selects · Enables protocol-specific inbound presets as feature switches.
- Config assembly → sing-box core: launches · Produces the final core configuration consumed by sing-box.
- sing-box.sh → Net and TLS: configures · Handles firewall, certificate, and routing-related deployment choices.
- Net and TLS → Exposure mode: conditions · Influences which ingress strategy is valid for the deployment.
- Exposure mode → nginx: optional · Uses nginx when HTTP subscription delivery is enabled.
- Exposure mode → cloudflared: optional · Uses cloudflared when tunnel-based exposure is selected.
- nginx → export artifacts: serves · Publishes generated client artifacts over HTTP.
- cloudflared → sing-box core: fronts · Exposes sing-box traffic through tunnel ingress.
- sing-box core → export artifacts: exports · Produces client-facing links, subscriptions, and QR artifacts.
- export artifacts → Client apps: consumed by · Feeds multiple downstream client families and formats.
- build.yml → Dockerfile: builds · Creates distributable container artifacts from the repo source.
- mirror.yml → Dockerfile: mirrors · Replicates built image or release assets for distribution.
- build.yml → docker_init.sh: packages · Bundles the container entrypoint into the release path.
- sing-box.sh → build.yml: publishes · Source scripts and templates are the basis for CI-produced artifacts.