Harthelm Docs
Guides

Run commands remotely

Run a command in a workspace with hart exec.

Last updated 2026-10-19

hart exec runs a command in a workspace from your computer or a pipeline, without opening a terminal. It is the tool for a database migration, a one-off script or a quick look at a file.

Run a command

Terminal
hart exec -w 42 -- npm run migrate

The command runs with bash in /data/app of the workspace, with the workspace's env vars, as the workspace's user. Its output comes back on your stdout and stderr, and hart exits with the command's own exit status.

Everything after -- is the command. One argument is run as a shell line, so pipes and && work when you quote it:

Terminal
hart exec -w 42 -- 'ls -la && du -sh node_modules'

Several arguments are quoted word by word and run as one command.

Limits

Run time120 seconds by default; --timeout up to 300
Outputat most 1 MiB per stream
Exit statusthe command's own; 124 when the timeout killed it, 137 when it was killed otherwise
Needsthe Editor role on the workspace

The workspace wakes if it sleeps, and a running command keeps it awake. For anything longer than 5 minutes, open a terminal in the IDE and a keep-awake window.

Use it in a script

migrate.sh
set -e
hart exec -w "$WORKSPACE" --timeout 300 -- npm run migrate
hart run

-o json prints the output and the exit code as JSON. Exit codes 2 to 6 come from hart itself (usage, sign-in, permissions, not found, conflict) before the command ran; see Exit codes.

Pull the code first

A pipeline that pushed new commits can bring the workspace up to date before it runs anything:

Terminal
hart ws wake 42 --wait
hart git pull -w 42
hart exec -w 42 -- npm ci

hart git pull fast-forwards /data/app; it never merges.

Next steps

On this page