lightning-studios

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Lightning AI Studios

Lightning AI Studios

A Studio is a persistent cloud development machine on lightning.ai. Its filesystem persists across sessions; compute (CPU/GPU) attaches on start and detaches on stop. Everything below uses the
lightning
CLI and
lightning_sdk
Python package.
Studio 是 lightning.ai 上的持久化云端开发机。其文件系统在不同会话间保持持久化;计算资源(CPU/GPU)会在启动时挂载,停止时卸载。以下所有操作均使用
lightning
CLI 和
lightning_sdk
Python 包。

Setup & auth

设置与身份验证

bash
undefined
bash
undefined

Use the Lightning AI CLI from the current env; install or upgrade it there if it's missing or older than 2026.9.18

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 token

This uses, and if needed installs into, the environment the agent runs in (the user's project
venv, a conda env, …). Then call plain `lightning …` everywhere. If setup doesn't go cleanly:

| Symptom | Fix |
|---|---|
| Both installs fail: no active env, or pip refuses with `externally-managed-environment` | Install it on its own instead: `uv tool install lightning-sdk` (or `pipx install lightning-sdk`), then call `"$(uv tool dir --bin)/lightning"` if that dir isn't on `PATH` |
| `lightning --version` still prints no `Lightning CLI version` line after installing | `command -v lightning` shows which one runs. Another tool owns the name (PyTorch Lightning also installs a `lightning` command), or the env you installed into isn't on `PATH`: activate it (`source .venv/bin/activate`) or call its `bin/lightning` by full path |
| `No such command`, `No such option` or `unexpected extra argument` | The CLI is older than this skill expects: `uv pip install -U lightning-sdk` (or `pip install -U lightning-sdk`) in the env `command -v lightning` points into; `uv tool upgrade lightning-sdk` for a uv tool install |
| The upgrade fails on a version conflict with the project's own pins | Don't fight the pins: install it outside the project with `uv tool install lightning-sdk` and call `"$(uv tool dir --bin)/lightning"` |
| Installing is blocked (read-only env or home, agent sandbox) | Skip it and run each command as `UV_CACHE_DIR="${TMPDIR:-/tmp}/uv" uvx lightning-sdk …` |
| Every call fails on SSL/certificates, even `lightning --version` (`Could not find a suitable TLS CA certificate bundle`), only inside an agent sandbox | A `**/*.pem` read-deny rule is hiding certifi's public CA bundle (`site-packages/certifi/cacert.pem`). Allow that one path; don't disable the sandbox |

Credentials are stored in `~/.lightning/credentials.json`.

The install above also makes `lightning_sdk` importable in that env, so Python snippets run with
its `python`. If the CLI came from a uv tool or `uvx` fallback instead, run one-off scripts with
`uv run --with lightning-sdk python script.py`. For code that stays in the user's project, ask,
then declare `lightning-sdk` as a dependency with the project's own tool (`uv add`, `poetry add`).
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 token

此操作会使用 Agent 运行所在的环境(用户的项目 venv、conda 环境等),如有需要也会安装到该环境中。之后所有地方都直接调用 `lightning …` 即可。如果设置过程不顺利,请参考下表:

| 症状 | 解决方法 |
|---|---|
| 两种安装方式都失败:没有激活的环境,或者 pip 以 `externally-managed-environment` 为由拒绝安装 | 改为单独安装:`uv tool install lightning-sdk`(或 `pipx install lightning-sdk`),如果该目录不在 `PATH` 中,则调用 `"$(uv tool dir --bin)/lightning"` |
| 安装后 `lightning --version` 仍然没有输出 `Lightning CLI version` 行 | 用 `command -v lightning` 查看运行的是哪个程序。可能是其他工具占用了这个名称(PyTorch Lightning 也会安装 `lightning` 命令),或者你安装到的环境不在 `PATH` 中:激活该环境(`source .venv/bin/activate`),或者使用完整路径调用其 `bin/lightning` |
| 提示 `No such command`、`No such option` 或 `unexpected extra argument` | CLI 版本低于本 Skill 的要求:在 `command -v lightning` 指向的环境中执行 `uv pip install -U lightning-sdk`(或 `pip install -U lightning-sdk`);如果是 uv tool 安装的,则执行 `uv tool upgrade lightning-sdk` |
| 升级因与项目自身的依赖版本锁定冲突而失败 | 不要强行修改版本锁定:使用 `uv tool install lightning-sdk` 在项目外部安装,并调用 `"$(uv tool dir --bin)/lightning"` |
| 安装被阻止(只读环境或主目录、Agent 沙箱) | 跳过安装,将每个命令改为 `UV_CACHE_DIR="${TMPDIR:-/tmp}/uv" uvx lightning-sdk …` 的形式运行 |
| 即使是 `lightning --version` 也会因 SSL/证书问题失败(`Could not find a suitable TLS CA certificate bundle`),且仅在 Agent 沙箱中出现 | 这是因为 `**/*.pem` 读取拒绝规则隐藏了 certifi 的公共 CA 包(`site-packages/certifi/cacert.pem`)。请允许该路径的访问权限,不要禁用沙箱 |

凭证存储在 `~/.lightning/credentials.json` 中。

上述安装操作还会让 `lightning_sdk` 在该环境中可被导入,因此 Python 代码片段可以用该环境的 `python` 运行。如果 CLI 来自 uv tool 或 `uvx` 备用方案,则使用 `uv run --with lightning-sdk python script.py` 运行一次性脚本。对于要保留在用户项目中的代码,请先询问用户,然后使用项目自身的工具(`uv add`、`poetry add`)将 `lightning-sdk` 声明为依赖项。

Resolving org and teamspace (do this first)

确定组织与团队空间(请先执行此操作)

Every studio lives in a teamspace owned by either an organization or a user. Never guess. Resolve in this order:
  1. Explicit
    --teamspace owner/teamspace
    flag (owner = org or user name) /
    Teamspace("owner/teamspace")
    in Python (the separate
    org=
    /
    user=
    arguments are deprecated).
  2. Env vars
    LIGHTNING_ORG
    ,
    LIGHTNING_TEAMSPACE
    ,
    LIGHTNING_USERNAME
    , or config defaults in
    ~/.lightning/config.yaml
    (
    lightning config get teamspace
    ).
  3. Otherwise list the options and ask the user which org/teamspace to use:
bash
lightning api /v1/memberships | jq -r '.memberships[] | [.ownerType, .name, .projectId] | @tsv'
Persist the user's choice so they aren't asked again:
lightning config set teamspace <owner>/<teamspace>
.
From a scoped API key (an agent, no user to ask):
/v1/memberships
gives the teamspace name and the owner id, but
--teamspace
needs the owner slug — resolve it via
/v1/orgs
(needs
jq
). Select the
organization
entry rather than
.memberships[0]
: the same teamspace is commonly listed twice, once with
ownerType: organization
and once with
ownerType: user
(identical
projectId
and
name
), so index 0 is a coin flip and the
user
row's
ownerId
will not resolve against
/v1/orgs
.
bash
M=$(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"
每个 Studio 都位于由组织或用户拥有的团队空间中。绝对不要猜测。 请按以下顺序确定:
  1. 显式指定
    --teamspace owner/teamspace
    参数(owner 为组织或用户名)/ 在 Python 中使用
    Teamspace("owner/teamspace")
    (单独的
    org=
    /
    user=
    参数已弃用)。
  2. 环境变量
    LIGHTNING_ORG
    、
    LIGHTNING_TEAMSPACE
    、
    LIGHTNING_USERNAME
    ,或
    ~/.lightning/config.yaml
    中的配置默认值(可通过
    lightning config get teamspace
    查看)。
  3. 否则列出所有选项,询问用户要使用哪个组织/团队空间:
bash
lightning api /v1/memberships | jq -r '.memberships[] | [.ownerType, .name, .projectId] | @tsv'
保存用户的选择,避免再次询问:
lightning config set teamspace <owner>/<teamspace>
。
使用受限 API 密钥时(即 Agent 场景,无法询问用户):
/v1/memberships
会返回团队空间名称和所有者的 ID,但
--teamspace
需要所有者的 slug——需要通过
/v1/orgs
解析(需要
jq
)。请选择
organization
类型的条目,而不是
.memberships[0]
:同一个团队空间通常会出现两次,一次是
ownerType: organization
,一次是
ownerType: user
(
projectId
和
name
完全相同),因此直接取第0个结果是随机的,而且
user
行的
ownerId
无法通过
/v1/orgs
解析。
bash
M=$(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"

CLI reference

CLI 参考

--teamspace
always takes
owner/teamspace
. Omitting
--name
/
--teamspace
in an interactive terminal opens a picker menu; in scripts always pass them explicitly.
bash
undefined
--teamspace
始终采用
owner/teamspace
格式。在交互式终端中省略
--name
/
--teamspace
会打开选择菜单;但在脚本中请始终显式传递这些参数。
bash
undefined

create (registers the studio, does NOT attach compute)

create (registers the studio, does NOT attach compute)

lightning studio create --name my-studio --teamspace owner/teamspace [--cloud PROVIDER] [--studio-type TEMPLATE]
lightning studio create --name my-studio --teamspace owner/teamspace [--cloud PROVIDER] [--studio-type TEMPLATE]

start compute (blocking; --create makes it if missing)

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
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

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
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)

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
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)

machine names the CLI accepts (offline list; says nothing about availability)

lightning machine list [--json]
undefined
lightning machine list [--json]
undefined

Files:
lit://
paths

文件:
lit://
路径

Studio paths use
lit://<owner>/<teamspace>/studios/<studio-name>/<path>
. Exactly one side of a copy must be
lit://
; directories need
-r
.
bash
lightning 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]
Studio 的路径使用
lit://<owner>/<teamspace>/studios/<studio-name>/<path>
格式。复制操作的两端必须恰好有一端是
lit://
路径;复制目录需要加
-r
参数。
bash
lightning 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]

Python SDK

Python SDK

python
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
python
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

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()
undefined
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()
undefined

Machine types

机器类型

Pass as
Machine.<NAME>
or string (
Machine.from_str("A100")
accepts name or slug):
  • CPU:
    CPU_SMALL
    ,
    CPU
    (default, 4 cores),
    CPU_X_2/4/8/16
    ; big-disk:
    DATA_PREP
    ,
    DATA_PREP_MAX
    ,
    DATA_PREP_ULTRA
  • GPU:
    T4_SMALL
    ,
    T4
    ,
    T4_X_2/4/8
    ,
    L4
    ,
    L4_X_2/4/8
    ,
    L40S
    ,
    L40S_X_2/4/8
    ,
    RTXP_6000
    (+
    _X_2/4/8
    ),
    A100
    (+
    _X_2/4/8
    ),
    H100
    (+
    _X_2/4/8
    ),
    H200
    (+
    _X_2/4/8
    ),
    B200
    ,
    B200_X_8
  • A100_40GB*
    /
    A100_80GB*
    variants exist in the SDK but are hidden from CLI
    --machine
    (usable with
    studio switch
    and in Python).
The names above are current as of writing and SKUs do get added, so treat the list as a starting point, not a closed set.
lightning machine list
prints the names your installed CLI accepts, but it is an offline list and says nothing about what a teamspace can launch. For live availability and prices, use
Teamspace("owner/teamspace").list_machines()
in Python (drops out-of-capacity machines; each has
cost
/
interruptible_cost
) or
GET /v1/core/accelerators?cloudProvider=<PROVIDER>
(no auth needed, so plain
curl
works; the
lightning-cost-estimation
skill has the provider values and the costing recipes). Don't invent a catalog endpoint:
/v1/accelerators
,
/v1/accelerator-catalog
,
/v1/pricing
and
/v1/compute/accelerators
all return
code: 5
.
Interruptible (spot) is a flag, not a machine type:
--interruptible
/
interruptible=True
.
可通过
Machine.<NAME>
或字符串形式传递(
Machine.from_str("A100")
支持名称或 slug):
  • CPU:
    CPU_SMALL
    、
    CPU
    (默认,4 核)、
    CPU_X_2/4/8/16
    ;大磁盘型:
    DATA_PREP
    、
    DATA_PREP_MAX
    、
    DATA_PREP_ULTRA
  • GPU:
    T4_SMALL
    、
    T4
    、
    T4_X_2/4/8
    、
    L4
    、
    L4_X_2/4/8
    、
    L40S
    、
    L40S_X_2/4/8
    、
    RTXP_6000
    (+
    _X_2/4/8
    )、
    A100
    (+
    _X_2/4/8
    )、
    H100
    (+
    _X_2/4/8
    )、
    H200
    (+
    _X_2/4/8
    )、
    B200
    、
    B200_X_8
  • SDK 中存在
    A100_40GB*
    /
    A100_80GB*
    变体,但在 CLI 的
    --machine
    参数中被隐藏(可通过
    studio switch
    和 Python 代码使用)。
上述名称是撰写本文时的当前版本,SKU 会不断新增,因此请将此列表作为起点,而非完整集合。
lightning machine list
会输出你安装的 CLI 支持的名称,但这是一个离线列表,无法反映团队空间实际可启动的机器类型。如需实时可用性和价格信息,请在 Python 中使用
Teamspace("owner/teamspace").list_machines()
(会排除容量不足的机器;每个机器都有
cost
/
interruptible_cost
字段),或调用
GET /v1/core/accelerators?cloudProvider=<PROVIDER>
(无需身份验证,因此直接用
curl
即可;
lightning-cost-estimation
Skill 包含提供商值和成本计算方法)。不要自行编造目录端点:
/v1/accelerators
、
/v1/accelerator-catalog
、
/v1/pricing
和
/v1/compute/accelerators
都会返回
code: 5
。
可中断(竞价实例)是一个标志,而非机器类型:对应参数为
--interruptible
/
interruptible=True
。

Example workflows

示例工作流

Prompts this skill handles: "spin up a GPU studio and run my training script", "copy this repo to my studio and start a long run", "SSH into exp-studio", "my studio is idle, stop it".
Create a studio, run a script, collect results, stop (cheap default: start on CPU, switch to GPU only for the run):
bash
lightning 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 L4
python
from 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)
bash
lightning cp -r lit://my-org/my-teamspace/studios/exp-1/src/outputs/ ./outputs
lightning studio stop --name exp-1 --teamspace my-org/my-teamspace
SSH in and run scripts interactively (for a human user; agents should prefer
studio.run*
above since
ssh
opens an interactive shell):
bash
lightning 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 shot
Kick off a long run and detach (survives your session; studio keeps billing until stopped):
python
out, code = studio.run_and_detach("cd ~/src && nohup python train.py > train.log 2>&1", timeout=30)
本 Skill 可处理的提示示例:"启动一个 GPU Studio 并运行我的训练脚本"、"把这个仓库复制到我的 Studio 并启动一个长时间运行的任务"、"通过 SSH 连接到 exp-studio"、"我的 Studio 空闲了,停止它"。
创建 Studio、运行脚本、收集结果、停止(低成本默认方案:先在 CPU 上启动,仅在运行时切换到 GPU):
bash
lightning 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 L4
python
from 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)
bash
lightning cp -r lit://my-org/my-teamspace/studios/exp-1/src/outputs/ ./outputs
lightning studio stop --name exp-1 --teamspace my-org/my-teamspace
通过 SSH 连接并交互式运行脚本(适用于人类用户;Agent 应优先使用上述
studio.run*
方法,因为
ssh
会打开交互式 shell):
bash
lightning 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 shot
启动长时间运行任务并断开连接(任务不会随会话结束而终止;Studio 会持续计费直到停止):
python
out, 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")

later: studio.run("tail -20 ~/src/train.log")

undefined
undefined

Raw API fallback

原生 API 备用方案

For anything the CLI doesn't wrap,
lightning api <path>
makes an authenticated request (
-X
method,
-F
typed field,
-f
string field,
-q
jq filter):
bash
lightning api /v1/memberships -q '.memberships[].name'
PROJECT_ID=$(lightning api /v1/memberships | jq -r '.memberships[] | select(.name=="<teamspace>") | .projectId' | head -1)
对于 CLI 没有封装的操作,
lightning api <path>
可以发起已认证的请求(
-X
指定请求方法,
-F
指定类型字段,
-f
指定字符串字段,
-q
指定 jq 过滤器):
bash
lightning 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)

studios are "cloudspaces" in the API — one word, and call it BARE (see Gotchas)

lightning api "/v1/projects/${PROJECT_ID}/cloudspaces" -q '.cloudspaces[].name'
undefined
lightning api "/v1/projects/${PROJECT_ID}/cloudspaces" -q '.cloudspaces[].name'
undefined

Gotchas

注意事项

  • Starting compute costs money; GPU machines cost more. Prefer
    CPU
    for setup work, switch to GPU only when needed, and stop studios when done. Ask before starting expensive machines (A100/H100/H200/B200) unless the user already specified one.
  • run*
    methods and
    studio switch
    require status
    Running
    ;
    start()
    on a studio already running on a different machine raises — use
    switch_machine
    instead.
  • Disabling auto-sleep (
    studio.auto_sleep = False
    ) or setting
    auto_sleep_time
    converts a free CPU studio to paid.
  • studio create
    does not attach compute;
    studio start --create
    does both.
  • lightning studio delete
    prompts for confirmation — pass
    -y
    /
    --yes
    non-interactively.
    Without it, a scripted or agent-run delete reads the prompt from a closed stdin, prints
    Are you sure you want to delete? [y/N]: Aborted.
    and exits without deleting, leaving the studio (and its billing) alive. Confirm with the user first, then pass
    -y
    ; there is no need to drop into the Python SDK for this.
  • The studios list endpoint is
    /cloudspaces
    , one word, and takes no
    -F
    fields.
    The hyphenated
    /v1/projects/{pid}/cloud-spaces
    returns
    HTTP 404 Not Found
    . Once corrected, adding
    -F limit=20
    still fails with
    HTTP 400 Bad Request
    , because
    lightning api
    sends any request with
    -f
    /
    -F
    fields and no
    -X
    as a POST (the create call). Call it bare and slice with
    -q
    , or pass
    -X GET
    to send the fields as query params.
  • Inside a Studio,
    Studio()
    with no args resolves to the current studio (via
    LIGHTNING_CLOUD_SPACE_ID
    ).
  • In Python,
    teamspace=
    takes the same
    "owner/teamspace"
    string as the CLI
    --teamspace
    flag (for
    Teamspace
    ,
    Studio
    and
    Job
    ). The separate
    org=
    /
    user=
    arguments still work but are deprecated and emit a
    DeprecationWarning
    ; passing both forms raises
    ValueError
    .
  • 启动计算资源会产生费用;GPU 机器费用更高。设置工作请优先使用
    CPU
    ,仅在需要时切换到 GPU,并且用完后请停止 Studio。启动昂贵的机器(A100/H100/H200/B200)前请先询问用户,除非用户已经指定了机型。
  • run*
    方法和
    studio switch
    要求 Studio 状态为
    Running
    ;对已经在其他机器上运行的 Studio 调用
    start()
    会报错——请改用
    switch_machine
    。
  • 禁用自动休眠(
    studio.auto_sleep = False
    )或设置
    auto_sleep_time
    会将免费的 CPU Studio 转为付费模式。
  • studio create
    不会挂载计算资源;
    studio start --create
    会同时完成创建和启动。
  • lightning studio delete
    会提示确认——非交互式场景下请传递
    -y
    /
    --yes
    参数。
    如果不加该参数,脚本或 Agent 执行删除操作时会从已关闭的标准输入读取提示,输出
    Are you sure you want to delete? [y/N]: Aborted.
    后退出,并未实际删除,导致 Studio(及其计费)继续存在。请先与用户确认,然后传递
    -y
    参数;无需为此使用 Python SDK。
  • Studio 列表的端点是
    /cloudspaces
    (一个单词),且不接受
    -F
    字段。
    带连字符的
    /v1/projects/{pid}/cloud-spaces
    会返回
    HTTP 404 Not Found
    。即使路径改对了,加上
    -F limit=20
    仍然会失败并返回
    HTTP 400 Bad Request
    ,因为
    lightning api
    会将任何带有
    -f
    /
    -F
    字段且没有指定
    -X
    的请求作为 POST(创建请求)发送。请直接调用该端点并用
    -q
    截取结果,或者传递
    -X GET
    将字段作为查询参数发送。
  • 在 Studio 内部,不带参数的
    Studio()
    会解析为当前 Studio(通过
    LIGHTNING_CLOUD_SPACE_ID
    )。
  • 在 Python 中,
    teamspace=
    参数接受与 CLI
    --teamspace
    标志相同的
    "owner/teamspace"
    字符串(适用于
    Teamspace
    、
    Studio
    和
    Job
    )。单独的
    org=
    /
    user=
    参数仍然可用,但已弃用并会发出
    DeprecationWarning
    ;同时传递两种形式会抛出
    ValueError
    。