[CLI] Add hf spaces ssh#4241
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
- Fix dev mode detection: use `SpaceRuntime.dev_mode` (from API `devMode` field) instead of checking `subdomain` presence. - Rename `--print` to `--dry-run` (follows gcloud/git/make convention). - Add `--auto` flag to enable Dev Mode without prompting. - If dev mode is off, prompt user to enable it (interactive confirm). - Extract `_wait_for_dev_mode` helper shared by `dev-mode` and `ssh`. - Remove unnecessary `FileNotFoundError` catch on `ssh` subprocess. - Mention `hf spaces ssh` in `dev-mode` output. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| cmd = ["ssh"] | ||
| if identity_file is not None: | ||
| cmd += ["-i", str(identity_file)] | ||
| cmd.append(f"{info.subdomain}@ssh.hf.space") |
There was a problem hiding this comment.
SSH attempted without waiting for space to be running
Medium Severity
When dev mode is already enabled (info.runtime.dev_mode is True) but the space is still in an intermediate stage (BUILDING, APP_STARTING, etc.), the code skips the _wait_for_dev_mode call and immediately attempts SSH. This happens if a user enables dev mode through the web UI or another CLI invocation and then quickly runs hf spaces ssh before the container is ready. The SSH connection will fail because the container isn't accepting connections yet. The wait logic only executes in the branch where dev mode was just enabled by this command.
Reviewed by Cursor Bugbot for commit 9e49757. Configure here.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default mode and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c32ba09. Configure here.
|
Tested and works well on https://huggingface.co/spaces/huggingface/tmp-dev-mode-test |
|
This PR has been shipped as part of the v1.17.0 release. |
Add a CLI shortcut to the Dev Mode SSH section: `hf spaces ssh` resolves the Space subdomain and opens the session for you, with `--dry-run` and `-i` examples plus an `--auto` note. Complements the existing manual `ssh <subdomain>@ssh.hf.space` instructions; the existing "register your SSH key" line covers the prerequisite for both paths. Added in huggingface_hub v1.17.0 (huggingface/huggingface_hub#4241). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add a CLI shortcut to the Dev Mode SSH section: `hf spaces ssh` resolves the Space subdomain and opens the session for you, with `--dry-run` and `-i` examples plus an `--auto` note. Complements the existing manual `ssh <subdomain>@ssh.hf.space` instructions; the existing "register your SSH key" line covers the prerequisite for both paths. Added in huggingface_hub v1.17.0 (huggingface/huggingface_hub#4241). Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>


Summary
Add
hf spaces ssh <space_id>to SSH into a Space's Dev Mode container.Features:
SpaceRuntime.dev_mode(new field, from APIdevMode).--autoflag skips the prompt and enables Dev Mode automatically.--dry-runflag prints thesshcommand instead of running it.-i/--identity-fileto forward a specific SSH key.Other changes:
hf spaces dev-modeoutput to mentionhf spaces ssh.dev_mode: boolattribute toSpaceRuntime.Example:
Usage:
🤖 Generated with Claude Code
Note
Low Risk
Low risk: primarily adds a new CLI entrypoint plus small refactoring and a new
SpaceRuntime.dev_modefield; behavior changes are limited to Dev Mode workflows and interactive confirmations.Overview
Adds
hf spaces sshto open an SSH session into a Space’s Dev Mode container, supporting--auto(enable Dev Mode without prompting),--dry-run(print thesshcommand), and-i/--identity-file(forward an SSH key).Extends
SpaceRuntimewith adev_modeflag sourced from the API (devMode), refactorshf spaces dev-modeto reuse a shared “wait until Dev Mode is ready” helper, and updates CLI/docs reference pages to document the new SSH workflow. Also generalizesout.confirm()so commands can customize the “skip confirmation” flag text (used to point users to--autofor this command).Reviewed by Cursor Bugbot for commit db5beec. Bugbot is set up for automated code reviews on this repo. Configure here.