Agent Skills guide
Skill scripts: bundling code in a skill without making it unsafe
When a skill should ship a script instead of instructions, how to write skill scripts agents can run reliably, and what a reviewer checks before trusting one.
Bookmark
Bookmarks are kept in your free account, so you can find this page again on any device.
Sign in to bookmarkOn this page
Skill scripts are executable files, usually in a scripts/ folder next to SKILL.md, that the agent runs instead of writing the same code from scratch each time. Bundle one when a task needs exact, repeatable output; make it non-interactive, pin its dependencies and say in SKILL.md when to run it. Only the script’s output enters the context.
A skill can be pure instructions, or it can ship code in a scripts/ folder that the agent runs. Scripts make some skills far more reliable. They also turn a skill from text you can read in a minute into software that runs with your permissions. This guide is about getting the first benefit without the second cost, from both sides: the author bundling a script, and the reviewer deciding whether to trust one. For the basics of the format, see what Agent Skills are; the SKILL.md format reference covers the compatibility and allowed-tools fields mentioned below.
When a skill script beats instructions
The model is good at judgement and bad at exactness. Give it a script when the task needs:
- Precise, repeatable output. Anthropic’s Slack GIF creator leaves drawing to the model but ships a validator that checks dimensions, frame rate and file size. “Is this under Slack’s limit?” becomes a pass or fail instead of a guess.
- Measurement. Trail of Bits rebuilt its supply chain risk auditor around scripts after the agent, collecting numbers by hand, reported the wrong maintainer counts and download figures. The skill now says plainly: run the collector and quote what it measured.
- Fiddly formats. Anthropic’s document skills (docx, xlsx, pptx) use scripts to unpack and repack Office files rather than asking the model to write that code each time.
- Something the model keeps getting wrong. If your skill has three paragraphs of “do it this way, not that way” about one command, a script that does it right is shorter.
Scripts also save context. The agent runs the script and sees only its output; the source never enters the context window unless the agent opens it.
Stay with instructions when the task is mostly judgement (reviewing code, writing copy), when the steps differ every time, or when the script would only wrap one obvious command.
Writing skill scripts agents can run
An agent is a poor interactive user. It cannot answer a prompt halfway through, it reads output literally, and its tool output is usually truncated somewhere in the tens of thousands of characters. Write for that.
- Non-interactive. Take input from arguments, environment variables or stdin. Never wait for a keypress or a
[y/N]. --helpthat explains itself, and a usage message on bad input.- Structured output on stdout (JSON or CSV), diagnostics on stderr, and distinct exit codes.
- Bounded output. Summarise, paginate or write large results to a file and print the path.
- A
--dry-runfor anything that changes files, systems or accounts. - Fail loudly. Supply chain risk auditor exits non-zero when it measured nothing, rather than printing a clean-looking empty report.
- Declare dependencies inline so the script runs without a setup step. For Python, a PEP 723 block run with
uv run:
# /// script
# requires-python = ">=3.11"
# dependencies = ["pillow==11.3.0"]
# ///
"""Check an image against size limits. Prints JSON; exits 1 if it fails."""
import argparse
import json
import os
import sys
from PIL import Image
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("path")
parser.add_argument("--max-bytes", type=int, default=128_000)
parser.add_argument("--max-side", type=int, default=128)
args = parser.parse_args()
with Image.open(args.path) as img:
width, height = img.size
size = os.path.getsize(args.path)
ok = size <= args.max_bytes and max(width, height) <= args.max_side
print(json.dumps({"ok": ok, "bytes": size, "width": width, "height": height}))
return 0 if ok else 1
if __name__ == "__main__":
sys.exit(main())
The agent runs uv run scripts/check_image.py out.gif and gets one line of JSON back.
Paths that work everywhere
Refer to scripts relative to the skill folder (scripts/check_image.py) and say whether the agent should run or read them. Two habits in published skills break portability:
- Hard-coded install paths. Several skills from OpenAI’s old catalogue build paths from
$CODEX_HOME/skills/<name>/, which only exists for Codex user installs. In Claude Code,${CLAUDE_SKILL_DIR}resolves to the skill’s folder; elsewhere, a relative path is the safe choice. - Files outside the skill folder. Trail of Bits’ constant-time analysis runs an analyser that lives one level up, in the plugin. Superpowers’ executing plans calls scripts from a sibling skill. Both work when installed as the full plugin and break when someone copies only the skill folder, which is exactly what
npx skills add --skillandgh skill installdo. Keep everything a skill needs inside its folder, or say clearly in the SKILL.md that it needs the whole plugin.
Output can depend on the network too. Anthropic’s algorithmic art produces a viewer that loads p5.js from a CDN, so the result does not work offline or under a strict content security policy. Say so in the SKILL.md when that is the case. K-Dense’s RDKit skill does the opposite well: it records the tested Python and RDKit versions in the compatibility field and needs no network once installed.
Remember the runtime differs by surface. In the Claude API container there is no network and no package installation at run time, so a script that pip installs will fail there. In Claude Code, Codex or Cursor, the script runs on your machine with your network and files.
What a reviewer looks for
If you install skills from others, the scripts are where to spend your attention. Open every file in scripts/ (and anything else executable) and check:
- Network calls.
curl,wget,requests,fetch, sockets. Where does data go, and is that what the skill says it does? - Credential and home-folder access. Reads of
~/.ssh,~/.aws,.env, browser profiles, keychains. - Obfuscation. Base64 blobs, long encoded strings,
eval/execon built strings, minified code in a skill that has no reason for it. - Downloads that run. Fetching and executing anything at install or run time, including
curl ... | sh. - Destructive commands without a dry run or confirmation.
- Pre-approved tools.
allowed-tools: Bashorshellin the frontmatter lets the script run without the agent asking you. Fine for a skill you wrote; a reason to slow down for one you did not. - Unpinned dependencies.
pip install foowithout a version can change underneath you.
For authors: make review easy
Reviewers trust what they can understand quickly. Keep scripts short and single-purpose, avoid clever one-liners, pin dependencies, document what each script touches at the top of the file, and list external needs in the compatibility field (“Requires Python 3.11+ and uv; needs network access to api.example.com”). A skill that is easy to audit gets installed; one that looks like it is hiding something gets deleted.
The full review procedure is in our security checklist for third-party skills and the audit a skill before installing workflow. The script-backed and gated loop shapes in Agent Skill design patterns show where scripts fit in a larger skill, and how to create a Claude skill builds a small one with a Git helper script from scratch.
Related
- Are Agent Skills safe? A security checklist for third-party skills
Are agent skills safe? What can go wrong when you install someone else's skill, what researchers found in public registries, and a fifteen-minute review.
- Agent Skill best practices: nine design patterns with real examples
Agent skill best practices as nine design patterns, from checklists and routers to script-backed and gated skills, each with a real example and when to use it.
- Scan a third-party Agent Skill before you install it
Read every file, grep scripts for risky patterns, run a skill scanner, then record a yes or no and pin it.
- allowed-tools
An experimental SKILL.md frontmatter field listing tools the agent may use without asking while the skill is active. Support varies by agent.
- Skill recipe: turn an incident runbook into a skill
A worked runbook skill for one service: a triage checklist, a read-only diagnostics script, and fixes the agent may only propose until a person says yes.