26 min read

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.

A local Qwen Code server connects through a Localtonet tunnel to a remote browser.
The workflow keeps Qwen Code on the host machine while a Localtonet tunnel provides remote access.
AI Coding Agents ยท Qwen Code ยท Localtonet ยท 2026

Run one local coding-agent session and reach it securely from approved remote clients

Qwen Code is an open-source coding agent that normally runs in a terminal, but its experimental qwen serve mode can expose a shared agent session through HTTP and Server-Sent Events. In this guide, we install Qwen Code using an officially documented method, configure model authentication, verify the interactive CLI, start the browser-based Web Shell on its loopback address, and test the daemon locally. We then connect that working local service to a Localtonet HTTP tunnel so it can be reached without inbound router port forwarding, firewall changes, VPN setup, or a public IP address. Because an AI coding agent may read files, modify a workspace, execute tools, and consume model tokens, the remote-access section treats authentication and limited workspace scope as essential rather than optional.

๐Ÿ”’ Authenticated shared-agent access ๐ŸŒ HTTP and Server-Sent Events โšก Local verification before tunneling

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 same project also documents headless execution for scripts, integrations for supported editors, SDKs, desktop applications, and an experimental daemon mode.

The daemon starts with qwen serve. It provides an HTTP service using the Agent Client Protocol, or ACP, and streams events with Server-Sent Events, commonly abbreviated as SSE. Instead of every interface starting a separate Qwen Code subprocess, multiple compatible clients can connect to one daemon and participate in a shared session. The official daemon documentation describes clients such as IDE integrations, web interfaces, CI scripts, and custom command-line applications.

A built-in Web Shell is served from the root of the daemon. The documented default URL is http://127.0.0.1:4170/. The Web Shell and API use the same origin, so this basic workflow does not require a second application port. The default loopback address is deliberately local: software on the same machine can connect, while another device cannot connect directly through the LAN or internet.

๐Ÿค– One shared agent Compatible clients can connect to the same daemon instead of independently spawning Qwen Code processes.
๐Ÿ–ฅ๏ธ Built-in Web Shell The daemon serves its browser interface at the root URL on the same HTTP origin as its API.
๐Ÿ“ก SSE streaming Agent events are delivered through Server-Sent Events, including reconnection behavior described by the project.
๐Ÿ“ Workspace-aware operation The daemon can register one or more workspaces. The first registered workspace is the primary default.
๐Ÿ” Permission mediation Connected clients can see tool permission requests, and the first client to respond determines the result.
๐ŸŒ Outbound tunnel connectivity Our Localtonet client establishes an outbound connection and gives the local HTTP service a public HTTPS address.

Localtonet does not install, configure, or authenticate Qwen Code for you. The Qwen Code daemon remains on your machine and retains access to the workspace and model provider you configure. Our role begins after the service works locally: the Localtonet client forwards requests from a public HTTP endpoint to the local daemon.

This separation is useful for diagnosis. If the Web Shell does not load at 127.0.0.1:4170, the problem is local and should be fixed before a tunnel is created. If local access works but the public address does not, the investigation can focus on the Localtonet client, tunnel state, selected device, and target configuration.

Experimental service boundary

Qwen Code labels qwen serve as experimental. Its daemon documentation has historically described it as appropriate for developer prototyping and local single-user or small-team collaboration, rather than promising production-grade behavior for long-running, network-flaky, or very large multi-client deployments. Review the documentation matching your installed release before treating it as a production service.

Prerequisites and decisions to make first

Prepare the host, project, model access, and security boundary before installation. The host must remain powered on while Qwen Code is needed remotely. The Qwen Code daemon, the Localtonet client, and the tunnel must all be running for the public address to work.

Choose the machine and workspace

Install Qwen Code on the computer that holds, or is allowed to reach, the project you want the agent to work with. Run it under an operating-system account with only the filesystem and command permissions that the workflow needs. Avoid starting an internet-accessible coding agent under an unnecessarily privileged administrator or root account.

Use a dedicated test repository for the first setup. Commit or back up important work before allowing an agent to modify it. Version control makes proposed file changes easier to inspect and reverse, but it does not protect untracked secrets, external systems, databases, or commands with side effects.

Choose an installation path

Qwen Code officially documents three normal installation paths. The standalone installer is the quickest path on Linux, macOS, and Windows. npm is appropriate when Node.js 22 or later is already installed and available on PATH. Homebrew is supported on macOS and Linux.

Installation method Supported environment Important requirement
Standalone installer Linux, macOS, or Windows using the matching official script Restart the terminal afterward if qwen is not immediately on PATH
npm A system where npm and Node.js are available Node.js 22 or later
Homebrew macOS or Linux with Homebrew installed A working brew installation
Offline release archive An environment where the archive is transferred manually The project documents an archive installer option and requires SHA256SUMS beside the archive

Prepare model-provider access

Qwen Code requires a model provider. On first launch, its provider menu can offer Alibaba ModelStudio choices, supported third-party providers, and a custom provider for a local server, proxy, or otherwise unsupported provider. The correct endpoint, model, API key, account permissions, and billing arrangement depend on the provider you choose.

Keep provider credentials out of terminal history, screenshots, source control, Qwen instruction files, and this article's example commands. The provider credential is separate from a Qwen daemon bearer token and separate again from a Localtonet device token. Each credential has a different purpose and should be stored and rotated independently.

Prepare Localtonet

You also need a Localtonet account and the Localtonet client on the device that will run, or can locally reach, Qwen Code. A Localtonet device authentication token identifies that client. Tokens are device-specific and should never be pasted into documentation, issue reports, chat transcripts, or shared configuration examples.

Relay server and region choices can vary. Select an available value from the current Localtonet dashboard rather than copying a server code from an old tutorial. Plan availability and specific options can also vary, so use the choices displayed for your account.

Remote access expands the trust boundary

A shared coding-agent session is not equivalent to publishing a static website. It may expose conversation history, diffs, tool prompts, workspace information, and actions backed by model-provider credentials. Configure Qwen daemon authentication before creating a public tunnel, limit the workspace, keep approval controls conservative, and share access only with trusted users.

Install Qwen Code using an official method

Choose exactly one normal installation path. Running multiple installers is unnecessary and can leave different qwen executables on PATH. If a previous installation exists, first identify which executable your shell resolves and follow the project's current upgrade or uninstall guidance for that installation type.

Option 1: standalone installer on Linux or macOS

In a terminal, run the official standalone installation command:

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

This downloads the installation script and passes it to the shell. Piping a remote script directly into a shell is convenient, but it means you are trusting its current contents. In controlled environments, review the script and your organization's software-installation policy before executing it.

Option 2: standalone installer on Windows

Open PowerShell and run the documented Windows command:

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

Restart PowerShell or your terminal application after installation if the qwen command is not found. This lets updated environment variables and PATH entries take effect.

Option 3: install globally with npm

Confirm that Node.js 22 or later and npm are already available, then install the latest published Qwen Code package:

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

The output from node --version must represent Node.js 22 or later. If the global install succeeds but the command remains unavailable, the usual issue is that npm's global executable directory is not on the current shell's PATH. Correct the npm environment rather than repeatedly installing the package.

Option 4: install with Homebrew

On macOS or Linux with a working Homebrew installation, run:

brew install qwen-code

Whichever method you choose, close and reopen the terminal if necessary. Then ask the executable for its help output:

qwen --help

A rendered help response confirms that the shell can resolve and execute Qwen Code. It does not yet prove that a provider is configured, the project is trusted, or the daemon can start.

Keep version-specific behavior in mind

Qwen Code is actively developed, and daemon behavior can change between releases. Record the installed version in your private operational notes and consult the documentation corresponding to that release when a flag, route, or interface differs from this workflow. Do not assume an old alpha limitation or a newer feature applies to every installed build.

Configure authentication and verify the interactive agent

Qwen Code installation, authentication, startup, and interactive verification flow.
Authentication should be completed before using an interactive exchange to verify the agent.

Before starting a network service, verify the simpler terminal workflow. This isolates installation, provider authentication, project access, and basic model operation from HTTP and tunneling concerns.

1

Open the intended project directory

Change into a test project that the operating-system account may safely read and modify. Starting Qwen Code from the correct directory reduces the chance of giving it context from an unrelated or overly broad filesystem location.

2

Launch the interactive terminal interface

Run qwen. On first launch, Qwen Code can prompt you to select and connect a model provider. Follow the provider-specific prompts without copying secrets into source-controlled files.

3

Open authentication settings when needed

Inside the Qwen Code session, use /auth to configure or change the provider and its credential. Available choices depend on the installed release and provider support.

4

Send a read-only verification prompt

Begin with a low-risk request such as asking what the project does or requesting a summary of its repository layout. Confirm that the response concerns the intended project and that provider authentication succeeds.

5

Review permission behavior

Observe how the installed version asks for approval before tool use. Do not select a broadly permissive mode merely to make initial testing faster. Exit the interactive session after confirming normal operation.

The core commands for this check are:

cd /path/to/your-project
qwen

Replace the example project path with a real local path. Once the interface opens, use:

/auth

Successful verification means the application launches, the intended provider is configured, a harmless prompt receives a response, and the agent is operating in the intended workspace. If any of these checks fail, fix them before moving on to qwen serve.

Start and verify the qwen serve daemon locally

The qwen serve process running beside a browser opened to localhost.
Verify the daemon through localhost before creating any public tunnel.

Start the daemon from the workspace you want to expose:

cd /path/to/your-project
qwen serve

The official daemon documentation identifies http://127.0.0.1:4170/ as the default Web Shell address. Open that exact URL in a browser on the same computer:

http://127.0.0.1:4170/

You can also ask Qwen Code to open the Web Shell automatically:

qwen serve --open

For an API-only daemon without the built-in Web Shell, the documented switch is:

qwen serve --no-web

The API-only mode is not the best choice for the browser-focused workflow in this guide. Use it only when a compatible client will connect directly to the daemon protocol and you have verified that client's requirements.

Local verification checklist

Confirm all of the following while still testing through the loopback address:

  • The daemon process remains running and does not exit with a configuration or provider error.
  • The browser can load the Web Shell from 127.0.0.1:4170.
  • A harmless text prompt receives a streamed response.
  • The session points to the intended workspace, not the user's home directory or another repository.
  • Permission requests are visible and can be accepted or rejected as expected.
  • Stopping the daemon makes the local page unavailable, proving that the test is reaching this process rather than a cached or unrelated service.

The loopback default is helpful when Localtonet runs on the same computer. Our client can target 127.0.0.1 without changing Qwen Code to listen on every network interface. This keeps the daemon unavailable directly from the LAN while the public access path is handled through the outbound tunnel.

Multiple clients and session behavior

Under the daemon's documented default single-session scope, clients that target the same workspace collaborate on the same ACP session. That can include shared conversation state, file diffs, and permission prompts. When the agent asks to use a tool, all connected clients may see the request, and the first response wins.

This behavior is useful for intentional pair work, but it also means the service should not be treated as a multi-tenant application. A collaborator may observe or affect the same agent session. Establish who is allowed to answer permission prompts and avoid connecting untrusted users to the same daemon.

Secure Qwen Code before public exposure

The default loopback deployment does not need authentication for purely local access. That assumption changes when requests can arrive through a public URL. Qwen Code documents bring-your-own bearer-token support through the QWEN_SERVER_TOKEN environment variable, as well as the --token and --require-auth controls.

Generate a strong, unique secret using an approved password manager or secret-management system. Set it in the daemon process environment without committing it to the repository. The exact secret injection method depends on your operating system, shell, service manager, and deployment policy, so this guide intentionally does not place a reusable credential in a command.

Require authentication for shared-host or tunneled use. Then verify that your intended browser interface or ACP client can supply the bearer token correctly before relying on it remotely. Do not assume that a client supports authentication merely because it can connect to an unauthenticated loopback daemon.

Never tunnel a tokenless coding daemon

A public URL can be discovered, copied, logged, or shared unintentionally. URL obscurity is not authentication. Configure Qwen Code's supported bearer-token controls, test that unauthenticated requests are rejected, and only then start the Localtonet tunnel.

Use a narrow workspace

Run the daemon from a dedicated project directory and avoid registering broad directories unless the workflow genuinely requires them. The official daemon supports repeated --workspace options for multiple isolated workspace runtimes under one listener, with the first workspace acting as the primary default. More workspaces increase the material reachable through one service, so add them deliberately.

Keep approval controls conservative

A model response is not a substitute for human authorization. Commands can delete files, change dependencies, contact external systems, or expose data through tool output. Review requested actions and diffs before approving them. Be especially careful when more than one client is connected because the first permission response determines the result.

Protect model cost and side-effect endpoints

Some daemon operations can trigger additional model calls. The official documentation specifically warns that session recap requests are pure-cost side queries and historically lacked a per-route rate limit in the documented v1 behavior. Authentication reduces the risk of an unknown client repeatedly consuming model tokens, but trusted clients should also avoid uncontrolled request loops.

Separate secrets by purpose

Secret Purpose Handling rule
Model-provider credential Authorizes Qwen Code to call the selected model service Store according to the provider's supported method and never expose it to remote users
Qwen daemon bearer token Authenticates clients connecting to qwen serve Use a strong unique value, require it for tunneled access, and rotate it after suspected disclosure
Localtonet device token Identifies and authenticates the device running our client Keep it device-specific and never place it in screenshots, articles, repositories, or client-facing instructions

Expose the verified daemon with a Localtonet HTTP tunnel

Remote browser traffic reaches qwen serve through a Localtonet HTTP tunnel.
The public endpoint routes authenticated requests through Localtonet to the locally verified qwen serve daemon.

Once Qwen Code works at http://127.0.0.1:4170/ and daemon authentication has been verified, add remote connectivity as a separate layer. HTTP is the appropriate Localtonet tunnel family because the daemon serves a browser interface and ACP traffic over HTTP with SSE.

The Localtonet client establishes an outbound connection to a Localtonet relay server. This means you do not need inbound router port forwarding, a public IP address, firewall changes, or VPN setup for this tunnel workflow. The assigned public HTTPS address forwards to the local Qwen Code target while the selected client is connected and the tunnel is running.

1

Install and run the Localtonet client

Install our client on the same computer as Qwen Code, or on a device that can reach the daemon's local address. For the default loopback target in this guide, the client must run on the Qwen Code host because 127.0.0.1 always refers to the current device.

2

Authenticate or select the device

Use the device-specific authentication token through the supported Localtonet client and dashboard workflow. Keep the token private. Confirm that the intended device appears connected before configuring the tunnel.

3

Select an available relay server

Choose a relay server or region currently offered in the dashboard. Do not copy a server code from another account or an older guide because availability can vary.

4

Create an HTTP tunnel to the local daemon

Configure the HTTP tunnel's local target as IP address 127.0.0.1 and port 4170. Select the connected device that is running Qwen Code. HTTP and File Server tunnels can use a generated subdomain, a selected subdomain where supported, or a custom domain, but exact domain and DNS options must be checked in the current dashboard and documentation.

5

Start the tunnel

Creating a tunnel does not make it active. Press Start, then wait until the tunnel is running and the selected Localtonet device remains connected.

6

Test the assigned public HTTPS address

Open the assigned address from a separate browser or network. Confirm that Qwen authentication is required, authenticate using the client mechanism supported by your Qwen Code release, and send only a harmless test prompt. Stop or delete the tunnel when remote access is no longer required.

For the current dashboard workflow and available options, consult our Localtonet HTTP tunnel documentation. The exact relay choices, domain options, and plan-dependent capabilities visible to you should take precedence over screenshots or values from older tutorials.

Why the target stays on 127.0.0.1

When Qwen Code and our client run on the same machine, Localtonet can forward to the daemon's loopback listener directly. You do not need to change Qwen Code to bind to every network interface. If our client runs on another device, that device cannot reach the Qwen host's 127.0.0.1; use a supported architecture that is explicitly secured and documented rather than guessing a bind flag.

Validate the complete request path

Test from outside the Qwen Code host after the tunnel starts. A useful validation sequence is:

  1. Open the Localtonet public HTTPS address.
  2. Verify that an unauthenticated request cannot use the daemon.
  3. Authenticate with the Qwen daemon's supported client flow.
  4. Confirm that the expected project or workspace is selected.
  5. Send a read-only prompt and observe the streamed response.
  6. Trigger no destructive tools during the connectivity test.
  7. Disconnect the remote client and confirm that the local daemon remains healthy.
  8. Stop the Localtonet tunnel and verify that the public address no longer reaches the service.

A tunnel is available only while the selected Localtonet client is connected and the tunnel is running. Qwen Code must also remain running. If any one of those three components stops, remote access ends.

Routine operation and troubleshooting

A safe startup sequence

Use the same order each time so failures are easy to locate:

  1. Start the host and confirm network access.
  2. Open the intended project directory.
  3. Load the Qwen daemon bearer token through your approved secret mechanism.
  4. Start qwen serve.
  5. Verify http://127.0.0.1:4170/ locally.
  6. Start the Localtonet client and confirm that the correct device is connected.
  7. Start the existing HTTP tunnel.
  8. Test authentication and a harmless prompt through the public HTTPS address.

Reverse the exposure-related portion when finishing. Stop the tunnel first so new remote requests cannot arrive, then stop Qwen Code. If access is no longer needed, delete the tunnel rather than leaving an unused configuration available for accidental restart.

The qwen command is not found

Restart the terminal after using the standalone installer. If npm was used, verify Node.js is version 22 or later and determine whether npm's global executable location is on PATH. If Homebrew was used, verify that the Homebrew executable directory is available to the current shell. Avoid installing through every method because that can hide the underlying path problem.

The interactive CLI opens, but prompts fail

Run /auth and confirm that the intended provider is selected. Check provider credentials, account access, configured model availability, network reachability, and provider-specific quotas or billing. Do not debug this through Localtonet because a failure in the local interactive CLI is not caused by the tunnel.

The daemon does not start

Read the terminal error before changing settings. Confirm that the installed Qwen Code release supports qwen serve, that provider configuration works in interactive mode, and that port 4170 is not already occupied. This article does not invent a port-changing flag because the supplied evidence only establishes the documented default address and port. Use the daemon documentation for your installed version if a different port is required.

The Web Shell does not load locally

Make sure the daemon process is still running and test the exact default URL, including http, loopback address, and port:

http://127.0.0.1:4170/

If you started the daemon with --no-web, the browser Web Shell is intentionally disabled. Restart without that flag for this workflow. Browser extensions, local proxies, and endpoint-security software can also affect a local request, so compare browser behavior with a direct local HTTP test tool available in your environment.

Local access works, but the public URL does not

Confirm that the Localtonet client is connected under the device selected by the tunnel. Verify that the tunnel is actually started, not merely created. Check that the tunnel family is HTTP and that the target remains 127.0.0.1:4170 when our client runs on the Qwen host. Also confirm that the assigned public address is the current address shown in the dashboard.

If Localtonet runs on another computer, 127.0.0.1 points to that other computer rather than the Qwen host. Move our client to the Qwen host for the loopback design used here. Do not expose Qwen Code broadly on the LAN by guessing undocumented bind options.

The page loads, but streaming stalls or reconnects

The daemon uses SSE, which keeps an HTTP response open while events are delivered. Test the local Web Shell first to distinguish a Qwen process or provider problem from the remote path. Then compare a different browser or network. The Qwen daemon documents reconnect support using Last-Event-ID within its replay window, but a specific client still needs to implement compatible reconnection behavior.

Do not claim a performance or uptime guarantee for either component. Actual responsiveness depends on the Qwen host, selected model provider, client, network path, active session, and available relay option.

Authentication works locally but not remotely

Confirm that the remote interface knows how to provide the Qwen bearer token. A browser opening a URL cannot automatically infer a secret stored on the host. Client authentication behavior can vary by Qwen Code release and interface, so verify it against the current daemon documentation. Never work around an incompatible client by disabling daemon authentication on a public tunnel.

The wrong project appears

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

Multiple users interfere with permission prompts

This follows the documented first-responder permission model. Every connected client can see a permission request, and the first answer wins. Limit access to a coordinated trusted group, agree on who controls approvals, or use separate daemon instances and workspaces where your installed release and operating model support that design. Do not present one shared session as isolation between mutually untrusted users.

Remote access stopped unexpectedly

Check the three independent lifecycle states: the Qwen daemon process, the Localtonet client connection, and the tunnel's running state. A tunnel configuration can still exist while stopped. Likewise, a running tunnel cannot reach a daemon that has exited. Host sleep, terminal closure, provider failures, and normal client shutdown can interrupt the workflow.

Logging and incident response

Avoid collecting secrets in screenshots or copied logs. If a model-provider key, Qwen bearer token, or Localtonet device token may have been exposed, stop the tunnel, terminate the daemon, and rotate the affected credential through its owning system. A Localtonet device token does not replace the Qwen daemon token, and rotating one does not rotate the others.

Frequently asked questions

What does qwen serve do?

qwen serve runs Qwen Code as an experimental local HTTP daemon. It supports shared agent access through HTTP and Server-Sent Events using ACP, and it serves a built-in Web Shell at the root URL unless started with --no-web.

What is the default qwen serve address and port?

The official daemon documentation identifies http://127.0.0.1:4170/ as the default Web Shell URL. The loopback address means it is reachable only from the same machine unless a separate access layer, such as a correctly secured Localtonet HTTP tunnel, forwards requests to it.

Which Localtonet tunnel type should I use for qwen serve?

Use a Localtonet HTTP tunnel because Qwen Code exposes its Web Shell and ACP service over HTTP with SSE. When our client runs on the same machine as Qwen Code, configure the local target as 127.0.0.1 on port 4170.

Does Localtonet replace Qwen Code authentication?

No. Localtonet supplies the public connectivity path, while Qwen Code must authenticate clients at the application layer. Configure the daemon's supported bearer-token controls and confirm that unauthenticated requests are rejected before starting the public tunnel.

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

No. Our Localtonet client establishes an outbound connection to a relay server. The HTTP tunnel can provide a public address without inbound router port forwarding, firewall changes, VPN setup, or a public IP address.

Can several people use the same Qwen Code session?

The daemon is designed to let multiple compatible clients share an agent session. Under its documented default single-session scope, clients targeting the same workspace can share conversation state, diffs, and permission prompts. This is collaboration, not tenant isolation, so only trusted and coordinated users should connect.

Must the Localtonet client run on the same computer as Qwen Code?

It must run on the same computer for the exact 127.0.0.1:4170 target used in this guide. Loopback always refers to the machine on which the connecting application runs. A client on another device cannot reach the Qwen host through that address.

Is qwen serve suitable for an unattended production service?

Qwen Code describes daemon mode as experimental, and its documentation has scoped early releases toward developer prototyping and local single-user or small-team collaboration. Review the guarantees and limitations for your exact installed release before using it for long-running, network-flaky, high-volume, or business-critical workloads.

Connect your verified Qwen Code daemon with Localtonet

Install and authenticate Qwen Code first, confirm qwen serve locally at 127.0.0.1:4170, require a daemon bearer token, and then use our HTTP tunnel to provide controlled remote access without inbound port forwarding.

Get Started Free โ†’

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