Skip to content

Self-Host Qwen Code with qwen serve and Localtonet

Install and verify Qwen Code, run a shared qwen serve session, and provide secure remote access through a Localtonet HTTP tunnel.

Summary in your language
In this article 14 sections
AI Coding Agents · Qwen Code qwen serve · Localtonet · 2026

Run a loopback-only Qwen Code daemon, require a bearer token, and reach it remotely through a Localtonet HTTPS tunnel

Qwen Code is an open-source coding agent that normally runs in a terminal. Its experimental qwen serve mode turns it into a shared daemon that speaks HTTP and Server-Sent Events and serves a built-in Web Shell. This guide uses Qwen Code v0.22.3 as its release baseline. It verifies model access locally, starts the daemon with authentication required, walks through the documented quickstart sequence against a protected API route, and only then connects the loopback service to a Localtonet HTTP tunnel. It also explains how the current Qwen documentation handles remote Web Shell login and HTTPS, and which of our tunnel settings matter for long-lived streams and token-carrying traffic.

🔒 Required daemon bearer token and HTTPS-only public URL 🌐 HTTP, SSE and WebSocket-capable tunnel ⚡ Local denial test before any public exposure
A local Qwen Code server connects through a Localtonet tunnel to an approved remote client.
The Qwen Code daemon remains on the host while Localtonet provides the remote HTTPS path.

What this self-hosted Qwen Code workflow provides

Qwen Code is an agentic coding tool that runs on a computer with access to a selected project. Its normal interactive mode starts with the qwen command and presents a terminal interface. The project also supports headless operation, editor integrations for Visual Studio Code, Zed and JetBrains IDEs, TypeScript, Python and Java SDKs, a desktop app, chat channels, and an experimental daemon mode.

The daemon starts with qwen serve. According to the current Qwen Code daemon documentation, it provides an HTTP service through which compatible clients can share agent functionality instead of each starting an independent Qwen Code subprocess. Events are streamed with Server-Sent Events, commonly abbreviated as SSE. The Qwen documentation site also publishes a separate Daemon REST API reference (the qwen serve HTTP protocol) and a developer deep dive covering the serve runtime, permission mediation, session lifecycle, the SSE event bus, and the auth and security model.

The daemon also serves a built-in Web Shell at its root. The documented default URL is http://127.0.0.1:4170/. The Web Shell and API share one origin, so the interface does not need a second application port. The loopback address matters: software on the same machine can connect, but another LAN or internet device cannot connect directly.

🤖 Shared daemon Compatible clients connect to one Qwen Code daemon rather than independently spawning agent processes. Parallel sessions in a workspace share one qwen --acp child process per workspace runtime.
🖥️ Built-in Web Shell The daemon serves a browser interface at the root URL unless started with --no-web. Current documentation covers remote and phone access, login to a remote daemon, and installing the Web Shell as an app.
📡 SSE event delivery Server-Sent Events carry streamed daemon events. Clients subscribe to the stream before sending a prompt so they see every event the turn produces.
📁 Workspace-aware operation The daemon can register one or more workspaces with repeated --workspace options, with the first registered workspace acting as the primary default.
🔐 Bearer-token authentication A token is supplied through QWEN_SERVER_TOKEN or --token, and --require-auth makes authentication mandatory.
🌐 Outbound tunnel connectivity Our Localtonet client opens an outbound connection to a relay and forwards an assigned public HTTPS address to the local HTTP service. WebSocket connections also pass through HTTP tunnels.

Localtonet does not install, configure, or authenticate Qwen Code. The daemon remains on your machine and keeps the project, model-provider access, session state, and tool permissions you configure. Our role begins only after the protected service works locally. The Localtonet client then forwards requests from a public endpoint to that local service. HTTPS is terminated at the Localtonet server, and the request then travels through the tunnel to your device, where our client passes it to 127.0.0.1:4170.

This separation makes failures easier to diagnose. If the protected daemon cannot be reached at 127.0.0.1:4170, fix Qwen Code before creating a tunnel. If local authenticated access works but the public address does not, investigate the Localtonet client, selected device token, target fields, server region, tunnel settings, and tunnel state.

A coding daemon is not a static website

A connected agent may read project files, propose or perform edits, invoke tools, display conversation history, and consume model-provider tokens. Use a dedicated workspace, conservative approval controls, a least-privileged operating-system account, and required application-layer authentication. Do not depend on an unguessable public URL as an access control.

Release baseline, Stage 1.5+ guarantees and Stage 1 boundaries

This revision uses Qwen Code v0.22.3, released on 28 August, as its release baseline. At the time of this revision we had not verified a newer stable release, but Qwen Code ships frequently. Open the project's releases page before installing, and if a newer stable tag exists, read its notes for daemon, Web Shell, or authentication changes before deciding whether to pin v0.22.3 or move forward. Pinning the npm installation makes the executable reproducible. If you use a standalone installer or Homebrew, verify the installed version before following version-sensitive daemon instructions.

The v0.22.3 release lists no known breaking changes. Its daemon-relevant highlights include a standalone daemon session API supporting create, list, resume, archive, and delete for top-level sessions, matching standalone session APIs in the SDK, daemon extension installs that accept absolute local paths while rejecting relative paths and unsupported options, and several Web Shell additions: GitHub-style state icons for sessions bound to pull requests, an opt-in composer add menu, an opt-in interactive browser terminal with independent PTY sessions per tab, and a fix for restoring saved session diffs.

Earlier versions of the daemon document described the first qwen serve npm release as v0.16-alpha, a text-only, local-only, experimental release aimed at prototyping and small-team collaboration. The current document frames scope differently. It contains a Stage 1.5+ runtime guarantees section describing what the runtime commits to, and a Stage 1 scope boundaries section describing what the project states it will not fix in Stage 1.5. Treat the v0.16-alpha description as history and the two Stage sections as the current statement of guarantees and limits.

Two boundary topics in the current document are directly relevant to a tunneled deployment. First, session state is described as local-mutation-only, and the document distinguishes Mode 1, headless qwen serve, from Mode 2, a Stage 1.5 qwen --serve co-hosted TUI. This guide uses Mode 1. Second, N parallel sessions share one qwen --acp child per workspace runtime, so sessions in one workspace are not isolated processes.

Evidence What it establishes How to use it
Historical v0.16-alpha description Launch scope of the first daemon release Background only; do not repeat alpha limits as current limits
Stage 1.5+ runtime guarantees What the current runtime is documented to guarantee Read before relying on reconnection, persistence, or concurrency behavior
Stage 1 scope boundaries Known limits the project does not plan to change in Stage 1.5, including local-mutation-only session state and a shared ACP child per workspace Design access and collaboration around these limits
v0.22.3 release page Continued daemon and Web Shell work, no known breaking changes Reproducible baseline for this guide
Your installed executable The options actually available on the machine Verify with qwen serve --help before exposing anything

This guide does not claim that v0.22.3 is production-grade. The project still labels daemon mode experimental. Review the guarantees and boundaries for the version you deploy, particularly before long-running, network-flaky, high-volume, or business-critical work.

Prerequisites and security decisions

Choose the host and workspace

Use a computer that contains, or is allowed to reach, the project Qwen Code will operate on. The host must remain running while remote access is needed. The Qwen daemon, Localtonet client, and tunnel must all be active for the public endpoint to work.

Start with a dedicated test repository. Commit or back up important files before allowing an agent to modify them. Version control helps inspect and reverse tracked changes, but it does not protect untracked secrets, databases, external services, or commands with side effects.

Run Qwen Code under an operating-system account with only the required filesystem and command permissions. Avoid an administrator or root account unless a separately reviewed workflow requires it. Do not start the daemon from a home directory or filesystem root when only one project should be available.

Prepare a model provider

Qwen Code requires a model provider. Its first-run provider menu can offer Alibaba ModelStudio options, supported third-party providers, and a custom provider for a local server, proxy, or otherwise unsupported provider. Endpoint, model, account, API key, quota, and billing requirements depend on the selected provider.

Keep the model credential out of shell history, screenshots, source control, project instruction files, and support transcripts. A model-provider credential is not the same secret as a Qwen daemon bearer token or a Localtonet device token.

Prepare Localtonet before you start

Our HTTP tunnel documentation lists three preconditions, and all of them apply here:

  • The Localtonet client is installed on the device and connected with an AuthToken. For this guide, that device is the Qwen Code host. The exact loopback target used later only works if our client runs on the same machine, because 127.0.0.1 always refers to the device on which the connecting client runs.
  • Your web service is running and you know its port. Here the service is qwen serve on port 4170.
  • For a Custom subdomain or Custom domain, you need balance on your account. A Custom domain additionally requires a domain you have added in DNS Manager. A Random subdomain needs nothing extra.

The AuthToken identifies the client device. Device tokens are device-specific and must remain private. Server regions and other dashboard options can vary, so select from the current values shown for your account rather than copying a value from an older guide.

Prepare a daemon token safely

Generate a long, unique random secret with your approved password manager or secret-management system. Do not reuse the model-provider key, Localtonet device token, account password, or any project secret. The examples below prompt for the daemon token without embedding its real value in the command.

Three independent credentials

The model-provider credential authorizes model use. QWEN_SERVER_TOKEN authenticates a client to qwen serve. The Localtonet AuthToken identifies the device running our client. Rotating one does not rotate the others.

Install Qwen Code and confirm the version

The Qwen Code overview documents standalone installers for Linux, macOS, and Windows, plus npm and Homebrew installation paths. Choose one method. Using several methods can put multiple qwen executables on PATH.

Reproducible npm installation

The most direct way to pin the release used by this guide is npm. Qwen Code requires Node.js 22 or later for this installation path:

node --version
npm --version
npm install -g @qwen-code/qwen-code@0.22.3

Confirm that the Node.js major version is 22 or later before installing. If a newer stable release exists and you decide to use it, replace the version in the command after reading its release notes. If npm reports success but qwen is unavailable, fix the global npm executable path rather than reinstalling.

Standalone installer on Linux or macOS

curl -fsSL https://qwen-code-assets.oss-cn-hangzhou.aliyuncs.com/installation/install-qwen-standalone.sh | bash

Restart the terminal if qwen is not immediately available. A remote script piped into a shell executes its current contents, so review the script and your organization's software-installation policy in controlled environments.

Standalone installer on Windows

irm https://qwen-code-assets.oss-cn-hangzhou.aliyuncs.com/installation/install-qwen-standalone.ps1 | iex

Restart PowerShell or the terminal application after installation if necessary.

Homebrew on macOS or Linux

brew install qwen-code

Standalone and Homebrew channels may install a release newer than this guide's baseline. Record the version reported by your installed executable and review its release information before applying version-sensitive instructions.

Inspect the installed command surface

qwen --version
qwen --help
qwen serve --help

Confirm that qwen serve --help lists the authentication controls used below, including --require-auth and --token, before creating any public tunnel. Keep this help output open: it is the authoritative list of flags for your exact build, including the port and host options covered in the CLI flags section of the daemon document. If your installed release does not expose a documented option, stop and use the documentation for that release rather than substituting an undocumented flag.

Configure the provider and verify the interactive agent

Qwen Code installation, provider authentication, startup, and interactive verification flow.
Verify provider authentication and workspace selection in the terminal before starting an HTTP service.

Test the normal terminal workflow first. This isolates installation, model-provider authentication, project access, and basic agent behavior from daemon and tunnel configuration.

1

Open the intended project

Change into a dedicated test repository that the current operating-system account may safely read and modify.

2

Launch Qwen Code

Run qwen. On first launch, select and configure a supported model provider using the prompts shown by the installed release.

3

Review authentication settings

Use /auth inside the session when you need to configure or change the provider and its credential.

4

Send a read-only prompt

Ask what the project does or request a repository-layout summary. Confirm that the response describes the intended project.

5

Review permission behavior

Observe how the installed version requests approval before tool use. Keep approval controls conservative and exit after confirming normal operation.

cd /path/to/your-project
qwen

Inside Qwen Code, use:

/auth

Do not continue until the intended provider works, a harmless prompt receives a response, and Qwen Code is operating in the correct workspace.

Start qwen serve on loopback

The qwen serve process running beside a browser opened to the loopback address.
Test the daemon on the host before adding any public network path.

The daemon document identifies http://127.0.0.1:4170/ as the default address. Keeping this loopback binding is the safest architecture for the same-host Localtonet workflow because it avoids exposing Qwen Code directly to the LAN. The CLI flags section of the daemon document describes the port and host options; check qwen serve --help for their exact names in your build if 4170 is unavailable, and if you change the port, use the new value as the Local port in the tunnel later.

The documented quickstart begins with step 1, "Start the daemon (loopback, no auth)". You may run that once to confirm the daemon launches:

cd /path/to/your-project
qwen serve

Open the following address only from the same machine:

http://127.0.0.1:4170/

The daemon documentation also lists these controls:

qwen serve --open
qwen serve --no-web

--open launches the local Web Shell in a browser. --no-web disables the built-in Web Shell for an API-only daemon. If your remote clients are API, SDK, or IDE clients only, --no-web reduces what the public URL serves. Do not use it if Web Shell verification is part of your test.

Local functional checklist

  • The daemon remains running without a provider or configuration error.
  • The local browser reaches 127.0.0.1:4170.
  • A harmless prompt receives a streamed response.
  • The session uses the intended project rather than a home directory or unrelated repository.
  • Tool permission requests can be reviewed and accepted or rejected.
  • Stopping the daemon makes the local page unavailable.

Stop this tokenless process after the local test. Never create a Localtonet tunnel to it. The next section restarts the daemon with authentication required, and every later step uses that protected instance.

Require a bearer token and prove unauthenticated denial

Authenticated requests travel through a Localtonet HTTP tunnel to qwen serve on loopback, while requests without a bearer token are denied.
The public Localtonet endpoint forwards authenticated requests to qwen serve on the host's loopback interface.

Qwen Code documents bring-your-own bearer-token support through the QWEN_SERVER_TOKEN environment variable and the --token option, and --require-auth for making authentication mandatory. The full rules live in the Authentication section of the daemon document. This guide uses the environment variable so the token value does not appear in the daemon's command line.

Linux and macOS

Open a terminal in the intended project. Prompt for the token without echoing it, export it to the daemon's environment, and start Qwen Code with authentication required:

cd /path/to/your-project
read -rsp "Qwen daemon token: " QWEN_SERVER_TOKEN
echo
export QWEN_SERVER_TOKEN
qwen serve --require-auth

Keep that terminal open. Do not paste the token value into the command itself, a shell script stored in the repository, or a screenshot.

Windows PowerShell

In a current PowerShell environment that supports masked input:

Set-Location C:\path\to\your-project
$env:QWEN_SERVER_TOKEN = Read-Host "Qwen daemon token" -MaskInput
qwen serve --require-auth

This environment variable applies to the current PowerShell process and programs launched from it. Closing the terminal removes it. Do not use a persistent system-wide environment variable for a temporary test unless that storage method has been reviewed for your environment.

Fail closed before tunneling

If qwen serve --help does not list the documented authentication options, if the daemon ignores --require-auth, or if an unauthenticated request to a protected API route succeeds, do not start the Localtonet tunnel. Resolve the release or configuration mismatch first.

Test a protected API route, not the root

The root URL serves the Web Shell. Static Web Shell assets may load without a token even when the API is protected, because the shell needs to render before it can ask for credentials. A response from / therefore proves very little in either direction. Run the denial and allow test against a documented API route instead. The natural choice is the route used in quickstart step 2, "Sanity-check it", in the daemon document. A session route from the Daemon REST API reference works as well.

Copy the exact path from your release's documentation into a shell variable. We use a variable rather than printing a path here so that the commands stay correct even if the route differs between releases:

QWEN_BASE="http://127.0.0.1:4170"
SANITY_PATH="/copy-the-path-from-the-sanity-check-step"

In a second terminal, first request it without an authorization header:

curl -i "${QWEN_BASE}${SANITY_PATH}"

The request must be refused rather than returning daemon data. We do not list an expected status code because the code was not part of the documentation we verified for this revision; record what your build returns in private notes, and confirm it is an authentication rejection, not a 404 caused by a mistyped path.

Next, load the same token into this terminal without echoing it and send it as a bearer token:

read -rsp "Qwen daemon token: " QWEN_SERVER_TOKEN
echo
export QWEN_SERVER_TOKEN
curl -i \
  -H "Authorization: Bearer ${QWEN_SERVER_TOKEN}" \
  "${QWEN_BASE}${SANITY_PATH}"

The authenticated request should succeed while the unauthenticated one stays denied. Your shell history contains the variable name, not the token value. On shared multi-user hosts, remember that expanded command arguments can be briefly visible to other local users in process listings, which is one more reason to use a dedicated host account.

Test the protected daemon on Windows

$QwenBase = "http://127.0.0.1:4170"
$SanityPath = "/copy-the-path-from-the-sanity-check-step"
curl.exe -i "$QwenBase$SanityPath"

$env:QWEN_SERVER_TOKEN = Read-Host "Qwen daemon token" -MaskInput
curl.exe -i `
  -H "Authorization: Bearer $env:QWEN_SERVER_TOKEN" `
  "$QwenBase$SanityPath"

A successful security check has two parts: the no-header request is rejected, and the request carrying the correct bearer token reaches the daemon. Do not weaken --require-auth to accommodate a client that cannot send the header.

Keep workspace and approval scope narrow

The daemon supports repeated --workspace options, with the first workspace acting as the primary default. Multiple workspaces increase the files and tools reachable through one listener, so register only those needed. The daemon document also has a Workspace registration capacity section if you plan to register several.

Clients targeting the same workspace may share conversation state, diffs, and permission prompts. When a tool permission request is shown to several clients, the first response wins. This is a collaboration model, not isolation between mutually untrusted users.

Some operations can trigger additional model calls. The daemon documentation describes the session recap route as a pure-cost side query and historically documented no per-route rate limit for it. Authentication stops unknown callers, but approved clients must still avoid uncontrolled request loops.

Credential Purpose Handling rule
Model-provider credential Authorizes Qwen Code to use the configured model service Store through the provider's supported mechanism and never disclose it to remote users
Qwen daemon bearer token Authenticates clients connecting to qwen serve Use a unique random value, require it for tunneled access, and rotate it after suspected disclosure
Localtonet AuthToken Identifies the device running our Localtonet client Keep it device-specific and remove it from screenshots, repositories, and client instructions

Walk through the daemon API with authentication

The daemon document's quickstart runs in five numbered steps: start the daemon, sanity-check it, open a session, subscribe to the event stream in another terminal, and send a prompt in the original terminal. Step 1 in the document starts the daemon on loopback without authentication. We replace it with the protected startup from the previous section and add the bearer header to every request. This gives API and SDK client authors an end-to-end test of the protocol before any tunnel exists.

Where the exact routes and bodies come from

The route paths, HTTP methods, request bodies, and response fields for these steps are defined in the quickstart of the daemon document and in the Daemon REST API reference. They were not part of the material we verified for this revision, so we show them as variables you fill in from the documentation for your installed release. The sequence, the authentication header, and the two-terminal pattern are what this section adds.

Step 1: start the protected daemon

Use the qwen serve --require-auth startup from the previous section. Keep that terminal dedicated to the daemon.

Step 2: sanity-check it

This is the authenticated request you already ran against SANITY_PATH. If it does not succeed with the token, stop here.

Step 3: open a session

In a client terminal that has QWEN_SERVER_TOKEN loaded, set the session-creation path from the "Open a session" step and send the request with the method and body shown there. The template below assumes a JSON request as is typical for this kind of API; adjust the method or body if your documentation differs:

SESSION_PATH="/copy-the-path-from-the-open-a-session-step"
curl -i -X POST \
  -H "Authorization: Bearer ${QWEN_SERVER_TOKEN}" \
  -H "Content-Type: application/json" \
  --data @open-session.json \
  "${QWEN_BASE}${SESSION_PATH}"

Put the request body from the documentation into open-session.json in a scratch directory outside the repository. Note the session identifier in the response; the next two steps use it. If you omit a working directory where the API allows it, the primary workspace is used.

Step 4: subscribe to the event stream first

Open a second client terminal, load the token again, and subscribe to the session's event stream before sending anything. Subscribing first ensures you see every event the prompt produces. -N disables curl's output buffering so events appear as they arrive, and Accept: text/event-stream is the standard request header for SSE:

read -rsp "Qwen daemon token: " QWEN_SERVER_TOKEN
echo
export QWEN_SERVER_TOKEN
QWEN_BASE="http://127.0.0.1:4170"
EVENTS_PATH="/copy-the-path-from-the-subscribe-step-with-your-session-id"
curl -N \
  -H "Authorization: Bearer ${QWEN_SERVER_TOKEN}" \
  -H "Accept: text/event-stream" \
  "${QWEN_BASE}${EVENTS_PATH}"

Leave it running. Also confirm the stream is protected: the same command without the Authorization header must be refused. An unprotected event stream would leak conversation content even if prompts are protected.

Step 5: send a prompt from the original terminal

PROMPT_PATH="/copy-the-path-from-the-send-a-prompt-step-with-your-session-id"
curl -i -X POST \
  -H "Authorization: Bearer ${QWEN_SERVER_TOKEN}" \
  -H "Content-Type: application/json" \
  --data @prompt.json \
  "${QWEN_BASE}${PROMPT_PATH}"

Use a harmless, read-only prompt in prompt.json, such as asking for a summary of the repository layout. Watch the subscriber terminal: streamed events for the turn should appear there. If the agent requests a tool permission, it will surface through the protocol, and under the first-responder model any connected client can answer it.

The daemon document also describes an Optional Todo Stop Guard, controls for adjusting session live-state polling, running channels from the daemon, loading and resuming a persisted session, and runtime MCP server management through POST /workspace/mcp/servers. None of these is needed for the basic tunnel, and runtime MCP changes alter what tools the agent can reach, so keep them out of a first deployment.

If you build a client in TypeScript, the Qwen documentation includes an API-only DaemonClient quickstart and an SDK daemon client guide. Whatever client you use, it must attach the bearer header to every protected HTTP request and to the event-stream connection.

Remote Web Shell access, login and HTTPS

An earlier version of this guide said that no documented bearer-token entry flow existed for the Web Shell. That is no longer accurate. The current daemon document includes a "Remote Web Shell and phone access" subsection in its quickstart, an Authentication section, an "HTTPS / TLS (for mobile / cross-device access)" section, an "Install the Web Shell as an app" section, and a section titled "Logging in to a remote daemon (issue #4175 PR 21)". Remote Web Shell use is therefore a documented scenario, and the login procedure lives in those sections.

The step-by-step screens of that login flow were not part of the material we verified, so we do not reproduce them here. Follow the "Logging in to a remote daemon" section for your installed release, and use this order so the browser path is held to the same standard as the API path:

  1. Start the daemon with --require-auth on loopback, as above.
  2. Repeat the API denial test against SANITY_PATH and confirm unauthenticated requests are refused.
  3. On the host, open http://127.0.0.1:4170/ in a private browser window and complete the documented login. Confirm the Web Shell can list sessions and send a harmless prompt only after login.
  4. Close the window, open a new private window, and confirm the Web Shell cannot use the API until you log in again, or behaves as the documentation says it should for a saved login.
  5. Only after the tunnel exists and the remote API denial test passes, repeat steps 3 and 4 against the public HTTPS address from an approved remote device.

Treat any credential a browser stores for the Web Shell as a daemon credential. Log out or clear site data on shared devices, and rotate the daemon token if a device that held it is lost.

How Localtonet HTTPS relates to Qwen's TLS guidance

The daemon document has a dedicated section on HTTPS and TLS for mobile and cross-device access. As a general web fact, browsers restrict many features, including installing a site as an app, to secure contexts, so cross-device use of a web interface usually needs HTTPS. The Qwen section describes how to provide that.

A Localtonet HTTP tunnel already provides HTTPS to visitors. Visitors reach the tunnel over HTTPS with a certificate that Localtonet provides and renews. TLS ends at the Localtonet server, the request travels through the tunnel to your device, and our client passes it to your local service, which can stay on plain HTTP. For this guide, that means you can keep qwen serve on plain HTTP at 127.0.0.1:4170 and still give remote devices an HTTPS address, which should satisfy the secure-context requirement for installing the Web Shell as an app.

Daemon configuration Localtonet setting Result
Plain HTTP on loopback (recommended here) HTTP tunnel, Is SslStream? off, Is Only Https? on HTTPS for visitors; TLS ends at the Localtonet server; plain HTTP only on the host's loopback
Daemon serving its own HTTPS per Qwen's TLS section HTTP tunnel with Is SslStream? on Our client connects to the local service with TLS and accepts its certificate as is, so a self-signed certificate works
Daemon must present its own certificate to remote clients TLS tunnel instead of HTTP tunnel Encryption reaches your own service; Localtonet does not decrypt at its server

Do not enable Qwen's own TLS and leave Is SslStream? off, or the reverse. A mismatch means our client speaks plain HTTP to a TLS listener or TLS to a plain listener, and requests fail. For a same-host loopback design, the first row avoids double TLS and is the simplest configuration to verify.

Logs, flags, threat model and runtime behavior

Before exposing the daemon, read the operational sections of the daemon document that govern what it records, which options it accepts, and what its default deployment assumes. We verified these sections by title in the current document. Their command-level details vary by release and were not part of the material we verified, so the table summarizes what each covers and how it applies to a tunneled deployment.

Daemon document section What it covers What to do for a tunneled daemon
Inspect and control a local daemon How to check on and control a running daemon from the same machine Use these local controls for status checks rather than probing the public URL
Daemon log file, with Disabling, Relation to session debug logs, and External rotation Where the daemon writes its log, how to turn it off, how it relates to per-session debug logs, and how to rotate it with external tools Find the log location for your release, restrict its file permissions, configure external rotation for long-running hosts, and never paste log excerpts containing headers or prompts into public channels
CLI flags The supported options, including network listener options, --open, --no-web, --token, --require-auth and --workspace Keep the listener on loopback. If you change the port, update the tunnel's Local port. Compare against qwen serve --help
Built-in daemon Git relocation guard A built-in guard related to Git repositories and relocation Leave defaults in place and read the section before working across repositories
Required external Tool Guard An external guard the document marks as required for tool execution Treat this as a deployment prerequisite. Configure it as documented before giving remote users access
Default deployment threat model, with deadlines and writer idle timeout, new-file mode for agent text writes, conversations working directory, and session attachment storage The trust assumptions of a default deployment and the related limits and storage locations Compare your remote exposure against those assumptions. If the default model assumes local trusted users, tunnel access widens it, so require authentication and restrict who can reach the URL
Multi-session and multi-workspace deployment Running several sessions and workspaces in one daemon Remember that parallel sessions in a workspace share one qwen --acp child; register only needed workspaces
Durability model What survives restarts and what can be lost Plan restarts and host sleep with this in mind; use the persisted-session loading and resuming flow where supported
Do not skip the Tool Guard requirement

The daemon document lists an external Tool Guard under its CLI flags as required. A remotely reachable agent that executes tools without the guard the project expects is a larger risk than a local one. Configure it per your release's documentation before starting the Localtonet tunnel.

Create the Localtonet HTTP tunnel

An approved remote client reaches a protected qwen serve daemon through a Localtonet HTTP tunnel.
The public endpoint forwards to the authenticated loopback daemon while both the Localtonet client and tunnel are running.

Create the tunnel only after the local test proves that requests to a protected API route without the bearer token are denied. HTTP is the right tunnel family because the Qwen daemon uses HTTP and SSE, and WebSocket connections also pass through an HTTP tunnel if any client feature needs them.

Our client establishes an outbound connection to a Localtonet relay, which provides a public URL without inbound router port forwarding, firewall changes, VPN setup, or a public IP address. The tunnel is available only while the selected device is connected and the tunnel is running. Confirm the prerequisites from the Prepare Localtonet section, then follow the sequence from our HTTP tunnel documentation:

1

Open the HTTP page

Open My Tunnels › HTTP and select Create HTTP Tunnel to open the form.

2

Choose the URL type

Random subdomain gives a generated name on the selected domain and needs nothing extra. Custom subdomain uses the name you type in Subdomain (letters, digits and hyphens) and needs account balance. Custom domain uses your own domain and needs balance plus a domain added in DNS Manager. A random subdomain is the simplest first test.

3

Choose the device and the region

In Device token, select the token used by the Localtonet app on the Qwen Code host. In Server region, choose a region close to the device for lower latency.

4

Enter the local address and create the tunnel

Set Domain (for example localto.net, or one of your own domains for Custom domain), Subdomain only for Custom subdomain, Local IP address 127.0.0.1, and Local port 4170. Select Create tunnel. It appears under Your tunnels as Tunnel # followed by its ID.

5

Start the tunnel

Select the start button in the Actions column. When the tunnel runs, its address in the URL column becomes a link. If the Localtonet app for that token is offline, a dialog tells you so; start the app, or select Start anyway and the tunnel goes live when the app connects.

Your public address is https:// followed by the host name in the URL column, with no port number. An HTTP tunnel keeps its subdomain until you delete the tunnel; stopping and starting does not change it. That stability is useful for clients and installed Web Shell apps that store the address, and it also means a leaked address stays valid until you delete the tunnel, so authentication remains essential.

Why the target remains 127.0.0.1

When Qwen Code and our client run on the same host, Localtonet forwards directly to the loopback listener, so the daemon never needs to listen on the LAN. If our client runs on another computer, that computer's 127.0.0.1 points back to itself, not to the Qwen host.

Verify the public endpoint without exposing the token

Before verifying, apply the settings in the next section, especially Is Only Https?. Then, on an approved remote Linux or macOS client, point the same protected route at the public address:

QWEN_BASE="https://YOUR-ASSIGNED-PUBLIC-HOST"
SANITY_PATH="/copy-the-path-from-the-sanity-check-step"
curl -i "${QWEN_BASE}${SANITY_PATH}"

The public request must be denied by the daemon. Then prompt for the token and send it:

read -rsp "Qwen daemon token: " QWEN_SERVER_TOKEN
echo
export QWEN_SERVER_TOKEN
curl -i \
  -H "Authorization: Bearer ${QWEN_SERVER_TOKEN}" \
  "${QWEN_BASE}${SANITY_PATH}"

On Windows PowerShell:

$QwenBase = "https://YOUR-ASSIGNED-PUBLIC-HOST"
$SanityPath = "/copy-the-path-from-the-sanity-check-step"
curl.exe -i "$QwenBase$SanityPath"

$env:QWEN_SERVER_TOKEN = Read-Host "Qwen daemon token" -MaskInput
curl.exe -i `
  -H "Authorization: Bearer $env:QWEN_SERVER_TOKEN" `
  "$QwenBase$SanityPath"

Replace the placeholder host with the address from your URL column, and never publish that address together with a credential. Finally, repeat the event-stream subscription from the API walkthrough through the public URL and confirm events arrive while a prompt runs. That proves the stream survives the tunnel path for your settings.

Stop or delete when finished

Stopping the tunnel ends the public path while keeping its configuration and subdomain. Deleting it removes the configuration and releases the subdomain. Use stop between working sessions and delete when the remote-access setup is no longer needed or after a suspected exposure.

Tunnel settings that matter for this workload

Open the settings button in the Actions column to reach the Tunnel settings panel. Under Tunnel Details you can rename the tunnel and change the local IP address and port. The following settings are the ones most relevant to a token-protected, streaming agent daemon.

Turn on Is Only Https?

Every request to this daemon carries a bearer token. With Is Only Https? off, the public address answers on both http:// and https://. With it on, a request to http:// is redirected to the same address on https://. Our documentation recommends turning it on for anything that carries logins or private data, and this workload qualifies. Note that a redirect does not undo a token already sent over plain HTTP, so configure every client with the https:// address from the start. Is HTTP/3 Active? is on for new tunnels; turn it off only if a client has trouble with HTTP/3.

Review HTTP Timeout for long streams

HTTP Timeout sets how long the server waits for a response from your local application, from 1 to 600 seconds. Agent turns can take a long time, and SSE subscriptions hold a response open indefinitely by design. Our documentation does not state precisely how this timeout interacts with a response that has started streaming but stays open, so test it: run a long prompt while subscribed through the public URL and see whether the stream is cut. If it is, raise the timeout, and make sure your client reconnects. The daemon documentation describes reconnection with Last-Event-ID within its replay window, which helps a client recover events after a reconnect.

Be careful with Basic Authentication

Basic Authentication? asks visitors for a username and password. HTTP Basic authentication uses the Authorization request header, which is the same header the Qwen daemon uses for its bearer token. A request can normally carry only one Authorization header value, so enabling Basic Authentication on this tunnel is likely to conflict with the daemon's bearer token. We have not confirmed the exact behavior for this combination; treat it as a likely conflict and test it before relying on it. For an additional gate in front of the daemon, prefer the controls below.

Optional defense in depth

🧱 IP Restriction Control which client IP addresses can access the tunnel. Useful when approved clients have stable addresses.
🪪 SSO Providers Visitors sign in with one of your identity providers before they can open the tunnel. Fits browser use of the Web Shell; test whether your API clients can complete it.
🛡️ Web Application Firewall The WAF button in the Actions column opens WAF Setting and shows whether the firewall is not configured, active, or inactive.
📜 Request Log Inspect requests reaching the tunnel. Helpful for confirming that denials happen and spotting unexpected callers.
🗂️ Activity Log and Tunnel Health Review starts, stops, and setting changes, and see health checks for the tunnel.
⏱️ Limits and expiration Expiration Date, Speed Limits, and Bandwidth Limit can stop the tunnel on a date or cap its speed and data.

These controls sit in front of the daemon's own authentication; they do not replace it. Request logs may record request details, so treat them as sensitive operational data.

The Free plan warning page

Our HTTP tunnel documentation has a section titled "The warning page on the Free plan", which describes a warning page shown for HTTP tunnels on that plan. Read that section for the current behavior and any documented way past it. A page intended for browser visitors may affect non-browser API, SDK, or SSE clients differently than browsers, so if you are on the Free plan, test your actual client through the public URL and check whether it receives daemon responses or the warning page. We do not claim a specific outcome beyond what that documentation section states.

The Host header

Your local service receives the host name the visitor used, which is the tunnel address. Some local servers choose behavior by host name. We have not verified whether qwen serve checks the Host header. If the daemon answers locally but rejects or misroutes public requests, open Headers in the tunnel settings and test adding a request header named Host with the value the daemon expects.

Routine operation and troubleshooting

Use a consistent startup sequence

  1. Start the host and confirm network connectivity.
  2. Open the intended project directory.
  3. Load QWEN_SERVER_TOKEN through the approved secret mechanism.
  4. Start qwen serve --require-auth with the required Tool Guard configured.
  5. Prove local denial and authenticated access against the protected sanity-check route.
  6. Confirm the Localtonet client is connected under the intended AuthToken.
  7. Start the existing HTTP tunnel from the Actions column.
  8. Repeat the denial and authenticated checks through the public HTTPS URL.
  9. Use only approved token-aware clients or the documented Web Shell login.

When finishing, stop the Localtonet tunnel first so new remote requests cannot arrive, then stop Qwen Code. Delete the tunnel if the configuration is no longer required.

End-to-end acceptance checklist

  1. The installed Qwen Code version has been recorded and checked against the releases page.
  2. The interactive CLI works with the selected provider.
  3. The daemon starts from the intended project and stays on loopback.
  4. --require-auth is active and the Tool Guard is configured.
  5. A local request to a protected API route without a token is denied; with the token it succeeds.
  6. The event stream is also refused without a token.
  7. The quickstart session, subscription, and prompt sequence works locally.
  8. The HTTP tunnel targets 127.0.0.1:4170 and is running.
  9. Is Only Https? is on.
  10. A public request to the protected route without a token is denied.
  11. An approved client can open a session and stream events through the public URL.
  12. Stopping the tunnel makes the public endpoint unavailable.

The qwen command is not found

Restart the terminal after using the standalone installer. For npm, verify Node.js 22 or later and confirm that npm's global executable directory is on PATH. For Homebrew, confirm that the Homebrew executable directory is available to the current shell. Installing through every available method can hide the underlying path issue.

The installed release is not the one you expected

For exact reproducibility, install the pinned npm package:

npm install -g @qwen-code/qwen-code@0.22.3

If you intentionally use another version, inspect qwen serve --help and read the daemon documentation and release notes for that build. Do not assume a command copied from the moving main-branch document exists in an older executable.

The interactive CLI opens, but prompts fail

Use /auth and confirm the intended provider. Check the provider endpoint, account access, API credential, selected model, quota or billing state, and network reachability. Diagnose this locally; Localtonet is not involved in the terminal workflow.

The daemon does not start

Read the terminal error and the daemon log file before changing settings. Confirm that the installed release supports qwen serve, that interactive provider access works, and that port 4170 is free. If another process holds the port, use the port option from the CLI flags section as shown by qwen serve --help, and update the tunnel's Local port to match.

The sanity-check route returns 404

A 404 is not an authentication result. Recheck the path you copied from the documentation, confirm it matches your installed release, and confirm you are hitting the daemon port. Only an authentication rejection counts as a passed denial test.

The root page loads but the API is denied

This is expected with --require-auth. The Web Shell shell may load at / while its API calls require login. Complete the documented "Logging in to a remote daemon" flow or use a token-aware client. Do not remove authentication to make the page work.

An unauthenticated API request succeeds

Stop the Localtonet tunnel immediately if it is running. Confirm that the daemon was started with --require-auth, that QWEN_SERVER_TOKEN was present in the same process environment, and that you tested a protected API route rather than a static asset. Verify the release and inspect qwen serve --help. Do not continue until an unauthenticated request is denied.

An authenticated request is still denied

Confirm that the client uses the exact bearer format:

Authorization: Bearer YOUR_DAEMON_TOKEN

Check for whitespace introduced while copying the token, confirm the client and daemon use the same value, and confirm the variable was set before the daemon started. If this happens only through the public URL, check whether Basic Authentication? is enabled on the tunnel, since it uses the same header. Avoid printing the token while troubleshooting.

The browser cannot log in to the remote Web Shell

Test the documented login locally on the host first. If it works locally but not remotely, confirm you are using the https:// address, that Is Only Https? is on, that an SSO or IP Restriction rule is not blocking the device, and that the Free plan warning page is not intercepting the flow. Do not remove --require-auth as a workaround.

The Web Shell will not install as an app on a phone

Browsers generally require a secure context to install a site as an app. Open the tunnel's https:// address rather than http://, and follow the "Install the Web Shell as an app" section of the daemon document for your browser.

Local access works, but the public URL does not

Confirm that the Localtonet client is connected under the device token selected by the tunnel and that the tunnel is started, not merely created. If you selected Start anyway while the app was offline, the tunnel goes live only once the app connects. Check that the target is 127.0.0.1 and 4170. If our client runs on another device, its loopback does not reach the Qwen host; move the client to the Qwen host rather than binding Qwen Code to the LAN.

Requests fail after enabling the daemon's own TLS

If qwen serve now serves HTTPS locally, turn on Is SslStream? so our client connects with TLS. If the daemon serves plain HTTP, turn it off. Changing Is SslStream? on a running tunnel restarts it, so the Localtonet app must be connected.

HTTP requests redirect or a client refuses the redirect

With Is Only Https? on, http:// requests are redirected to https://. Some API clients do not follow redirects for POST requests. Configure clients with the https:// address directly.

Streaming stalls or ends during long turns

Test the same subscription locally to separate a Qwen, client, or provider problem from the tunnel path. Through the tunnel, review HTTP Timeout (1 to 600 seconds) and test a higher value if long responses end early. Make sure the client reconnects with Last-Event-ID as described in the daemon documentation. Responsiveness depends on the host, model provider, client, network, and relay; we make no uptime or performance guarantee.

A non-browser client receives an HTML page instead of daemon data

On the Free plan, check the "warning page on the Free plan" section of our HTTP tunnel documentation and confirm whether that page is what your client received. Also check SSO, which may present a sign-in page to clients that cannot complete it.

A client is blocked unexpectedly

Review IP Restriction rules, SSO configuration, and WAF state in the tunnel settings, then use the Request Log to see how the request was handled and the Activity Log to see recent setting changes.

A WebSocket-based feature does not connect

WebSocket connections pass through HTTP tunnels. Confirm the feature works locally, then confirm the client uses the https:// address so its WebSocket upgrade uses a secure scheme.

The wrong project appears

Stop the public tunnel before investigating. Confirm the directory from which the daemon was started and review registered workspaces. The first registered workspace is the primary default for requests that omit a working directory. Restart from the intended project, verify locally, then restart the tunnel.

Multiple users interfere with permission prompts

This matches the documented first-responder permission model and the shared qwen --acp child per workspace runtime. Restrict access to a coordinated trusted group and agree on who approves tools. A shared daemon session is not tenant isolation.

Remote access stops unexpectedly

Check three independent states: the Qwen daemon process, the Localtonet client connection, and the tunnel's running state. Host sleep, terminal closure, provider failure, an Expiration Date, or a bandwidth limit can interrupt the workflow. The Activity Log and Tunnel Health views help identify tunnel-side causes, and the daemon log helps with Qwen-side causes.

Respond to possible credential disclosure

Stop the tunnel and terminate the daemon. Rotate the exposed credential through the system that owns it: the daemon bearer token for remote access, the provider credential for model access, and the Localtonet AuthToken for the device. Log out of the Web Shell on any device that stored a login. Delete and recreate the tunnel if you also want a new public address, because the subdomain persists until deletion.

Frequently asked questions

Which Qwen Code version does this tutorial use?

The baseline is Qwen Code v0.22.3, released on 28 August, installed with @qwen-code/qwen-code@0.22.3. Check the releases page for a newer stable tag before installing, and verify the installed version and qwen serve --help before continuing.

What does qwen serve do?

qwen serve runs Qwen Code as an experimental HTTP daemon. Compatible clients share agent functionality over HTTP and SSE, and the daemon serves a built-in Web Shell at its root unless started with --no-web.

What is the default qwen serve address?

The documented default is http://127.0.0.1:4170/. Loopback keeps the daemon local to the host unless a separate connectivity layer such as a Localtonet tunnel forwards requests to it.

How do I require authentication and test it correctly?

Set a unique token as QWEN_SERVER_TOKEN in the daemon environment and start qwen serve --require-auth. Test a documented protected API route, such as the quickstart sanity-check route, rather than the root page, and confirm it is denied without the Authorization: Bearer header and succeeds with it.

Can I use the Web Shell through the public URL?

Yes, as a documented scenario. The current daemon document covers remote Web Shell and phone access, authentication, HTTPS for cross-device use, installing the Web Shell as an app, and logging in to a remote daemon. Test the login locally against --require-auth first, then through the tunnel's HTTPS address with Is Only Https? on.

Do I need to enable TLS in Qwen Code if I use Localtonet?

Not for this same-host design. Our HTTP tunnel serves HTTPS with a certificate we provide and renew, and TLS ends at the Localtonet server, so the daemon can stay on plain HTTP on loopback. If you do enable the daemon's own TLS, turn on Is SslStream?; if it must present its own certificate to clients, use a TLS tunnel instead.

Which Localtonet tunnel type and settings should I use?

Use an HTTP tunnel targeting 127.0.0.1 on port 4170, turn on Is Only Https?, review HTTP Timeout for long streams, and consider IP Restriction, SSO, WAF, and Request Log as extra layers. Avoid Basic Authentication, which likely conflicts with the daemon's bearer header.

Will SSE streams work through the tunnel?

SSE is ordinary HTTP, so it travels through an HTTP tunnel, and WebSockets pass through too. Because HTTP Timeout controls how long the server waits for your local application, test a long turn through the public URL, adjust the timeout between 1 and 600 seconds if needed, and use a client that reconnects with Last-Event-ID.

Does Localtonet replace Qwen Code authentication?

No. Localtonet provides the connectivity path and optional access controls in front of it. Qwen Code remains responsible for authenticating its clients. Require daemon authentication and prove unauthenticated denial before starting the tunnel.

Do I need router port forwarding or a public IP address?

No. Our Localtonet client establishes an outbound relay connection, so the HTTP tunnel does not require inbound router port forwarding, firewall changes, VPN setup, or a public IP address.

Does the public address change when I restart the tunnel?

No. An HTTP tunnel keeps its subdomain until you delete the tunnel; stopping and starting does not change it. Delete and recreate the tunnel if you need a new address.

Is qwen serve suitable for unattended production use?

Qwen Code still describes daemon mode as experimental. Read the Stage 1.5+ runtime guarantees, Stage 1 scope boundaries, durability model, and default deployment threat model for your release, and configure the required external Tool Guard, before relying on it for unattended or business-critical work.

Connect a verified Qwen Code daemon with Localtonet

Pin and verify Qwen Code, keep the daemon on 127.0.0.1:4170, require its bearer token, prove denial on a protected API route, and then create an HTTPS-only Localtonet HTTP tunnel for your approved clients and Web Shell devices.

Get Started Free →

Corrections & updates

Substantive changes approved by the Localtonet editorial team are listed transparently below.

Updated the remote Web Shell guidance, daemon API walkthrough, version baseline, and Localtonet HTTP tunnel steps, and added notes on timeouts, HTTPS-only, and access controls.

Reviewed and updated for accuracy and completeness.

Localtonet is a secure multi-protocol tunneling and proxy platform designed to expose localhost, devices, private services, and AI agents to the public internet supporting HTTP/HTTPS tunnels, TCP/UDP forwarding, mobile proxy infrastructure, file server publishing, latency-optimized game connectivity, and developer-ready AI agent endpoint exposure from a single unified control plane.

Support