Use shell tools safely in sandboxed environments by discovering files from real workspace roots instead of assumed user folders, then explicitly verifying outpu
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-sandbox-file-discovery-and-validation-435ef510694d ,按照其中的说明把「sandbox-file-discovery-and-validation」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
Use this skill when working in constrained or sandboxed shell environments where common folders like ~/Desktop, ~/Documents, or ~/Downloads may not exist, may be inaccessible, or may not be where task files are stored.
The goal is to:
/ unless necessary.Use this pattern when:
Begin by identifying where you are and what directories are actually available.
Example:
pwd
ls -la
find . -maxdepth 2 -type d | sort
If needed, inspect nearby likely roots:
ls -la /tmp
ls -la /workspace 2>/dev/null || true
ls -la /workspaces 2>/dev/null || true
ls -la /mnt/data 2>/dev/null || true
Treat only confirmed, readable directories as search roots.
Do not begin with paths like:
~/Desktop~/Documents~/Downloadsunless you have already confirmed they exist and are relevant.
Bad:
find ~/Desktop -name "*.xlsx"
Better:
find . -type f -name "*.xlsx"
or, if a root is confirmed:
find /workspace -type f -name "*.xlsx" 2>/dev/null
Prefer targeted searches over broad filesystem scans.
Useful patterns:
find . -type f | sort
find . -type f -iname "*report*"
find . -type f \( -iname "*.csv" -o -iname "*.xlsx" -o -iname "*.json" \)
If multiple roots are known:
find . /workspace /mnt/data -type f 2>/dev/null | sort
Guidelines:
2>/dev/null when appropriate,When generating a file, write it somewhere explicit and easy to re-check.
Good patterns:
./output,Example:
mkdir -p output
python make_result.py --out output/final.xlsx
Avoid writing to guessed locations that may not exist.
Never assume generation succeeded just because a command exited successfully.
At minimum, confirm:
Basic checks:
ls -l output/final.xlsx
test -f output/final.xlsx && echo "exists"
test -s output/final.xlsx && echo "non-empty"
file output/final.xlsx
For text-like outputs:
head -n 20 output/result.csv
wc -l output/result.csv
For structured outputs, inspect with the relevant tool:
.xlsx: verify internal structure or open with a libraryA file existing is necessary but not sufficient.
Check the artifact against the requested deliverable:
Examples:
When you finish, cite the exact artifact path and the validation you performed.
Good completion style:
output/final.xlsx.”Summary and Data.”This reduces false positives where an output was produced but not actually checked.
pwd
ls -la
find . -maxdepth 3 -type f | sort
find . -type f \( -iname "*.xlsx" -o -iname "*.csv" -o -iname "*.tsv" \) | sort
find . /workspace /mnt/data -type f 2>/dev/null | sort
mkdir -p output
some_command > output/result.txt
test -f output/result.txt && test -s output/result.txt && echo "validated"
pwd to anchor yourselffind from . or other verified rootsDiscover roots:
pwd && ls -la
Find candidate inputs:
find . -type f \( -iname "*.xlsx" -o -iname "*.csv" \) | sort
Create controlled output location:
mkdir -p output
Generate artifact:
python transform.py input/source.csv output/final.csv
Validate artifact exists and inspect content:
ls -l output/final.csv
test -s output/final.csv
head -n 5 output/final.csv
Validate requirement-specific properties:
This pattern is applied correctly when: