Skip to the content
Forge

Debug shells

When a run fails and its output doesn't say why, re-run it with debug. Forge starts the run again as its next attempt and, once the process exits, keeps the container so you can open a shell in it and look around: the files, the environment and any processes left behind.

Re-run with debug

On an ended run's page, choose Re-run with debug. It asks for:

  • Keep the container for (minutes): how long the container is held after the process exited. The default is 15 minutes, up to your organization's debug shell time (60 minutes by default, set by the plan).
  • Also when the process succeeds: by default the container is held only when the process failed, a command's timeout included.

Start debug run starts the next attempt with the same spec, secrets, variables and registry logins as a retry would. Once its process exits, the run is Held for debugging: its exit code is known, but the run isn't over yet. The page says until when.

Open the shell

Open shell on a held run opens a terminal in the run's own container:

  • as the run's user, in its working directory, with its environment and its secrets;
  • with its files, leftover processes and services as the process left them;
  • with bash if the image has it, else sh. An image with neither can't be debugged.

One shell per run can be open at a time. A shell closes when you exit it, after 10 minutes without input, or when the run ends. Exiting the shell doesn't end the run: open another one, or cancel the run to release it. Otherwise the run ends when its keep time is over.

A held run ends with its process's own result, failed with its exit code or succeeded, not as cancelled.

What the shell shows isn't masked. Unlike the run's log, secrets printed in the shell appear as they are.

From the command line

forge debug RUN                # re-run, wait until held, open the shell
forge debug --keep 30m RUN     # hold the container for 30 minutes
forge debug --always RUN       # hold it even when the process succeeds
forge debug --detach RUN       # only start it and print the new run's id
forge shell RUN                # open a shell in a held run

--keep takes whole minutes. forge debug and forge shell exit with the shell's exit code, or 125 when the shell ended without one. In a terminal, Ctrl-C goes to the shell, not to forge.

Who can, and what

  • Re-running with debug and opening a shell need the run:debug permission. Maintainers and owners have it, developers don't, because the shell sees the run's secrets (see members and roles).
  • Debug runs go only to your project's or organization's own runners, never to shared runners. The runner must be recent enough.
  • These can't be debugged:
    • a run that is still going;
    • a VM or compose run;
    • an approval step;
    • a deploy to an environment, as it would deploy again;
    • a run that pushes images, as it would push again;
    • a run of a pull request from a fork;
    • a step of a flow run that is still going.
  • A debug attempt of a flow step doesn't change its flow run: the flow run keeps its result.
  • A debug run isn't retried.

Audit

Opening and closing a shell are recorded in the organization's audit log: the run, its attempt, its runner, how long the shell was open and how it ended. What was typed or shown is never recorded or stored.

API

  • POST /api/v1/runs/{run}/debug with {"keep_minutes": 15, "when": "on_failure"} (or "always") starts the debug run. It answers 409 not_debuggable when the run can't be debugged, with the reason.
  • GET /api/v1/runs/{run}/shell?cols=80&rows=24 is a WebSocket to the shell while the run is held: binary messages carry the terminal's bytes both ways, and text messages are JSON, such as {"resize": {"cols": 120, "rows": 40}}.