Skip to main content

Web-based terminal: run any shell command in a PTY, accessed through the browser over WebSocket.

Project description

tunnelterm

A web-based terminal: spawn any shell command in a real PTY and interact with it from the browser over WebSocket.

  • Password-protected (per-IP rate limited)
  • Single-active-session per token
  • Origin allow-list for the WebSocket handshake
  • Token TTL + LRU eviction
  • Themes, fonts, search, web-links, WebGL renderer
  • Persistent preferences in the browser

Install

uv tool install tunnelterm
# or
uv pip install tunnelterm

Run

--command is required. Examples:

TUNNELTERM_PASSWORD=hunter2 tunnelterm --command bash
TUNNELTERM_PASSWORD=hunter2 tunnelterm --command "zsh -l"
TUNNELTERM_PASSWORD=hunter2 tunnelterm --command htop --port 4242

Open http://127.0.0.1:4200 and log in with the password.

CLI options

Option Description Default
--command Command to run in the PTY. Required.
--host Host to bind to 127.0.0.1
--port Port to bind to 4200
--password-env Env var name to read the password from TUNNELTERM_PASSWORD
--config Path to TOML config file ~/.config/tunnelterm/config.toml
--allowed-origin Allowed Origin header (repeat to allow multiple) accept all
--log-level Log level: DEBUG, INFO, WARNING, ERROR INFO
--version Print version and exit

Environment variables

Variable Description
TUNNELTERM_PASSWORD Password for authentication (REQUIRED)
TUNNELTERM_HOST Bind host
TUNNELTERM_PORT Bind port
TUNNELTERM_COMMAND PTY command (if --command not given)
TUNNELTERM_ALLOWED_ORIGINS Comma-separated Origin allow-list
LOG_LEVEL Log level fallback

Config file

~/.config/tunnelterm/config.toml:

password = "hunter2"
command = "bash"
host = "127.0.0.1"
port = 4200
allowed_origins = ["https://terminal.example.com"]

chmod 600 is recommended — tunnelterm logs a warning if the file is group- or world-readable.

Behind nginx with HTTPS

Plaintext ws:// is fine for 127.0.0.1 only. For any other deployment, terminate TLS at a reverse proxy. Minimal nginx example:

server {
    listen 443 ssl http2;
    server_name terminal.example.com;

    ssl_certificate     /etc/letsencrypt/live/terminal.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/terminal.example.com/privkey.pem;

    location / {
        proxy_pass http://127.0.0.1:4200;
        proxy_http_version 1.1;
        proxy_set_header Host              $host;
        proxy_set_header X-Real-IP         $remote_addr;
        proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Upgrade           $http_upgrade;
        proxy_set_header Connection        "upgrade";
        proxy_read_timeout 1h;
    }
}

Then run tunnelterm with --allowed-origin https://terminal.example.com.

Systemd

sudo cp systemd/tunnelterm.service /etc/systemd/system/
# Edit User=, WorkingDirectory=, and ExecStart=.
sudo mkdir -p /etc/tunnelterm
sudo cp systemd/env.example /etc/tunnelterm/env
sudo chmod 600 /etc/tunnelterm/env
sudo $EDITOR /etc/tunnelterm/env  # set TUNNELTERM_PASSWORD

sudo systemctl daemon-reload
sudo systemctl enable --now tunnelterm
sudo journalctl -u tunnelterm -f

Security notes

  • Tokens are sent via Sec-WebSocket-Protocol (not the URL), so reverse-proxy access logs do not capture them.
  • Each token may only be active in one WebSocket connection at a time.
  • Tokens expire after 24h by default; LRU-evicted at 64 outstanding.
  • Five failed auth attempts in 15min lock the source IP out for 5min.
  • Origin allow-list prevents cross-site WebSocket hijacking.
  • All HTTP responses ship CSP, X-Content-Type-Options, X-Frame-Options.
  • xterm assets are vendored locally; no third-party CDN trust.

Development

uv sync
uv run pytest
uv run ruff check
uv run pyright

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tunnelterm-0.1.0.tar.gz (151.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tunnelterm-0.1.0-py3-none-any.whl (149.5 kB view details)

Uploaded Python 3

File details

Details for the file tunnelterm-0.1.0.tar.gz.

File metadata

  • Download URL: tunnelterm-0.1.0.tar.gz
  • Upload date:
  • Size: 151.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tunnelterm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3c73ea973ed1405e987d3c1192db390c830cdd0d62e9bbcec4678a167c3064c6
MD5 f867ca66b96d1a7cb7c739d07a1a1f59
BLAKE2b-256 92a09e927d9d39718ac4521b28e9e3641df3408f62660a7449f8b9cb7b819429

See more details on using hashes here.

Provenance

The following attestation bundles were made for tunnelterm-0.1.0.tar.gz:

Publisher: ci.yml on nimitbhardwaj/tunnelterm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tunnelterm-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tunnelterm-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 149.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tunnelterm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 40cdbf2523dd4805ee1d0acab321d21d6174a6790655f77fb77adcf96cac09a8
MD5 4c2e941ba9e4754681fb6a3defb17c87
BLAKE2b-256 a0eb2096eafe786de8432d3d530777063705f8a6477eb492aa5e39e829eb862a

See more details on using hashes here.

Provenance

The following attestation bundles were made for tunnelterm-0.1.0-py3-none-any.whl:

Publisher: ci.yml on nimitbhardwaj/tunnelterm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page