sandcast-capture
Capture the current project and the host environment (languages, host tools, curated shell configuration, agent harnesses) into a sandcast manifest at .sandcast/manifest.yaml.
- License 许可
- Apache-2.0
- 最近更新
- 2026-10-25
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- sandcast-capture
- description
- Capture the current project and the host environment (languages, host tools, curated shell configuration, agent harnesses) into a sandcast manifest at .sandcast/manifest.yaml.
- sandcast_version
- 0.2.1
03 SKILL.md 正文
sandcast capture
You turn the current project directory and the developer's host environment into a sandcast manifest (.sandcast/manifest.yaml).
The sandcast binary provides every fact you need. Your job is judgment: present what the binary found, let the user decide, curate the shell configuration, and write the result.
The build happens later, through /sandcast-build or sandcast build.
Rules
Follow these rules in every step. They are part of the sandcast contract and a reviewer checks them.
- Facts come from the binary. Component keys, match evidence, host tool versions, harness discovery and validation results come from
sandcast ... --json. Never invent a component key, a version, or a configuration value the binary did not report. - Never handle credentials. Never ask for, print, copy, or write a secret value (tokens, API keys, passwords, private keys). The binary replaces discovered secrets with
${SANDCAST_SECRET_N}placeholders. Keep each placeholder exactly as returned and tell the user to supply the real value at runtime as a credential of the OpenShell provider attached to the sandbox. - Write only the manifest. You create or change
.sandcast/manifest.yamlthroughsandcast init,sandcast manifest set-shelland direct edits, and.sandcast/mise.lockthroughsandcast lock. Never write a Containerfile or any other image definition (FR-037), never touch.sandcast/build/,.sandcast/fragments/or.sandcast/recipes/. The one exception: with the user's consent, copy a chosen skill or local marketplace from outside the project into the project (Step 2). - Ask before deciding. Every component, harness extension and shell change ends up in an image the user runs. Present proposals with their evidence and wait for confirmation.
- Run commands from the project root (or pass
--project <dir>). Exit codes: 0 success, 1 operation failed, 2 usage or validation error, 3 external tool missing or at the wrong version. - Temporary files live outside the project: create them with
mktemp, never under a fixed name in a shared directory, and delete them when the step is done.
Step 1: Check the skill and binary versions
Run:
sandcast skills check --harness claude-code
- Exit 0: continue.
- Exit 3: the installed skills and the binary disagree. Print the message exactly as the command printed it, tell the user which side to update, and stop. The message names it:
run "sandcast skills install --harness claude-code"when the skill is missing or older than the binary,update the sandcast binarywhen the skill is newer. - Command not found: tell the user to install the
sandcastbinary first and stop. - Any other failure: show the output and stop.
Step 2: Choose the harnesses
Ask the user upfront which agent harnesses the image should include (FR-036). Show what this host has:
sandcast harness list --json
Each entry has name, component, installed and path. Offer exactly the harnesses this list reports, marking which are installed on the host. If the user asks for a harness the list does not report, say that its adapter is not available yet and leave it out. The user may also choose no harness at all.
For each selected harness only, run discovery with the harness name from the list (for example claude-code):
sandcast harness discover <harness> --json
Run it once per selected harness and handle each result with the steps below. If the user selected no harness, skip discovery and continue with Step 3.
The JSON has harness, mcp_servers (each with name, command or url, env, origin), plugins and skills (each with name, source, origin, portable, and reason when portable is false), redacted (each with path, kind, placeholder, env_var) and notes. A plugin whose local marketplace directory is a git checkout with a remote comes with a remote object (url, unpushed_commits, uncommitted_changes, name_match) and a source taken from that remote (owner/repo for GitHub, else the remote URL).
-
Present the MCP servers, plugins and skills as three short groups, each item with its origin file. For MCP servers show the environment variable names, not their values.
-
For each non-empty group, ask which items to bake into the image with a multi-select prompt: a checkbox list the user ticks, not a request to type item numbers. Use the harness's multi-select control when it has one (for example, in Claude Code,
AskUserQuestionwithmultiSelect: true), and fall back to a numbered list only when the harness has no such control. Offer MCP servers, plugins and skills as three separate multi-select prompts so each is chosen independently. Nothing is baked by default: an empty selection bakes none. -
Check the
portablemarker of every chosen skill and plugin; do not decide by looking at the path yourself. An entry withportable: falsemakes the manifest host-specific: the binary reads its source on the machine that runs the plan, sosandcast planandsandcast buildfail in CI and on every other machine that lacks the path. Show itsreason. For each such skill, explain this and offer to copy it into the project:- Ask first. If the user declines, keep the discovered source and say that only this host can build the image.
- Copy only the skill directory, to
.claude/skills/<name>in the project, and never overwrite an existing directory. List its files first and leave out every file that holds a credential (.envfiles, private keys such as*.pemor*.key, files named like token, secret or credentials); if the skill needs such a file, stop and ask. Show symbolic links and ask before copying them. - The name filter misses a token inside an ordinary file, such as a script or a
config.json, and no sandcast command scans the copied files before a commit. So after copying, show the user the list of copied files (paths only, never their contents) and ask them to confirm that none of them holds a credential. Remove every file they are unsure about, or stop and ask. - Record
source: .claude/skills/<name>for the skill. Only after the user has confirmed the file list, remind them to commit the directory; check that.gitignoredoes not exclude it.
For a non-portable local marketplace, explain the same limit and offer two remedies: copy the marketplace directory into the project (same rules) and use its
./path as the plugin source, or publish it as a git repository and useowner/repoor its URL.A plugin with a
remoteobject was proposed through the git remote of its local marketplace, so you need no manual remote lookup. It stays opt-in like every other plugin. Before the user decides, present its remote notes: the remoteurl;unpushed_commitsgreater than 0 oruncommitted_changes: truemeans the image gets the remote's state, not the local one, so the user should push first, andunpushed_commits: nullmeans the count is unknown because no remote-tracking ref exists locally;name_match: mismatchmeans the remote's marketplace file declares another name than the locally registered one, andname_match: unknownmeans it could not be checked: no remote-tracking ref exists locally (discovery never fetches), or the remote's marketplace file is missing or declares no name. -
For every entry in
redacted, explain: the value atpathlooked like a credential (kind), the binary replaced it withplaceholder, and the user supplies the real value at runtime as a provider credential under the environment variable named inenv_var(theenvkey when the whole env value was the secret,SANDCAST_SECRET_Nfor a secret inside a longer value, an argument or a URL, including an access key in a URL path). Never offer to fill in the value. MCP servers reached byurlcarry their bearer credential as oneenventry, either a placeholder such asMCP_<NAME>_TOKEN: "${SANDCAST_SECRET_N}"or a reference such asVAR: "${VAR}". Keep both forms unchanged. -
Show every
notesentry.
Do not run discovery for harnesses the user did not select. Unselected harnesses leave no trace in the manifest.
Step 3: Create the manifest and choose the components
If .sandcast/manifest.yaml does not exist, ask for the manifest name (kebab-case, default: the directory name), the target (openshell by default, or container) and the base image. Show the registry entries for the chosen target:
sandcast base-images list --target <openshell|container> --json
Each entry has target, name, ref, default and notes. Show the notes; they say which user and tools the image has.
Ask where the image will run, because sandcast init never asks:
-
A local OpenShell gateway that uses the same container engine on this machine (for example a gateway with the podman driver): the default
localhost/<name>works. Create the skeleton:sandcast init --name <name> --base-image <registry-entry-or-image-ref> --target <openshell|container> -
A remote gateway (a cluster, a cloud gateway, or any gateway that cannot read this engine's image storage): ask for the registry reference the cluster can pull (for example
quay.io/<user>/<name>, neverdocker.io/<name>without a namespace) and the cluster's architecture (linux/amd64for most clusters), and pass them with push enabled:sandcast init --name <name> --base-image <registry-entry-or-image-ref> --target openshell --image <registry/name> --platform <linux/amd64|linux/arm64> --pushWhen the platform differs from this machine's architecture, point the user to
docs/guides/cross-arch.md.
If the manifest already exists, read it, tell the user you will update it, and keep its existing entries unless the user removes them.
Now let the binary match the project and the host against the component tiers. Add one --harness <harness> per selected harness so the agent components are proposed too; pass no --harness flag when the user selected no harness:
sandcast components match . --host --harness <harness> --json
The JSON shape is:
{"project": "<dir>",
"proposals": [{"key": "go", "name": "Go", "source": "project", "evidence": ["go.mod"], "detected_version": "1.25.1",
"pinned_versions": [{"value": "1.26.7", "file": "go.mod", "kind": "exact"}]}],
"available": [{"key": "rust", "name": "Rust", "tier": "shipped"}],
"notes": []}
pinned_versions lists every version the project pins for the component, with its file and its kind: exact (a full version such as 1.95.0), range (>=3.12, ^20, 1.26) or channel (stable, nightly, lts/*). Show every notes entry; a note names a pin file that could not be read.
source is one of project (ecosystem files), host (a tool found on the host PATH), harness (a selected harness) or always (base system components).
- Present the proposals grouped by source as a table with key, name, evidence and detected version.
- If no proposal has the source
project, say explicitly: "No recognizable ecosystem files were found in this project." Then still offer the host tools and theavailablecomponents as optional additions. - Offer the
availablecomponents as optional additions. - Let the user confirm, drop or add components. Keep
alwaysproposals unless the user explicitly removes them. - Additions must be keys from
proposals,available, orsandcast components list --json. If the user wants a tool that no tier defines, explain the two choices: add it withoptional: trueso that/sandcast-buildoffers to write an install fragment for it, or let the user define it in.sandcast/components/<key>.yamlfirst. The user writes that file; you may show the shape fromsandcast components show <similar-key>, but do not write it yourself. - Set
versionon a component only when the user asks for a specific version or the project pins one. When a proposal haspinned_versions, propose the firstexactvalue as the component'sversion:(for go only the first entry counts: it is the highest version across ago.work's modules, and when it is arangesuch as1.27a lower exact pin is not proposed), name the file it came from, and let the user accept or change it. Never turn arangeorchannelvalue into an exact pin; mention it, and leaveversionout unless the user chooses a version. Without a pin, leaveversionout; the lockfile pins exact versions.
Keep the confirmed list in mind; you write it in Step 5.
Step 4: Curate the shell configuration
The image gets a curated copy of the user's interactive shell configuration, installed under /etc for the final user.
Host configurations carry plugin managers, macOS paths and host-only tools that break inside a Linux sandbox. The rules below encode the failures recorded in earlier image builds (brainstorm 072, changes 7, 11, 12 and 13).
Find the login shell with basename "$SHELL".
zsh: read${ZDOTDIR:-$HOME}/.zshrc.bash: read~/.bashrc(or~/.bash_profilewhen there is no.bashrc).- Any other shell: say that sandcast curates only zsh and bash. Ask whether to skip the shell configuration or to write a minimal zsh or bash configuration with the user. If the user skips it, continue with Step 5.
If the file sources other files from the home directory that hold aliases or functions, ask before reading them. Never print a line that sets a credential; refer to it by line number and variable name only.
4a: Strip
Remove these lines, and tell the user what you removed and why:
- Plugin managers and everything they load: antidote (
source .../antidote.zsh,antidote load,antidote bundle), oh-my-zsh (export ZSH=...,ZSH_THEME=...,plugins=(...),source $ZSH/oh-my-zsh.sh), zinit (source .../zinit.zsh, everyzinit ...line), zplug (source ~/.zplug/init.zsh, everyzplug ...line). Treat antigen, prezto, zgenom, sheldon and znap the same way. For bash: oh-my-bash (export OSH=...,OSH_THEME=..., theplugins=(...),completions=(...)andaliases=(...)arrays,source "$OSH"/oh-my-bash.sh), bash-it (export BASH_IT=...,BASH_IT_THEME=...,source "$BASH_IT"/bash_it.sh) and ble.sh (source .../ble.sh,ble-attach). List the plugins that are lost, so the user knows. - Homebrew, Linuxbrew and host paths: anything under
/opt/homebrew,/usr/local/Homebrew,/usr/local/opt,/usr/local/Cellar,/home/linuxbrew/.linuxbrew,~/.linuxbrew,/Applications,/Library,~/Libraryor/System, plusbrew shellenv,$(brew --prefix ...),HOMEBREW_*andDYLD_*. In aPATHassignment remove only the host entries and keep the portable ones, for exampleexport PATH="/opt/homebrew/bin:$HOME/.local/bin:$PATH"becomesexport PATH="$HOME/.local/bin:$PATH". Absolute paths into the host home (/Users/<name>/...,/home/<name>/...): rewrite to$HOME/...only when the image provides the target or a missing target is harmless (aPATHentry); otherwise drop the line. - Host-only tools and integrations: macOS commands (
pbcopy,pbpaste,open,osascript,defaults,security,launchctl), terminal integrations (iTerm2 shell integration and similar), agent setup (ssh-agent,ssh-add,gpg-agent,keychain), SDK loaders from host paths, and version managers (mise activate,asdf,nvm,pyenv init,rbenv init,condainit blocks,sdkman). The image installs tools with mise and puts them onPATHwithout activation. - Sourced host files that do not exist in the image (
source ~/.zsh_local,source ~/.config/zsh/aliases.zsh). If the user wants their content, inline the relevant parts after applying these same rules. - Credentials: every line that exports a token, key, password or secret, and every export whose value comes from a command or file that yields a credential: keychains and password managers (
security find-generic-password,op read,pass,gopass), CLI token commands ($(gh auth token),$(aws configure get ...)), and secret files ($(cat ~/.secrets/...)). Do not repeat the value. Tell the user to supply the variable as a provider credential at runtime.sandcast manifest set-shellrefuses configurations with credential-shaped values.
Keep aliases, functions, setopt and shopt options, history settings, bindkey lines, zstyle lines, prompt configuration, and exports of non-secret settings such as EDITOR, PAGER or LANG.
4b: Add and rewrite
Apply each rule whenever its trigger is present after stripping:
-
Completion system (zsh): the configuration needs
compinitwhen it has nocompinitcall and any of these remain:- a
compdefcall or azstyle ':completion:*'line, - a sourced or evaluated completion script, such as
source <(<tool> completion zsh),eval "$(<tool> completion zsh)"or a sourced file that starts with#compdef(these scripts callcompdef), - a stripped plugin manager that loaded
compinit.
Then insert this line before the first of those lines:
autoload -Uz compinit && compinit -i -DKeep both flags and never use
-C. The home directory can be the workspace (/sandbox), which the sandbox and the checked-out project can write.-Dkeepscompinitfrom reading or writing a.zcompdumpthere, because a planted dump file would run as shell code at every shell start.-iskips completion directories that fail the ownership check instead of stopping the shell with a prompt.Plugin managers load
compinittransitively. Without it,zstylehas no effect, every completion script printscommand not found: compdefat shell start, and tab completion falls back to plain file globbing. - a
-
Starship prompt: guard the init line so that non-interactive exec sessions with
TERM=dumbdo not print starship errors:if [[ "$TERM" != "dumb" ]]; then eval "$(starship init zsh)" fiUse
starship init bashfor bash. -
Completions of removed plugins: a stripped plugin often provided the completion that a kept
compdefline refers to (for examplecompdef kubecolor=kubectlafter an oh-my-zshkubectlplugin). Before a keptcompdefline whose completion a removed plugin provided, add a guarded load of the tool's own zsh completion, so the shell starts without errors whether or not the tool is in the image:command -v <tool> >/dev/null && source <(<tool> completion zsh)Use the tool's own command for its completion script (
kubectl completion zsh,gh completion -s zsh); when the tool has none, drop thecompdefline instead. -
fzf key bindings: replace
source <(fzf --zsh)(andeval "$(fzf --zsh)"or[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh) with this version-aware block.fzf --zshneeds fzf 0.48 or newer, and distribution packages can be older:if fzf --zsh &>/dev/null; then source <(fzf --zsh) elif [ -f /usr/share/doc/fzf/examples/key-bindings.zsh ]; then source /usr/share/doc/fzf/examples/key-bindings.zsh [ -f /usr/share/doc/fzf/examples/completion.zsh ] && source /usr/share/doc/fzf/examples/completion.zsh fiFor bash, replace
eval "$(fzf --bash)"(or~/.fzf.bash) with:if fzf --bash >/dev/null 2>&1; then eval "$(fzf --bash)" elif [ -f /usr/share/doc/fzf/examples/key-bindings.bash ]; then . /usr/share/doc/fzf/examples/key-bindings.bash fi
4c: List the referenced commands
List every external command the curated configuration references: the first word of each alias value, every eval "$(<cmd> ...)" and source <(<cmd> ...), commands called in functions, and the values of EDITOR, VISUAL, PAGER and MANPAGER. Ignore shell builtins and the base utilities every image ships (ls, cat, grep, sed, awk, find and similar).
For each referenced command, find its component with sandcast components list --json: a component whose key equals the command or whose match.host_tools contains it (for example rg belongs to ripgrep). Confirm with sandcast components show <key>; its binaries are installer.<kind>.bins, else provides, else the key.
- A component exists: add its key to
shell.components. A missing prompt or listing tool is a runtime failure the build cannot detect, so do not skip this. - No component exists: ask the user whether to drop the line or to keep it and add the command as an optional component (Step 3, item 5).
Show the user the final curated configuration and the list of referenced components. Apply their corrections.
4d: Write it
Write the curated text to a private temporary file created with mktemp, store it in the manifest, and delete the file. Run it as one shell command so that $tmp survives, and set --program to the shell you curated (zsh or bash). The snippet runs unchanged in sh, bash and zsh, in a subshell so that its exit and traps never end your own shell. It removes the file on every exit path, an interrupt included, and ends with the exit status of sandcast, so an exit 2 reaches you:
(
tmp="$(mktemp)" || exit
trap 'rm -f "$tmp"' EXIT
trap 'exit 129' HUP
trap 'exit 130' INT
trap 'exit 143' TERM
cat > "$tmp" <<'SANDCAST_RC' || exit
<the curated configuration>
SANDCAST_RC
sandcast manifest set-shell --program <zsh|bash> --file "$tmp"
)
The command also accepts the configuration on standard input. If it exits 2 because of a credential-shaped value, remove that line and write again; never weaken the value to get past the check.
Do not edit shell.rc in the manifest by hand; rerun sandcast manifest set-shell to change it.
Example
The host .zshrc:
export PATH="/opt/homebrew/bin:$HOME/.local/bin:$PATH"
source /opt/homebrew/opt/antidote/share/antidote/antidote.zsh
antidote load
zstyle ':completion:*' menu select
eval "$(starship init zsh)"
source <(fzf --zsh)
alias ls=lsd
setopt HIST_IGNORE_DUPS SHARE_HISTORY
The curated configuration:
export PATH="$HOME/.local/bin:$PATH"
autoload -Uz compinit && compinit -i -D
zstyle ':completion:*' menu select
if [[ "$TERM" != "dumb" ]]; then
eval "$(starship init zsh)"
fi
if fzf --zsh &>/dev/null; then
source <(fzf --zsh)
elif [ -f /usr/share/doc/fzf/examples/key-bindings.zsh ]; then
source /usr/share/doc/fzf/examples/key-bindings.zsh
[ -f /usr/share/doc/fzf/examples/completion.zsh ] && source /usr/share/doc/fzf/examples/completion.zsh
fi
alias ls=lsd
setopt HIST_IGNORE_DUPS SHARE_HISTORY
The referenced components are fzf, lsd and starship, so shell.components is [fzf, lsd, starship].
Step 5: Propose the dotfiles beyond the shell
The image baked configuration must survive the OpenShell home overmount: at runtime the workspace volume is mounted over the home, so anything under the home is hidden and a startup file there is never read. sandcast relocates dotfiles outside the home automatically; your job is only to propose which ones to bake.
sandcast components match reports the host dotfiles from a bounded allowlist under dotfiles in its JSON (git, the prompt tool, tmux and readline basics; the shell configuration is already handled in Step 4, so it is not repeated here). Present them with a multi-select, exactly as you do for MCP servers and plugins, and let the user confirm which to bake. Add nothing the user did not confirm.
The user may also name dotfiles the allowlist omits, within these bounds, which sandcast enforces at plan time:
- From the home, only allowlist entries and the configuration of these tools under
~/.config:git/,starship.toml,nvim/,helix/,tmux/,alacritty/,kitty/,wezterm/,ghostty/,bat/,ripgrep/(for example~/.config/ghostty/configor~/.config/nvim/init.lua). Nothing else under~/.configis read: it also holds credential stores (gh,gcloud,sops,op,containers,rclone) whose contents no redactor recognizes reliably. Use~/, never~user/, and spell the path exactly. - Any project-relative path inside the project. An absolute path only when it lies inside the project.
- Never a credential store (
~/.ssh,~/.aws,~/.gnupg,~/.kube,~/.docker,~/.config/ghand the other~/.configstores),.netrc, a history file, or a path with a segment that looks like a key, token, secret, credential or certificate. Do not propose these, and tell the user why when they ask for one. - Only regular files up to 256 KiB.
For a file outside these bounds, suggest copying it into the project and listing the project-relative path. sandcast skips an entry outside the bounds, or one that does not exist at build time, with a notice; it never fails the build.
Record the confirmed entries under dotfiles in the manifest as a list of {path: ...} entries. A ~/ path resolves against the host home; a project-relative path resolves against the project root and must stay inside it. Record only the source path, never the contents: sandcast reads the file at build time, redacts any credential shape, and bakes it to a persistent location outside the home (for example /etc/gitconfig, /etc/tmux.conf or /etc/xdg/...). Do not add a relocation target by hand; the plan chooses it.
Step 6: Write the components and harnesses, then validate
Edit .sandcast/manifest.yaml directly for the parts sandcast manifest set-shell does not write. The schema rejects unknown keys everywhere. The shape:
schema_version: 1
name: my-project
base_image: nvidia-community-base
components:
- key: git
- key: go
- key: python
version: "3.13"
- key: my-internal-tool
optional: true
harnesses:
- name: claude-code
mcp_servers:
- name: docs
command: [npx, -y, "@example/docs-mcp"]
env:
DOCS_API_KEY: "${SANDCAST_SECRET_1}"
- name: tracker
url: https://mcp.example.com/sse
env:
MCP_TRACKER_TOKEN: "${SANDCAST_SECRET_2}"
plugins:
- name: clangd-lsp@claude-plugins-official
source: anthropics/claude-plugins-official
skills:
- name: review
source: .claude/skills/review
shell:
program: zsh
rc: |
# written by sandcast manifest set-shell
components: [fzf, lsd, starship]
dotfiles:
- path: ~/.gitconfig
- path: ~/.config/starship.toml
targets:
openshell:
image: localhost/my-project
components: the confirmed list from Step 3. Leave out components already listed inshell.components, the shell program itself (zshorbash) and the agent component of each harness (claude-code); the plan adds those implicitly.harnesses: one entry per selected harness with only the MCP servers, plugins and skills the user chose. Copyname,command,url,env, andsourceexactly as discovery printed them, placeholders included, except thesourceof a skill or marketplace you moved into the project in Step 2. Drop theoriginfields. Omitharnessesentirely when the user selected none.shell.components: the referenced components from Step 4c.dotfiles: the confirmed entries from Step 5, each{path: ...}. Omitdotfilesentirely when the user confirmed none.platform: set it (linux/amd64orlinux/arm64) only when the user builds for a platform other than the host's.
Then validate:
sandcast manifest validate --json
The JSON has valid, manifest and diagnostics (each with path, line, message).
If valid is false, show every diagnostic with its line, fix what is clearly yours to fix (a typo in a key, a wrong field name), and validate again. If a diagnostic needs a user decision or reports a credential, stop and show the diagnostics; never write a credential to make validation pass.
Step 7: Offer the lockfile
Builds install mise tools in locked mode, and sandcast plan fails for a platform the lockfile lacks. Offer to generate the lockfile for the target platform (default: the manifest platform, else the host architecture). Repeat --platform for more than one:
sandcast lock --platform linux/arm64
Exit 3 means the host has no mise or one older than the minimum release named in the error message. Report every tool the command could not lock, with its platform and reason.
Finish
Summarize for the user:
- the components, harness extensions and shell components in the manifest,
- the dotfiles baked and where each one is relocated to,
- every secret placeholder and how to supply it at runtime,
- what the shell curation removed,
- the next step:
/sandcast-build(orsandcast build --verifywhen no component is unresolved).
Suggest committing .sandcast/manifest.yaml and .sandcast/mise.lock.
04 同仓库更多 Skills
review
Fixture skill review.
review
Fixture skill review.
deploy
Fixture skill deploy.
writing
Fixture skill writing.
sandcast-capture
Fixture skill sandcast-capture.
review
Fixture skill review.