Remote commands
Run commands on your environment without keeping a terminal session alive. qc exec executes the command server-side in a one-off container, so the run survives laptop sleep, dropped connections, and closed terminals — the CLI only watches progress.
When to use exec vs ssh
Section titled “When to use exec vs ssh”qc ssh --command |
qc exec run |
|
|---|---|---|
| Where it runs | Inside the live container, over an interactive session | In a one-off container, server-side |
| Laptop sleeps mid-run | Command is killed | Run continues |
| Interactive input | Yes | No |
| Exit code in scripts | Yes | Yes |
| Run length | As long as the session holds | Up to 1 hour |
Use ssh for interactive work (shells, REPLs, debugging). Use exec for anything long-running or unattended: cron-style jobs, imports, migrations, cache rebuilds.
Run a command
Section titled “Run a command”qc exec run "drush cron"The CLI prints a run ID immediately, then streams output as the run progresses:
✔ Command created (runId: 411fc62f-b8d5-4d7c-b8af-5a53f371d222)Regenerating cache...Processed 1000 items✔ Completed (exit 0) in 4m 02sContainer startup adds roughly a minute before the first output appears. The remote exit code becomes the CLI’s exit code, so failures propagate to scripts and CI.
Survive a laptop sleep
Section titled “Survive a laptop sleep”Nothing to do — this is the default behavior. If your machine sleeps while watching, the run continues on the server; when you wake, the CLI’s next poll picks up where things stand. If the CLI process died entirely, reattach:
qc exec status <runId> --watchReattaching reprints the run’s accumulated output from the beginning, then streams new lines live.
Fire and forget
Section titled “Fire and forget”Start a run and return immediately:
qc exec run "./import.sh" --detachCheck on it later — from the same machine or any other machine with CLI access:
qc exec status <runId> # one-shot checkqc exec status <runId> --watch # attach until it completesPressing Ctrl+C while watching only detaches the CLI; the run itself is unaffected.
Target a container
Section titled “Target a container”If your environment runs multiple containers, pick one (defaults to the first in the task definition):
qc exec run "php artisan migrate --force" --container phpQuoting and shell operators
Section titled “Quoting and shell operators”Commands with shell operators (&&, ;, |, …) are automatically wrapped in /bin/sh -c on the server. Write them flat — don’t nest your own sh -c quoting:
# Goodqc exec run "echo start && ./migrate.sh"
# Avoid — nested quoting gets mangledqc exec run "sh -c 'echo start && ./migrate.sh'"Limits
Section titled “Limits”- Runs are capped at 1 hour; longer runs finish with status
TIMED_OUT. For recurring work, use scheduled cron jobs on the environment instead. - Runs are non-interactive — commands that prompt for input will hang until the cap.
See the qc exec command reference for all flags.
