Introducing a new way to review your PRs.

Read the announcement

solana-foundation / surfpool

Surfpool is where developers start their Solana journey.

View on GitHub

21 documents · Updated Nov 23, 2026

docs / cli-and-server

CLI and HTTP server

The surfpool command-line application is the main operator entry point for a local Surfnet. It starts and controls the network, prepares project state, runs project automation, and updates the installed CLI. Its HTTP serving path exposes Studio and scenario services beside the local network's RPC endpoints.

Command-line control

The CLI turns an operator command into one of four broad actions: start a local network, manage a running session, run project automation, or update the client. It also supports separate server operation and shell completion generation. See User interfaces for how this surface relates to the terminal and automation interfaces.

Command dispatch

The binary entry point passes control to the command layer. That layer selects one operating area and applies shared command setup before the selected action runs. The main areas are:

  • start, also available as simnet, starts a local Surfnet.
  • stop asks a running Surfnet to shut down through its JSON-RPC endpoint.
  • run and ls operate on project runbooks. See Runbook automation.
  • mcp starts the MCP server as a separate server mode.
  • completions creates shell completion files.
  • update replaces the current CLI with a selected or latest release.

The CLI can run with an interactive terminal view or as a log-driven process. CI and daemon modes use the headless path so another process can manage the session without a terminal dashboard. Startup can also lock selected or all state-changing cheatcodes before the RPC service accepts requests. A locked session must stop through Ctrl-C or a process signal because the stop command uses the RPC exit method.

References: crates/…/main.rs• L1-15 crates/…/mod.rs• L109-139 crates/…/mod.rs• L999-1057

Simnet startup

The start command creates a local execution session and connects it to the services that clients use. It can use a named Solana network or a custom RPC data source for initial and missing account state. It can also run fully offline.

The startup choices cover these system concerns:

  • Network access: bind host, local RPC port, WebSocket port, data source, or offline mode. An optional genesis hash lets clients identify the local network as a chosen cluster.
  • Project setup: manifest path, deployment runbooks, program artifacts, and optional artifact watching.
  • Initial state: airdrop targets, account snapshots, persistent storage, and the Surfnet identity.
  • Runtime behavior: terminal UI, Studio, daemon or CI mode, slot timing, and block production.
  • SVM and observation: feature flags, signature and blockhash checks, cheatcode access, plugins, logs, profiles, and metrics.

The command builds one shared configuration from these choices. The local runtime then owns execution while the CLI performs project inspection and startup work. Client traffic stays on the local network even when the session reads initial state from a remote data source. In offline mode, the CLI can set a stable genesis hash so clients do not need to use the generated default identity for that session.

The startup path below shows how operator input becomes a usable local network.

flowchart TD
    A["surfpool start"] --> B["Build network and runtime configuration"]
    B --> C["Start local Surfnet and RPC services"]
    C --> D["Inspect project and prepare startup plan"]
    D --> E{Startup work}
    E -->|"Declared clones"| F["Hydrate accounts from data source"]
    E -->|"Runbooks"| G["Deploy or prepare project state"]
    E -->|"No work"| H["Seal empty plan"]
    F --> I["Local network ready"]
    G --> I
    H --> I
    I --> J["TUI or headless logs"]
    I --> K["RPC, WebSocket, Studio, and MCP clients"]

References: crates/…/mod.rs• L232-296 crates/…/mod.rs• L437-513 crates/…/mod.rs• L689-703 crates/…/mod.rs• L45-249 crates/…/startup.rs• L36-80 crates/…/lib.rs• L37-52

Startup planning

Startup planning turns project files and CLI choices into the work needed before the local network is usable. A runbook is a set of project actions that prepares programs and accounts for the local network. The CLI first checks for a txtx.yml manifest and then chooses how to obtain that runbook.

The startup path follows these rules:

  • An existing txtx.yml is authoritative and runs from disk. Framework detection only adds declared clone accounts, so a detection failure does not stop that runbook from running.
  • --artifacts-path builds an in-memory deployment runbook so the selected artifact location is used.
  • --anchor-compat without an existing txtx.yml also builds an in-memory deployment runbook.
  • Without those options, the CLI detects a supported project framework and can scaffold a txtx.yml and deployment runbook on disk.

When the CLI scaffolds files, it can ask which programs to deploy and whether to install the Solana development skill. A recorded choice avoids asking again. The install runs beside startup and reports its result without changing whether the local network can start.

The plan can require two kinds of work:

  • Remote accounts declared by the project must be loaded from the data source.
  • Startup runbooks must complete their deployment or setup actions.

The plan is sealed before its tasks run. Readiness therefore means that all declared startup work has finished. It does not mean only that the process and RPC listener have started. With --watch, later changes to deployed .so artifacts trigger another runbook execution without rebuilding the Surfnet process. A watcher problem is reported as a warning because it does not invalidate the already planned startup. For the distinction between process startup and usable network state, see State and Surfnet execution.

References: crates/…/startup.rs• L36-80 crates/…/startup.rs• L192-335 crates/…/startup.rs• L337-462 crates/…/mod.rs• L77-124 crates/…/mod.rs• L257-279 crates/…/mod.rs• L281-345 crates/…/mod.rs• L347-690

Operator modes

After core startup, the CLI dispatches startup work, starts the headless failure watchdog when needed, and chooses how an operator observes and stops the session. The terminal mode presents chain progress, logs, transactions, and runbook progress. The headless mode prints events to logs and uses Ctrl-C or a terminate command for orderly shutdown.

The terminal view also sends controls back to the Surfnet. An operator can pause or resume the clock, move a slot forward, change block production mode, and send a small transaction to test transaction handling. See Interactive terminal for the terminal layout and key behavior.

In headless mode, a startup watchdog ends the process when a required startup task fails. This stops a failed session from answering readiness checks as if it were usable. A terminal session stays open so the operator can see the failure.

References: crates/…/mod.rs• L201-305 crates/…/mod.rs• L327-375 crates/…/mod.rs• L378-537 crates/…/startup.rs• L84-135 crates/…/simnet.rs• L390-465 crates/…/simnet.rs• L725-788

Update workflow

The update command keeps the installed CLI aligned with a GitHub release. It selects a release for the current operating system and CPU type. It checks whether the requested version is newer and asks for confirmation unless the caller uses --yes.

The command downloads the release archive and checks its SHA-256 digest when the release provides one. It extracts the matching surfpool binary and replaces the running executable. A missing or invalid digest produces a warning rather than a verified integrity result. Operators should treat that case differently from a successful checksum check.

References: crates/…/mod.rs• L920-928 crates/…/mod.rs• L15-31 crates/…/mod.rs• L31-181 crates/…/mod.rs• L184-216

HTTP service surface

The running system exposes more than one HTTP-facing service. The local RPC server operates the simulated Solana network. The CLI's Actix server provides Studio-related APIs, static UI content, scenario management, and the streamable MCP transport.

Local network endpoints

The core runloop is the serving entry point for the local JSON-RPC and WebSocket endpoints. Both endpoints use the same Surfnet state and command path. Reads, transactions, subscriptions, clock controls, and administrative actions therefore observe one local chain.

The HTTP RPC service handles method calls. The WebSocket service handles subscription traffic. The server also registers supported RPC groups for Solana methods, account and bank data, Jito operations, administration, and Surfnet cheatcodes. The start command supplies the bind host and ports.

This endpoint pair is the network contract for local programs, SDK clients, the CLI TUI, and startup readiness checks. The upstream data source remains a source for local state. It is not the endpoint that clients should use for local execution.

References: crates/…/mod.rs• L174-248 crates/…/mod.rs• L943-1054 crates/…/mod.rs• L1056-1127 crates/…/mod.rs• L45-70

Studio and scenario service

The HTTP entry point in crates/…/mod.rs starts the service used by Studio. It publishes a configuration view and scenario templates. It also manages an in-memory set of loaded scenarios that clients can create, list, replace, and delete. See Studio UI for the browser-facing view of this service.

Scenario creation is safe to retry when the same ID has the same content. The service returns a conflict when that ID already holds different content. A patch keeps fields that the request omits. A patch for a missing ID can create a complete scenario, but it cannot create an incomplete one. The path ID is authoritative, and invalid or unknown fields are rejected before the stored scenario changes.

The same service mounts the streamable MCP transport at /mcp. When Studio is enabled, it also serves the Studio web assets and publishes the URLs that let the browser reach local RPC and query services. When Studio is disabled, the local RPC network still operates. Only the Studio UI serving path is turned off.

The API namespace is separate from the static UI fallback. Unknown /v1/* requests return a JSON not-found response instead of an HTML page. API clients can therefore distinguish a missing API route from a browser navigation request.

References: crates/…/mod.rs• L44-109 crates/…/mod.rs• L131-161 crates/…/mod.rs• L163-375 crates/…/mod.rs• L383-396 crates/…/mod.rs• L420-518 crates/…/mod.rs• L542-797

Service lifecycle

The CLI starts the Studio and scenario service while it starts the local Surfnet. The service returns a handle that the CLI keeps until the session ends. On normal termination, the CLI stops that service after the event or terminal loop finishes.

The local RPC and WebSocket servers have their own close handles inside the core runloop. A stop request reaches the local JSON-RPC exit method unless the session locked that administrative method. In that case, the runtime stays protected and the operator must use Ctrl-C or a process signal. A successful stop lets the runtime close its network servers and complete storage cleanup. Ctrl-C follows the same terminate path from the TUI or headless logger.

The simnet startup resolves listener addresses separately from the URLs shown to operators and Studio. SURFPOOL_STUDIO_HOST controls where the Studio service listens. SURFPOOL_PUBLIC_HOST supplies a shared advertised host, while the SURFPOOL_PUBLIC_RPC_URL, SURFPOOL_PUBLIC_WS_URL, and SURFPOOL_PUBLIC_STUDIO_URL settings can define individual public URLs. This supports reverse-proxy deployments while local listeners stay bound to the configured network interface.

The endpoint resolver rejects malformed hosts and URLs, zero ports, and Studio listener conflicts before the HTTP service starts. It resolves literal IP addresses and localhost without DNS, and checks named hosts before it accepts a listener layout. Startup therefore fails early for an unsafe or unresolvable endpoint layout instead of exposing a partial set of service URLs.

The startup path buffers events that arrive before the front end starts and replays them after core startup. Early snapshot and startup messages can therefore reach either the terminal view or the headless logger.

References: crates/…/endpoints.rs• L10-380 crates/…/mod.rs• L127-177 crates/…/mod.rs• L201-217 crates/…/mod.rs• L253-305 crates/…/mod.rs• L999-1119 crates/…/mod.rs• L974-984 crates/…/mod.rs• L1027-1054

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the start option groups aligned with the configuration passed to the Surfnet, RPC, WebSocket, Studio, and startup-planning paths. A flag that reaches only one service can create different views of the same session.
  • Keep framework detection and runbook selection aligned with the startup mode. An existing txtx.yml is authoritative, while custom artifact and Anchor compatibility paths need a generated in-memory runbook.
  • Keep the startup task list aligned with the readiness contract. Adding required work without a seal, start, and completion path can leave clients waiting forever or expose state too early.
  • Keep generated on-disk runbooks and in-memory runbooks aligned with the same project inputs. A change to detected programs, artifacts, accounts, or local network settings can otherwise deploy different state by mode.
  • Keep development-skill consent markers and installer reporting separate from startup readiness. A declined or failed optional install must not block a usable local network.
  • Keep public service URLs aligned with bind hosts and reverse-proxy settings. The TUI, Studio, and browser clients use the published URLs rather than rebuilding them from local assumptions.
  • Keep the optional genesis hash aligned from CLI parsing into simnet configuration. Clients that use cluster identity checks must receive the selected value rather than a generated offline default.
  • Keep endpoint override validation, host resolution, and listener binding aligned. Changes to Studio host parsing or public URL rules must preserve the separation between local listeners and advertised service addresses.
  • Keep cheatcode lock parsing aligned with the RPC method groups and the stop path. A lock that covers exit must produce a clear signal-based shutdown path rather than a misleading RPC stop failure.
  • Keep the /v1 API guard ahead of the static UI fallback. Otherwise a missing API route can look like a successful HTML response to an API client.
  • Keep scenario patch rules aligned with the Scenario data shape. Changes to required fields or nested values can turn valid upserts into incomplete records or allow invalid state into the service.
  • Keep update asset names and binary names aligned with the release workflow. A valid release can still fail if the platform asset or archive member name changes without a matching CLI change.

Important failure modes

TriggerConsequenceGuard
A required remote account cannot be loaded during startupThe startup plan fails and a headless session terminates instead of becoming readyCheck the data source or preload the account in a snapshot; wait for readiness before sending work
A project framework cannot be detected when the CLI must build a deployment planStartup cannot create the required runbook and the command returns an errorUse a supported project layout, provide an existing txtx.yml, or use the correct artifact and test paths
A project uses an existing txtx.yml but framework detection failsThe runbook can still run, but declared clone accounts are not loadedFix the project metadata if clones are needed, or preload those accounts another way
RPC or WebSocket bind port is already in useThe local network cannot expose one or both client endpointsSelect free ports with --port and --ws-port
The optional Solana development-skill installer cannot start or exits with an errorThe skill is not installed, but startup can continue and reports the reasonInstall the required package tool and review the warning if the skill is needed
A scenario patch has unknown or invalid fieldsThe request returns an error and the stored scenario remains unchangedSend fields that match the scenario schema and use a complete document when creating a missing ID
A missing scenario route falls through to the Studio pageAn API client receives HTML with a success-like response instead of a JSON not-found resultKeep the /v1 default route before the static UI fallback
Studio bind settings use an invalid, unresolvable, or overlapping addressThe service refuses to start instead of providing a usable Studio endpointUse a valid resolvable non-zero Studio port and a listener address that does not overlap the local RPC or WebSocket bind
The Studio HTTP service cannot bind or startThe local Surfnet can continue, but Studio, scenario APIs, and the MCP HTTP transport are unavailableUse a free Studio listener and review the startup warning before relying on browser or MCP access
Startup fails in headless mode without a watchdogReadiness clients can continue to poll a process that will never become usableKeep the headless watchdog connected to startup failure and termination
The session locks the RPC exit method and an operator runs surfpool stopThe command reports that shutdown is disabled and the session remains runningStop with Ctrl-C or signal the process; do not lock exit when RPC shutdown is required
An update release has no usable platform assetThe binary cannot be replacedUse a supported OS and CPU pair or install a release that publishes the matching archive
A release checksum is absent or invalidThe update can continue without a verified integrity checkReview the warning and use a release with a valid SHA-256 digest when integrity verification is required

Key files

FileWhy to read it
crates/…/main.rsShows the binary entry point and the top-level CLI module boundary.
crates/…/mod.rsDefines command areas, start options, cheatcode access controls, configuration choices, stop behavior, and command dispatch.
crates/…/mod.rsConnects CLI startup to the Surfnet thread, Studio service, event loop, TUI, and headless operation.
crates/…/endpoints.rsSeparates local listener addresses from public service URLs, resolves endpoint hosts, and checks listener conflicts before startup.
crates/…/startup.rsDefines project inspection, startup planning, runbook dispatch, artifact watching, and readiness failure handling.
crates/…/mod.rsDetects project layouts and creates the on-disk or in-memory deployment inputs used by simnet startup.
crates/…/mod.rsDefines release selection, download, checksum handling, archive extraction, and self-update behavior.
crates/…/mod.rsProvides the HTTP entry point for Studio APIs, scenario management, static UI content, and MCP transport.
crates/…/mod.rsStarts the local JSON-RPC and WebSocket servers and joins them to the Surfnet lifecycle.
crates/…/mod.rsDescribes the shared request context that lets RPC methods read local state and send runtime commands.
crates/…/simnet.rsShows the interactive terminal's operator view and the controls it sends to the running Surfnet.