Skip to main content

Command Palette

Search for a command to run...

CommandHub – All in One Command & Tool Platform Using Streamlit

Updated
7 min read

Managing system commands and tools can sometimes feel like juggling too many things at once. You open multiple terminals, run commands, monitor outputs, and often lose track of what’s happening. To make this process easier, I built CommandHub – an all-in-one centralized platform powered by Streamlit.


🌟 What is CommandHub?

CommandHub is a web-based dashboard where you can:

  • Run essential system commands directly from your browser

  • Monitor outputs in real-time

  • Manage different tools without switching between multiple terminals

  • Have everything in one simple and clean interface

Think of it as a control center for your system operations.


🛠️ Tech Stack

  • Streamlit → For creating the interactive web dashboard

  • Python (subprocess/os modules) → For executing system commands safely

  • Docker (optional) → To containerize and run the platform anywhere


🚀 Features

✔ Execute system commands from the browser
✔ Display live command outputs
✔ Add and manage frequently used tools in one place
✔ User-friendly dashboard (no need to remember all commands)
✔ Secure and extendable


🔧 How It Works

  1. Start the Streamlit app → It runs locally or inside Docker.

  2. Open the browser → Use the CommandHub dashboard.

  3. Type/choose a command → Press execute.

  4. See real-time output directly on the web page.


📌 Use Cases

  • Developers who run common commands daily (git, docker, kubectl, etc.)

  • Sysadmins monitoring services and processes

  • Beginners learning Linux commands without being overwhelmed by the terminal

  • Teams who want a shared command execution panel


Step-by-Step: Build & Demo CommandHub


1) Prerequisites

Make sure you have:

  • Git installed and logged in (git --version)

  • Python 3.8+ (I use 3.10)

  • pip

  • Docker (optional, for container run)

  • Streamlit will be installed in the venv


2) Create project folder & virtualenv

Open terminal (Linux/macOS) or PowerShell (Windows) and run:

Linux / macOS:

mkdir commandhub
cd commandhub
python3 -m venv venv
source venv/bin/activate

Windows (PowerShell):

mkdir commandhub
cd commandhub
python -m venv venv
.\venv\Scripts\Activate.ps1

3) Create the files (copy & paste into files)

app.py

Create app.py and paste:

# app.py
import streamlit as st
import subprocess
import json
import os
import shlex
from pathlib import Path

st.set_page_config(page_title="CommandHub", layout="wide")
st.title("⚡ CommandHub — Run & Save System Commands")

DATA_FILE = Path("saved_commands.json")
# safety blacklist (basic)
DISALLOWED = ["rm -rf /", ":(){:|:&};:", "reboot", "shutdown", "mkfs", "dd if="]

def load_saved():
    if DATA_FILE.exists():
        try:
            return json.loads(DATA_FILE.read_text())
        except Exception:
            return {}
    return {}

def save_command(name, cmd):
    data = load_saved()
    data[name] = cmd
    DATA_FILE.write_text(json.dumps(data, indent=2))

def delete_command(name):
    data = load_saved()
    if name in data:
        data.pop(name)
        DATA_FILE.write_text(json.dumps(data, indent=2))

def sanitize(cmd):
    lowered = cmd.lower()
    for bad in DISALLOWED:
        if bad in lowered:
            return False, f"Command contains disallowed pattern: {bad}"
    return True, ""

# Predefined common commands (cross-platform)
is_windows = os.name == "nt"
COMMON = {
    "List files": "dir" if is_windows else "ls -la",
    "Current directory": "cd" if is_windows else "pwd",
    "Disk usage": "wmic logicaldisk get size,freespace,caption" if is_windows else "df -h",
    "Processes": "tasklist" if is_windows else "ps aux",
    "Docker ps": "docker ps -a",
}

st.sidebar.header("Saved Commands")
saved = load_saved()
if saved:
    for name, cmd in saved.items():
        cols = st.sidebar.columns([3,1])
        cols[0].write(f"**{name}**  \n`{cmd}`")
        if cols[1].button("Run", key=f"run_{name}"):
            st.session_state["run_cmd"] = cmd
        if cols[1].button("Del", key=f"del_{name}"):
            delete_command(name)
            st.experimental_rerun()
else:
    st.sidebar.write("No saved commands yet.")

st.sidebar.markdown("---")
st.sidebar.header("Save a Command")
with st.sidebar.form("save_form", clear_on_submit=True):
    cmd_name = st.text_input("Name (short)", "")
    cmd_text = st.text_input("Command", "")
    submitted = st.form_submit_button("Save")
    if submitted:
        ok, reason = sanitize(cmd_text)
        if not ok:
            st.sidebar.error(reason)
        elif not cmd_name.strip():
            st.sidebar.error("Please provide a name.")
        else:
            save_command(cmd_name.strip(), cmd_text.strip())
            st.sidebar.success("Saved.")
            st.experimental_rerun()

st.markdown("### 🔧 Quick Commands")
choice = st.selectbox("Pick a common command", [""] + list(COMMON.keys()))
if choice:
    st.code(COMMON[choice])

st.markdown("### ⌨️ Run a command")
cmd_input = st.text_input("Enter command (or leave blank and choose common command above)", value="")
if "run_cmd" in st.session_state:
    # when user hits a Run button from sidebar
    cmd_input = st.session_state.pop("run_cmd")

col1, col2 = st.columns([3,1])
with col1:
    run_button = st.button("Execute")

with col2:
    st.checkbox("Show stderr", value=True, key="show_err")

if run_button and (cmd_input.strip() or choice):
    command_to_run = cmd_input.strip() if cmd_input.strip() else COMMON[choice]
    ok, reason = sanitize(command_to_run)
    if not ok:
        st.error(reason)
    else:
        st.info(f"Running: `{command_to_run}`")
        # run and stream output
        try:
            proc = subprocess.Popen(command_to_run, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
            out_area = st.empty()
            # stream stdout
            while True:
                out_line = proc.stdout.readline()
                if out_line:
                    out_area.code(out_line)
                elif proc.poll() is not None:
                    break

            out, err = proc.communicate()
            if out:
                out_area.code(out)
            if st.session_state["show_err"] and err:
                st.error(err)
        except Exception as e:
            st.error(f"Error running command: {e}")

st.markdown("---")
st.markdown("### ℹ️ Tips & Safety")
st.markdown(
"""
- This is a **development/demo tool**. Avoid running it on production servers.
- Commands run with the privileges of the user that started the Streamlit process.
- Dangerous commands are blocked by a basic blacklist — add more rules as needed.
"""
)

requirements.txt

Create requirements.txt:

streamlit==1.24.1

(you can omit version to use latest: streamlit)

.gitignore

Create .gitignore:

venv/
__pycache__/
saved_commands.json
.vscode/
.env

Dockerfile (optional)

Create Dockerfile:

FROM python:3.10-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8501
CMD ["streamlit", "run", "app.py", "--server.address=0.0.0.0", "--server.port=8501"]

README.md

Create README.md (paste this whole block):

# CommandHub — Streamlit Command Dashboard

## What
A Streamlit app to run system commands from a browser and save frequently used commands.

## Run locally
1. Create venv and activate
2. pip install -r requirements.txt
3. streamlit run app.py
Open http://localhost:8501

## Docker
docker build -t commandhub .
docker run -p 8501:8501 -v $(pwd)/saved_commands.json:/app/saved_commands.json commandhub

## Security
- Do NOT run on production servers without proper auth.
- Use OS-level isolation (dedicated VM/container) for demo.

4) Install dependencies & run locally

With venv activated:

pip install -r requirements.txt
streamlit run app.py

Open http://localhost:8501 in your browser.


5) Quick manual tests (what to demo)

  1. From UI: choose Quick Commands → click Execute → observe output.

  2. Enter custom command (e.g., uname -a or whoami) → Execute.

  3. Save a command in the sidebar:

    • Name: docker-ps

    • Command: docker ps -a

    • Click Save → then click Run from sidebar.

  4. Delete a saved command with Del button.


6) Dockerize & run container (optional)

Build image:

docker build -t commandhub .

Run container and persist saved commands:
Linux/macOS:

docker run -p 8501:8501 -v "$(pwd)/saved_commands.json:/app/saved_commands.json" commandhub

Windows PowerShell:

docker run -p 8501:8501 -v ${PWD}\saved_commands.json:/app/saved_commands.json commandhub

Open http://localhost:8501.


7) Initialize Git & push to GitHub

Replace <your-username> and <repo> with your values.

git init
git add .
git commit -m "feat: add CommandHub Streamlit app with saved commands"
# Create repo on GitHub (via website) named commandhub
git remote add origin https://github.com/<your-username>/commandhub.git
git branch -M main
git push -u origin main

Suggested extra commits if you change later:

  • feat: add Dockerfile

  • fix: sanitize commands

  • docs: update README


8) Demo script (copy & run to demonstrate)

Open new terminal and run these commands to present quickly:

# clone & run
git clone https://github.com/<your-username>/commandhub.git
cd commandhub
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
streamlit run app.py
# then open http://localhost:8501 and demo steps

9) Validation checklist (tick before demo)

  • streamlit run app.py opens and loads UI

  • Quick commands display & run

  • Custom command runs and prints output

  • Save command persists into saved_commands.json

  • Deleting saved command works

  • Docker image builds and container runs (if used)

  • Repo pushed to GitHub and README present


10) Safety & next enhancements

Safety notes

  • This app runs shell commands — never expose to untrusted users.

  • Run inside isolated VM/container for demos.

Next features you can add

  • Authentication (Streamlit auth / reverse proxy)

  • Command whitelist (YAML) instead of blacklist

  • Command history with timestamps

  • Concurrent output tabs / streaming improvements

  • Role-based access & audit logs🎯 Future Enhancements

  • Role-based access control (security for multi-user environments)

  • Integration with cloud services (AWS, GCP, Azure commands)

  • Logs & history for executed commands

  • Dark mode 🌙


✨ Conclusion

CommandHub is a simple yet powerful tool to simplify command execution and tool management. Instead of switching between endless terminals and windows, you now have one platform to manage it all.

Would love to hear your thoughts and feedback on this project! 🚀

More from this blog

Amazon S3 Storage Classes

43 posts