Loading...
Loading...
Manage Lightning AI Studios (cloud dev machines with CPUs/GPUs) - create, start, stop, delete studios, switch machine types, run commands in them, upload/download files, and SSH in. Use when the user wants to work with lightning.ai Studios, needs a cloud GPU dev box, or asks to run something "on a studio".
npx skill4agent add lightning-ai/skills lightning-studioslightninglightning_sdk# Use the Lightning AI CLI from the current env; install or upgrade it there if it's missing or older than 2026.9.18
v=$(lightning --version 2>/dev/null | sed -n 's/^Lightning CLI version //p')
[ -n "$v" ] && [ "$(printf '%s\n' 2026.9.18 "$v" | sort -V | head -1)" = 2026.9.18 ] \
|| uv pip install -U lightning-sdk || python3 -m pip install -U lightning-sdk
lightning --version # must print "Lightning CLI version …"; if not, see the table below
lightning login # browser flow; or set env vars for headless use:
export LIGHTNING_API_KEY=... LIGHTNING_USER_ID=... # USER_ID optional: with it Basic auth, without it the key is a Bearer tokenlightning …| Symptom | Fix |
|---|---|
Both installs fail: no active env, or pip refuses with | Install it on its own instead: |
| |
| The CLI is older than this skill expects: |
| The upgrade fails on a version conflict with the project's own pins | Don't fight the pins: install it outside the project with |
| Installing is blocked (read-only env or home, agent sandbox) | Skip it and run each command as |
Every call fails on SSL/certificates, even | A |
~/.lightning/credentials.jsonlightning_sdkpythonuvxuv run --with lightning-sdk python script.pylightning-sdkuv addpoetry add--teamspace owner/teamspaceTeamspace("owner/teamspace")org=user=LIGHTNING_ORGLIGHTNING_TEAMSPACELIGHTNING_USERNAME~/.lightning/config.yamllightning config get teamspacelightning api /v1/memberships | jq -r '.memberships[] | [.ownerType, .name, .projectId] | @tsv'lightning config set teamspace <owner>/<teamspace>/v1/memberships--teamspace/v1/orgsjqorganization.memberships[0]ownerType: organizationownerType: userprojectIdnameuserownerId/v1/orgsM=$(lightning api /v1/memberships)
ROW=$(echo "$M" | jq -c '[.memberships[] | select(.ownerType=="organization")][0] // .memberships[0]')
TS=$(echo "$ROW" | jq -r .name) # teamspace
OWNER=$(lightning api "/v1/orgs/$(echo "$ROW" | jq -r .ownerId)" | jq -r .name) # owner (org) slug
lightning config set teamspace "$OWNER/$TS" # every command now defaults here; or pass --teamspace "$OWNER/$TS"--teamspaceowner/teamspace--name--teamspace# create (registers the studio, does NOT attach compute)
lightning studio create --name my-studio --teamspace owner/teamspace [--cloud PROVIDER] [--studio-type TEMPLATE]
# start compute (blocking; --create makes it if missing)
lightning studio start --name my-studio --teamspace owner/teamspace --machine CPU [--create] [--interruptible]
lightning studio start --name my-studio --teamspace owner/teamspace --gpus L4:4 # --gpus and --machine are mutually exclusive
# manage
lightning studio list --teamspace owner/teamspace [--all] [--sort-by status] # default lists only your studios
lightning studio switch --name my-studio --teamspace owner/teamspace --machine A100 # requires Running studio
lightning studio stop --name my-studio --teamspace owner/teamspace
lightning studio delete my-studio --teamspace owner/teamspace -y # NAME is positional here; -y/--yes: required non-interactively
# ssh / one-shot connect (create + start + ssh)
lightning studio ssh --name my-studio --teamspace owner/teamspace
lightning studio connect my-studio --teamspace owner/teamspace --machine CPU
# machine names the CLI accepts (offline list; says nothing about availability)
lightning machine list [--json]lit://lit://<owner>/<teamspace>/studios/<studio-name>/<path>lit://-rlightning cp ./train.py lit://owner/teamspace/studios/my-studio/train.py # upload
lightning cp -r lit://owner/teamspace/studios/my-studio/logs/ ./logs # download dir
lightning ls lit://owner/teamspace/studios/my-studio # list files (-r recursive, --json)
lightning rm lit://owner/teamspace/studios/my-studio/old.txt [-r] [-f]from lightning_sdk import Machine, Studio, Teamspace
ts = Teamspace("my-org/my-teamspace") # owner/teamspace; org=/user= are deprecated
studio = Studio(name="my-studio", teamspace=ts, create_ok=True) # create_ok=False -> error if missing
studio.start(machine=Machine.CPU) # blocking; interruptible=True for spot pricing
print(studio.status) # NotCreated|Pending|Running|Stopping|Stopped|Completed|Failed
# run commands — studio must be Running
out = studio.run("nvidia-smi") # raises RuntimeError on non-zero exit
out, code = studio.run_with_exit_code("pytest -q") # no raise on non-zero
out, code = studio.run_and_detach("python train.py", timeout=30) # keeps running in background
studio.upload_file("train.py", remote_path="train.py") # remote path relative to studio home
studio.download_file("outputs/model.ckpt", "model.ckpt")
studio.upload_folder("./src"); studio.download_folder("outputs/")
studio.switch_machine(Machine.A100) # change machine while running
studio.set_env({"WANDB_API_KEY": "..."}) # env vars; partial=True merges
studio.stop() # releases compute, keeps filesystem
studio.delete()Machine.<NAME>Machine.from_str("A100")CPU_SMALLCPUCPU_X_2/4/8/16DATA_PREPDATA_PREP_MAXDATA_PREP_ULTRAT4_SMALLT4T4_X_2/4/8L4L4_X_2/4/8L40SL40S_X_2/4/8RTXP_6000_X_2/4/8A100_X_2/4/8H100_X_2/4/8H200_X_2/4/8B200B200_X_8A100_40GB*A100_80GB*--machinestudio switchlightning machine listTeamspace("owner/teamspace").list_machines()costinterruptible_costGET /v1/core/accelerators?cloudProvider=<PROVIDER>curllightning-cost-estimation/v1/accelerators/v1/accelerator-catalog/v1/pricing/v1/compute/acceleratorscode: 5--interruptibleinterruptible=Truelightning studio start --name exp-1 --teamspace my-org/my-teamspace --machine CPU --create
lightning cp -r ./src lit://my-org/my-teamspace/studios/exp-1/src/
lightning studio switch --name exp-1 --teamspace my-org/my-teamspace --machine L4from lightning_sdk import Studio
studio = Studio("exp-1", teamspace="my-org/my-teamspace")
out, code = studio.run_with_exit_code("cd ~/src && pip install -r requirements.txt && python train.py")
print(out)lightning cp -r lit://my-org/my-teamspace/studios/exp-1/src/outputs/ ./outputs
lightning studio stop --name exp-1 --teamspace my-org/my-teamspacestudio.run*sshlightning studio ssh --name exp-1 --teamspace my-org/my-teamspace # interactive shell
lightning ssh configure --name exp-1 --teamspace my-org/my-teamspace # writes ~/.ssh/config Host block...
ssh exp-1 'python ~/src/eval.py' # ...then plain ssh runs one-off commands
lightning studio connect exp-1 --teamspace my-org/my-teamspace --machine CPU # create+start+ssh in one shotout, code = studio.run_and_detach("cd ~/src && nohup python train.py > train.log 2>&1", timeout=30)
# later: studio.run("tail -20 ~/src/train.log")lightning api <path>-X-F-f-qlightning api /v1/memberships -q '.memberships[].name'
PROJECT_ID=$(lightning api /v1/memberships | jq -r '.memberships[] | select(.name=="<teamspace>") | .projectId' | head -1)
# studios are "cloudspaces" in the API — one word, and call it BARE (see Gotchas)
lightning api "/v1/projects/${PROJECT_ID}/cloudspaces" -q '.cloudspaces[].name'CPUrun*studio switchRunningstart()switch_machinestudio.auto_sleep = Falseauto_sleep_timestudio createstudio start --createlightning studio delete-y--yesAre you sure you want to delete? [y/N]: Aborted.-y/cloudspaces-F/v1/projects/{pid}/cloud-spacesHTTP 404 Not Found-F limit=20HTTP 400 Bad Requestlightning api-f-F-X-q-X GETStudio()LIGHTNING_CLOUD_SPACE_IDteamspace="owner/teamspace"--teamspaceTeamspaceStudioJoborg=user=DeprecationWarningValueError