← Back to DAGDA | Support | Source: https://gist.github.com/Natuworkguy/4e21c781fef805c96479b84ac0d177f6
Skip to content

Instantly share code, notes, and snippets.

@Natuworkguy
Last active July 3, 2026 04:04
Show Gist options
  • Select an option

  • Save Natuworkguy/4e21c781fef805c96479b84ac0d177f6 to your computer and use it in GitHub Desktop.

Select an option

Save Natuworkguy/4e21c781fef805c96479b84ac0d177f6 to your computer and use it in GitHub Desktop.
Run a noVNC Linux Desktop in GitHub Codespaces
#!/usr/bin/env bash
# ==============================================================================
# noVNC Desktop for GitHub Codespaces
# Created by @Natuworkguy
# ==============================================================================
set -Eeuo pipefail
VIEWER_PORT="${VIEWER_PORT:-6080}"
VIEWER_PATH="${VIEWER_PATH:-vnc_lite.html}"
VIEWER_PATH="${VIEWER_PATH#/}"
LOG_FILE="/tmp/start-gui-$(date +%m%d%y%H%M%S%3N).log"
GUI_ENV_FILE="/tmp/gui.env"
cleanup() {
rm -f "$GUI_ENV_FILE"
pkill -f "Xvfb :1" || true
pkill -f "x11vnc -display :1" || true
pkill -f "websockify.*${VIEWER_PORT}" || true
}
trap cleanup EXIT INT TERM
echo "Installing dependencies..."
sudo apt-get update -y >/dev/null
sudo apt-get install -y xvfb x11vnc fluxbox websockify novnc >/dev/null
echo "Cleaning old sessions..."
cleanup
rm -f /tmp/.X1-lock
echo "Starting GUI services..."
export DISPLAY=:1
cat > "$GUI_ENV_FILE" <<EOF
export DISPLAY=:1
export VIEWER_PORT=${VIEWER_PORT}
export VIEWER_PATH=${VIEWER_PATH}
EOF
Xvfb :1 -screen 0 1024x768x24 >>"$LOG_FILE" 2>&1 &
sleep 1
fluxbox >>"$LOG_FILE" 2>&1 &
x11vnc \
-display :1 \
-nopw \
-forever \
-shared \
-rfbport 5900 \
-listen 127.0.0.1 \
-quiet \
>>"$LOG_FILE" 2>&1 &
websockify \
--web=/usr/share/novnc \
"$VIEWER_PORT" \
127.0.0.1:5900 \
>>"$LOG_FILE" 2>&1 &
echo "Forwarding port ${VIEWER_PORT} if GitHub CLI supports it..."
if command -v gh >/dev/null 2>&1 && [ -n "${CODESPACE_NAME:-}" ]; then
gh codespace ports forward "${VIEWER_PORT}:${VIEWER_PORT}" -c "$CODESPACE_NAME" \
>>"$LOG_FILE" 2>&1 &
sleep 2
gh codespace ports visibility "${VIEWER_PORT}:public" -c "$CODESPACE_NAME" \
>>"$LOG_FILE" 2>&1 || true
fi
if [ -n "${CODESPACE_NAME:-}" ]; then
DOMAIN="${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN:-app.github.dev}"
URL="https://${CODESPACE_NAME}-${VIEWER_PORT}.${DOMAIN}/${VIEWER_PATH}?autoconnect=1&resize=scale"
else
URL="http://localhost:${VIEWER_PORT}/${VIEWER_PATH}?autoconnect=1&resize=scale"
fi
echo
echo "GUI desktop is ready"
echo
echo "Open this URL:"
echo "$URL"
echo
echo "Logs are hidden. To view them:"
echo "tail -f $LOG_FILE"
echo
echo "To use DISPLAY in a shell, run:"
echo "source \"$GUI_ENV_FILE\""
echo
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment