docker-sandboxes-env
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDocker Sandboxes: Declarative sbxenv.yaml Environments
Docker Sandboxes: 声明式 sbxenv.yaml 环境
Overview
概述
sbxenv.yaml"1"sbx env create|run|plan|exec|rmkits:sbxenv.yaml"1"sbx env create|run|plan|exec|rmkits:When to use this skill
何时使用本 skill
Activate this skill when:
- The user wants a checked-in, reproducible definition of a sandbox
environment instead of a long /
sbx createcommand line.sbx run - The user wants host-side setup/teardown commands (cloning a repo, seeding fixtures, archiving state) tied to a sandbox's create/attach/remove lifecycle.
- The user wants to parameterize a shared environment file with named
arguments (+
args:).--env-arg - The user is debugging why /
sbx env createis asking for approval, or why a file, kit, or secret it declares was skipped or flagged.run
在以下情况激活此 skill:
- 用户想要一个可入库、可重现的 sandbox 环境定义,而不是一长串 /
sbx create命令行。sbx run - 用户想要将宿主侧设置/清理命令(克隆仓库、填充 fixtures、归档状态)绑定到 sandbox 的 create/attach/remove 生命周期。
- 用户想要使用命名参数(+
args:)参数化一个共享环境文件。--env-arg - 用户正在调试为什么 /
sbx env create要求审批,或者为什么它声明的文件、kit 或 secret 被跳过或被标记。run
Do not use this skill when
不要使用本 skill 的情况
Do not use this skill when:
- The task is the underlying /
sbx create/runflag-based workflow with normfile involved — usesbxenv.yaml.docker-sandboxes-lifecycle - The task is choosing network policy or storing a secret/registry
credential independent of any environment file — use
(this skill's
docker-sandboxes-network-credentials/secrets:/registries:blocks provision into that same store, but do not redefine its rules here).bindings: - The task is authoring the kit a
spec.yamlentry points at — usekits:.docker-sandboxes-kits
不要使用本 skill,当:
- 任务是底层基于 /
sbx create/run标志的流程,且不涉及任何rm文件——请使用sbxenv.yaml。docker-sandboxes-lifecycle - 任务是选择网络策略或存储与任何环境文件无关的 secret/registry 凭据——请使用 (本 skill 的
docker-sandboxes-network-credentials/secrets:/registries:块会配置到同一存储中,但不会在此重新定义其规则)。bindings: - 任务是编写 条目所指向的 kit
kits:——请使用spec.yaml。docker-sandboxes-kits
Core guidance
核心指导
File resolution and required fields
文件解析与必填字段
- The file reads from a directory is exactly
sbx env— no other name, and a directory-namedsbxenv.yamlat the project level is not read as a project's own file (only the home-directory base layer uses that hidden name; see below)..sbxenv.yaml - Every environment file requires and
schemaVersion: "1"(a built-in agent name or the manifest name of an agent kit supplied viaagent:). Everything else is optional.kits:needs no credentials and is the simplest way to validate a file's mechanics.agent: shell - accept one or more
sbx env create|run|plan|exec|rmarguments. EachPATHis either a directory (resolved toPATH) or the file itself. Passing more than one deep-merges them in declaration order —<PATH>/sbxenv.yaml-style semantics: later files override earlier ones, mappings merge key-by-key, sequences concatenate.docker compose -fbashsbx env create sbxenv.yaml override.yaml
- 从目录读取的文件恰好是
sbx env——没有其他名称,项目级别的sbxenv.yaml不会作为项目自身的文件被读取(只有主目录基础层使用该隐藏名称;见下文)。.sbxenv.yaml - 每个环境文件都需要 和
schemaVersion: "1"(一个内置 agent 名称,或通过agent:提供的 agent kit 的 manifest 名称)。其他一切均可选。kits:不需要任何凭据,是验证文件机制的最简单方式。agent: shell - 接受一个或多个
sbx env create|run|plan|exec|rm参数。每个PATH要么是目录(解析为PATH),要么是文件本身。传递多个时会按声明顺序进行深层合并——<PATH>/sbxenv.yaml风格语义:后面的文件覆盖前面的文件,映射按键逐一合并,序列拼接。docker compose -fbashsbx env create sbxenv.yaml override.yaml
Naming, workspace, and the .sbxenv.yaml
user base layer
.sbxenv.yaml命名、工作区与 .sbxenv.yaml
用户基础层
.sbxenv.yaml- Unless the file sets or
name:overrides it, the sandbox is named after the mounted directory (or the project directory when nothing is mounted) — so an environment that mounts nothing is still the same sandbox every time it is applied. Two different environment files in the same directory derive the same sandbox name and collide unless each sets its own--name(or you pass a distinctname:per invocation) — always give each environment its own explicit--namewhen more than one may exist in the same directory.name: - names the read/write mount, exactly like
workspace:'s omitted-path behavior: omittingsbx createmounts nothing at all. A relativeworkspace:path resolves against the directory of the file that declares it —workspace:mounts the directory the file sits in.workspace: .names the project directory (the one holding the first${{ env.projectDir }}, or cwd when none is named);PATHnames the declaring file's own directory. Nothing else is expanded — a bare${{ env.fileDir }}is literal text, so a value written for the container ($) reaches it unchanged.PATH: $PATH:/opt/binyamlworkspace: . # mounts the directory this file sits in # workspace: ${{ env.projectDir }} # mounts the project directory explicitly - Relative kit sources follow the same file-directory anchoring rule as
(see
workspace:for kit reference syntax).docker-sandboxes-kits - Files within a mounted workspace get default read-only masking, and that
protection is complete only when the file sits directly at the mount's own
root. A read-only bind at the mount point cannot be renamed by the
sandbox — there is nothing above it inside the mount to rename. But an
environment file in a subdirectory of a read-write mount is protected
only at its current path: the sandbox can rename the containing directory
(which it can write to) and then recreate the original path itself,
landing a sandbox-controlled file back where the read-only bind no longer
applies. calls this gap out explicitly for a file that is not at a mount's root. Do not claim renaming the containing directory creates no gap — for anything but the mount root, it does.
sbx env plan - With no given, an
PATHin the home directory is merged underneath as a base layer for defaults shared across projects; naming any.sbxenv.yamlskips this layer entirely. The base layer may not setPATH(which identifies one project) and itsname:must be rooted atworkspace:— any other value would mount one fixed directory under every project that merges it.${{ env.projectDir }}
- 除非文件设置了 或由
name:覆盖,sandbox 以挂载的目录命名(如果未挂载任何内容,则以项目目录命名)——因此一个不挂载任何内容的环境每次应用时仍是同一个 sandbox。同一目录中的两个不同环境文件会派生出相同的 sandbox 名称并发生冲突,除非每个文件都设置了自己的--name(或者每次调用传入不同的name:)——当同一目录中可能存在多个环境时,务必为每个环境设置显式的--name。name: - 指定读/写挂载,与
workspace:省略路径时的行为完全一致:省略sbx create则不挂载任何内容。相对workspace:路径相对于声明它的文件所在目录解析——workspace:挂载该文件所在的目录。workspace: .表示项目目录(第一个${{ env.projectDir }}所在的目录,若未命名 PATH 则为当前工作目录);PATH表示声明文件自身的目录。除此之外不做任何展开——单独的${{ env.fileDir }}是字面文本,因此为容器写的值($)会原样到达。PATH: $PATH:/opt/binyamlworkspace: . # 挂载此文件所在的目录 # workspace: ${{ env.projectDir }} # 显式挂载项目目录 - 相对 kit 源与 遵循相同的文件目录锚定规则(kit 引用语法见
workspace:)。docker-sandboxes-kits - 挂载工作区内的文件默认获得只读掩码,且只有在文件直接位于挂载自身根目录时,这种保护才是完整的。 挂载点上的只读绑定无法被 sandbox 重命名——挂载内部没有比它更高的层级可供重命名。但是,位于读/写挂载子目录中的环境文件仅在其当前路径受到保护:sandbox 可以重命名包含它的目录(该目录可写),然后自行重新创建原路径,从而让 sandbox 控制的文件回到只读绑定不再适用的位置。会针对不在挂载根目录的文件明确指出这一缺口。不要声称重命名包含目录不会产生缺口——对除挂载根目录以外的任何位置来说,这确实会产生缺口。
sbx env plan - 当未指定 时,主目录中的
PATH会作为基础层合并到下方,为跨项目共享默认值;指定任何.sbxenv.yaml都会完全跳过该层。基础层不能设置PATH(那会标识某个项目),其name:必须以workspace:为根——其他任何值都会在合并它的每个项目下挂载一个固定目录。${{ env.projectDir }}
args:
— parameterizing a shared file
args:args:
— 参数化共享文件
args:- Declare named inputs under , each with a
args:(making it optional,defaultcounts as a real default) ordefault: ""(mutually exclusive), plus optionalrequired: true,description, orenum.pattern - Reference one as anywhere a value appears in the file, and supply it with
${{ env.args.NAME }}(repeatable) or--env-arg NAME=VALUE.--env-args-file PATH
- 在 下声明命名输入,每个输入带有
args:(使其可选,default也算真正的默认值)或default: ""(互斥),以及可选的required: true、description或enum。pattern - 在文件中的任意值位置用 引用某个输入,并通过
${{ env.args.NAME }}(可重复)或--env-arg NAME=VALUE提供。--env-args-file PATH
lifecycle:
— host commands and the approval plan
lifecycle:lifecycle:
— 宿主命令与审批计划
lifecycle:- declares shell commands that run on the host, outside the sandbox, with your own privileges — not inside the container. Three phases, run in this order per invocation:
lifecycle:- — runs on every
initializeandcreate, including one that only attaches to an existing sandbox. It is the one phase that can produce what the environment needs to exist (a cloned workspace, a generated file), so it must be idempotent — it reruns on every reattach.run - — runs once, after the sandbox exists, before an interactive attach takes the terminal.
postCreate - — runs before
preRemovedeletes the sandbox, whilesbx env rmcan still reach it. A failingsbx env execis only a warning — the failure itself does not block removal. After the hook, removal rechecks the approved destroy plan and sandbox identity. A new credential or changed binding not covered by that approval, or a replacement sandbox under the same name, stops removal before deletion. Review the new destroy plan before retrying.preRemove - runs no lifecycle commands at all, and requires the sandbox to already exist — it does not create one. Run
sbx env exec/sbx env createfirst.sbx env run
yamllifecycle: initialize: - command: test -d app || git clone https://github.com/acme/app postCreate: - command: ./scripts/seed-fixtures.sh preRemove: - command: ./scripts/archive-state.sh - Every command runs through the shell from the project directory by
default (override per-command with ; bound its runtime with
workdir:).timeout: - A file that declares any lifecycle command is asked about on every
invocation that reaches it, whether or not this particular invocation
changed anything — approving a command also trusts whatever it invokes,
including a script whose contents can change after the answer, so the
question is repeated rather than remembered by default. The one exception:
makes it ask again only when the commands actually change. Never treat an untrusted file's or an untrusted kit's lifecycle commands as pre-approved, and never enable
sbx settings set env.rememberHostCommands truefor a file whose commands you have not reviewed. An environment that declares no host commands at all, and whose config is otherwise unchanged from what was last approved, applies silently with no prompt. UserememberHostCommandsto run none of the declared commands for one invocation.--skip-host-commands
- 声明在宿主机上、sandbox 之外、使用你自己的权限运行的 shell 命令——而不是在容器内。三个阶段,每次调用按此顺序运行:
lifecycle:- — 在每次
initialize和create时运行,包括仅附加到已有 sandbox 的情况。它是唯一能产生环境所需内容(克隆的工作区、生成的文件)的阶段,因此它必须是幂等的——每次重新附加都会重新运行。run - — 在 sandbox 创建后、交互式附加占用终端之前运行一次。
postCreate - — 在
preRemove删除 sandbox 之前运行,此时sbx env rm仍可访问它。失败的sbx env exec只是警告——失败本身不会阻止删除。钩子执行后,删除会重新检查已批准的销毁计划和 sandbox 身份。该审批未覆盖的新凭据或更改后的绑定,或同名替换 sandbox,会在删除前中止删除。重试前请审查新的销毁计划。preRemove - 完全不运行任何生命周期命令,且要求 sandbox 已存在——它不会创建 sandbox。请先运行
sbx env exec/sbx env create。sbx env run
yamllifecycle: initialize: - command: test -d app || git clone https://github.com/acme/app postCreate: - command: ./scripts/seed-fixtures.sh preRemove: - command: ./scripts/archive-state.sh - 默认情况下,每条命令都在项目目录中通过 shell 运行(可用 按命令覆盖;可用
workdir:限制其运行时间)。timeout: - 任何声明了生命周期命令的文件,在每次到达它的调用中都会被询问,无论本次调用是否改变了任何内容——批准一条命令也意味着信任它所调用的任何内容,包括可能在回答后内容发生变化的脚本,因此默认情况下该问题会被重复询问,而非记住。唯一例外:使其仅在命令实际变化时再次询问。绝不要将不受信任的文件或不受信任的 kit 的生命周期命令视为已预先批准,也绝不要对未审查过命令的文件启用
sbx settings set env.rememberHostCommands true。一个完全不声明宿主命令、且配置与上次批准相比没有变化的环境,会静默应用且不提示。使用rememberHostCommands可在单次调用中不运行任何已声明命令。--skip-host-commands
The environment plan: what it is and is not
环境计划:它是什么与不是什么
- prints everything applying the file would set up — host commands, credentials/bindings, MCP registrations, directories, published ports, the sandbox itself, and its variables — compared against what was last applied/approved. It changes nothing.
sbx env plan [PATH...] - /
sbx env createshow the same plan and require approval before doing any work (sbx env run/--auto-approveskips the prompt for non-interactive use — never default to-yfor a file or kit you have not reviewed). A secret's literal-yis the one field shown both in the plan and recorded to state as avalue:digest rather than in the clear; asha256:/ref:secret shows where the credential comes from, not its resolved value.command:
- 打印应用该文件将设置的一切——宿主命令、凭据/绑定、MCP 注册、目录、已发布端口、sandbox 本身及其变量——并与上次应用/批准的内容进行比较。它不会更改任何内容。
sbx env plan [PATH...] - /
sbx env create显示相同的计划,并在做任何工作之前要求批准(sbx env run/--auto-approve可跳过非交互使用的提示——绝不要对未审查过的文件或 kit 默认使用-y)。secret 的字面-y是唯一一个在计划中显示并记录到状态中时以value:摘要而非明文形式出现的字段;sha256:/ref:secret 显示凭据来源,而不是其解析后的值。command:
Secrets, registries, and bindings scoped to the environment
作用域于环境的 secrets、registries 和 bindings
- and
secrets:provision into the same credential storeregistries:uses, at this environment's sandbox scope, sosbx secret setcan remove exactly what it created. Each entry uses the samesbx env rm/value/refshape ascommand(exactly one of the three) — seesbx secret setfor what those mean at runtime and why a literal secret value should not otherwise appear in a checked-in file.docker-sandboxes-network-credentials - are per-service credential bindings merged into the user's global
bindings:; unlikecredentials.yaml/secrets:, they are left in place by default byregistries:(they are user-wide and may be shared with other sandboxes/environments) — passsbx env rmto also remove them.--prune-bindings - Never write a literal secret value directly into a checked-in
. Use
sbxenv.yaml(1Password/AWS Secrets Manager) orref:so the value never lives in the file at all; if a literalcommand:is used transiently, both the plan and state show only its digest, but the original environment file still contains the plaintext secret. See the labeledvalue:fragment below for the shape — it is intentionally not part of the minimal asset, which needs no credentials at all to validate.secrets:yaml# OPTIONAL fragment — add only if this environment actually needs a # credential; the minimal asset omits this entirely. secrets: anthropic: ref: op://Private/Anthropic/api-key # never a literal `value:` in a checked-in file refresh: 55m
- 和
secrets:配置到registries:使用的同一凭据存储中,范围为此环境的 sandbox 作用域,因此sbx secret set可以精确移除它创建的内容。每个条目使用与sbx env rm相同的sbx secret set/value/ref形态(三者恰好一个)——运行时的含义以及为什么字面 secret 值不应出现在入库文件中,请参见command。docker-sandboxes-network-credentials - 是合并到用户全局
bindings:中的按服务凭据绑定;与credentials.yaml/secrets:不同,registries:默认会将其保留在原处(它们是用户级的,可能与其他 sandbox/环境共享)——传入sbx env rm也会一并移除它们。--prune-bindings - 绝不要将字面 secret 值直接写入入库的 。 使用
sbxenv.yaml(1Password/AWS Secrets Manager)或ref:,这样值永远不会存在于文件中;如果临时使用字面command:,计划和状态都只显示其摘要,但原始环境文件仍包含明文 secret。参见下面的带标签value:片段了解其形态——它有意不包含在最小资产中,因为最小资产不需要任何凭据即可验证。secrets:yaml# OPTIONAL fragment — add only if this environment actually needs a # credential; the minimal asset omits this entirely. secrets: anthropic: ref: op://Private/Anthropic/api-key # never a literal `value:` in a checked-in file refresh: 55m
kits:
, additionalWorkspaces:
, mcp:
, ports:
, and sandboxOptions:
kits:additionalWorkspaces:mcp:ports:sandboxOptions:kits:
、additionalWorkspaces:
、mcp:
、ports:
与 sandboxOptions:
kits:additionalWorkspaces:mcp:ports:sandboxOptions:- composes mixin kits (and, exactly once, an agent kit whose name matches
kits:) onto the base agent; a relative source anchors to the declaring file's own directory, the same rule asagent:.workspace: - mounts extra directories beyond the primary
additionalWorkspaces:(a file cannot declare one without the other) — theworkspace:equivalent ofsbxenv.yaml's extra positional workspace arguments withsbx run.:ro - registers MCP servers on the host and adds them to the sandbox's fixed (static) MCP set at create time; registrations are host-global and left in place by
mcp.servers:.sbx env rm - pins explicit host-port bindings for container ports the sandbox exposes — the equivalent of
ports:— and is torn down automatically whensbx ports --publishdeletes the sandbox.sbx env rm - (beyond
sandboxOptions:, below) maps onto the remainingwritableEnvFilesflags:sbx create,template,memory,cpus,pullPolicy,profile.skills
See for the exact field shapes, required
keys, and a YAML example for each of the five blocks above.
references/env-schema-fields.md- 将 mixin kit(并且恰好一次,一个名称与
kits:匹配的 agent kit)组合到基础 agent 上;相对源锚定到声明文件自身的目录,与agent:规则相同。workspace: - 挂载主要
additionalWorkspaces:以外的额外目录(一个文件不能只声明其中一个而不声明另一个)——相当于workspace:的额外位置工作区参数加sbx run。:ro - 在宿主机上注册 MCP 服务器,并在创建时将它们添加到 sandbox 的固定(静态)MCP 集合中;注册是宿主全局的,
mcp.servers:会保留它们。sbx env rm - 为 sandbox 暴露的容器端口固定显式的宿主端口绑定——相当于
ports:——并在sbx ports --publish删除 sandbox 时自动拆除。sbx env rm - (除下面的
sandboxOptions:外)映射到剩余的writableEnvFiles标志:sbx create、template、memory、cpus、pullPolicy、profile。skills
有关以上五个块的精确字段形状、必需键和 YAML 示例,请参阅 。
references/env-schema-fields.mdsandboxOptions.writableEnvFiles
— a deliberate, explicit downgrade
sandboxOptions.writableEnvFilessandboxOptions.writableEnvFiles
— 一种有意且显式的降级
sandboxOptions.writableEnvFiles- By default, every environment file mounted inside the workspace is read-only at its own path, even though the rest of the mount is writable. This stops an agent editing the very file that decides what host lifecycle commands and secret-resolving commands run on your machine on the next invocation.
- Set only where an agent is deliberately meant to edit its own environment file. This is a real security downgrade — the plan then reports the file as writable — so treat it the same as any other explicit trust decision, not a default.
sandboxOptions.writableEnvFiles: true - The protection is complete only at a mount's own root. A file placed
directly at the root of a read-write mount cannot be reached even by
renaming, because the sandbox cannot rename the mount point itself. A file
in a subdirectory of that mount is a different case: it is read-only at
its current path, but the sandbox can rename the directory holding it
(which it can write to) and recreate a file at the original path, ending
up with a sandbox-controlled file there. flags this gap for a file that is not directly at a mount's root — read the plan's output rather than assuming renaming is always harmless.
sbx env plan
- 默认情况下,挂载在工作区内的每个环境文件在其自身路径上是只读的,即使挂载的其余部分是可写的。这可以防止 agent 编辑那个决定下次调用时哪些宿主生命周期命令和 secret 解析命令会在你机器上运行的文件。
- 仅在确实有意让 agent 编辑其自身环境文件时设置 。这是一种真正的安全降级——计划随后会将该文件报告为可写——因此要像对待任何其他显式信任决策一样对待它,而不是默认值。
sandboxOptions.writableEnvFiles: true - 该保护仅在挂载自身根目录处是完整的。 直接放置在读/写挂载根目录的文件,即使通过重命名也无法被触及,因为 sandbox 无法重命名挂载点本身。位于该挂载子目录中的文件则是另一种情况:它在其当前路径上是只读的,但 sandbox 可以重命名包含它的目录(该目录可写),并在原路径重新创建一个文件,最终在那里得到 sandbox 控制的文件。会标记这种缺口,针对不直接位于挂载根目录的文件——请阅读计划输出,而不是假设重命名总是无害的。
sbx env plan
Related skills
相关 skills
- For the /
sbx create/runflag-based workflow this file wraps, userm.docker-sandboxes-lifecycle - For what /
secrets:/registries:mean at runtime, and for configuring network policy independent of any environment file, usebindings:.docker-sandboxes-network-credentials - For the schema of the kit a
spec.yamlentry (orkits:pointing at an agent kit) references, useagent:.docker-sandboxes-kits
- 对于该文件所包装的基于 /
sbx create/run标志的流程,请使用rm。docker-sandboxes-lifecycle - 要了解 /
secrets:/registries:在运行时的含义,以及配置独立于任何环境文件的网络策略,请使用bindings:。docker-sandboxes-network-credentials - 要了解 条目(或指向 agent kit 的
kits:)引用的 kitagent:的 schema,请使用spec.yaml。docker-sandboxes-kits
References
参考资料
- — provenance for every rule above (help captures, source paths, docs URLs).
references/sources.md - — exact field shapes and YAML examples for
references/env-schema-fields.md,kits:,additionalWorkspaces:,mcp:, andports:.sandboxOptions:
- — 上述每条规则来源(帮助捕获、源路径、文档 URL)。
references/sources.md - —
references/env-schema-fields.md、kits:、additionalWorkspaces:、mcp:和ports:的精确字段形状及 YAML 示例。sandboxOptions:
Assets
资产
- — a complete, minimal, safe example: a
assets/sbxenv.yamlagent mounting the declaring file's own directory, one static env var, and no credentials at all — it validates and plans without any onboarding authentication.shell
- — 一个完整、最小、安全的示例:一个
assets/sbxenv.yamlagent 挂载声明文件自身的目录、一个静态环境变量、且完全没有任何凭据——它无需任何 onboarding 认证即可验证和规划。shell
Checks
检查
- — Verification runbook for sbxenv.yaml commands (unexecuted runbook; run manually with an isolated, uniquely-named
checks/verification.md, never with real secret values or untrusted lifecycle commands auto-approved).--app-name
- — sbxenv.yaml 命令的验证手册(未执行的 runbook;请手动使用隔离的、唯一命名的
checks/verification.md运行,绝不要使用真实 secret 值,也不要自动批准不受信任的生命周期命令)。--app-name