Skip to content

Interactive Container Terminal (Exec)

StackPilot provides an interactive, in-browser shell terminal for any running container across your fleet, eliminating the need to configure SSH keys, open firewall ports, or manage reverse tunnels.


1. Architecture & Protocol

The terminal engine is designed for low latency, secure transport, and responsive rendering:

sequenceDiagram autonumber actor Administrator as Administrator (Browser) participant Hub as Central Hub participant Agent as Host Agent participant Container as Container PTY Administrator->>Hub: POST /api/hosts/:ip/containers/:id/terminal/start Hub->>Agent: POST /api/terminal/start { container, cols, rows } Agent->>Container: Allocate PTY & spawn `podman exec -it <cnt> /bin/sh` Agent-->>Hub: { sessionId } Hub-->>Administrator: { sessionId } Administrator->>Hub: GET /api/hosts/:ip/containers/:id/terminal/stream?session=:id Hub->>Agent: GET /api/terminal/stream?session=:id Agent-->>Administrator: Server-Sent Events (SSE) data stream Administrator->>Hub: POST .../terminal/input { session, data, isBase64: true } Hub->>Agent: POST .../terminal/input Agent->>Container: Write stdin to PTY master

Components:

  • Frontend (xterm.js): Industry-standard terminal emulator with color support, copy/paste, and font scaling.
  • PTY Master/Slave: On Linux hosts, the agent allocates a genuine pseudo-terminal pair via pty.openpty(), ensuring curses programs like htop, nano, and interactive shells work natively.
  • Asynchronous Output Stream: PTY output is buffered, base64-encoded, and delivered over an SSE (text/event-stream) connection with periodic keep-alive pings.
  • Input Pipeline: Keystrokes are captured and transmitted via JSON POST requests directly into the PTY stdin pipe.

2. Opening a Container Terminal

To open a terminal session:

  1. Navigate to the Workloads view for the target host.
  2. Locate any running container or service.
  3. Click the Exec button in the action column.
  4. The terminal modal will open, automatically detecting the shell environment (/bin/bash, /bin/sh, or /bin/ash).

[!NOTE] The Exec button is only visible when the container or service is in an active running state. If a service is stopped or failed, start it first before launching a terminal session.


3. Terminal Controls & Keybindings

  • Clear: Clears the current xterm viewport buffer.
  • Reconnect: Re-establishes the SSE stream and spawns a new session if disconnected.
  • Close (✕ or Footer): Gracefully terminates the child process and closes PTY file descriptors.
  • Copy & Paste:
  • Select text with your cursor to copy automatically.
  • Paste directly into the terminal using standard keyboard shortcuts (Ctrl+V or Cmd+V).
  • Dynamic Resize: The terminal viewport uses ResizeObserver to detect size changes. When the browser window is resized, the frontend calculates new character columns and rows and issues a resize command (TIOCSWINSZ), preventing line wrapping errors in text editors.

4. Security & Role Permissions

Interactive container shell access provides direct execution within the container environment. StackPilot enforces strict governance:

  • Role Gating: Only users with the Admin role can initiate or interact with terminal sessions.
  • Operator and Viewer Restrictions: Operators and viewers are restricted from terminal execution and receive an Access Denied (403) response.
  • Container Isolation: Because StackPilot containers run under rootless Podman user namespaces, root inside the container (UID 0) is mapped to an unprivileged user (UID 1000+) on the host filesystem, preventing host breakout.
  • Audit Logging: All terminal session start, input, and close events are recorded in the Central Hub security audit log (audit.log).