AWS Security Agent(AWS提供のセキュリティ検査サービス)によるスキャンをワークスペース上で実行します。ソースコードをAWSにアップロードし、マネージド型のセキュリティ検査サービスでスキャンしたうえで、検出された問題を重要度順にランク付けして返します。各問題の位置情報と修正方法も含めた検証済みの結果が得られます。 次のような場合に使用: ユーザーがコードのスキャン、脆弱性の検出、セキュリティ検査・レビューの実行、セキュリティ上の問題の確認、スキャン状態の確認、検出結果の表示、最近のスキャン履歴の一覧表示、またはスキャンの中止をリクエストした場合。
Run an AWS Security Agent scan on the workspace — uploads the source to AWS, scans it with the managed Security Agent service, and returns ranked, verified findings with code locations and remediations. Use when the user asks to scan code, find vulnerabilities, run a security scan or review, check security issues, check scan status, show findings, list recent scans, or stop a scan.
このスキルはリポジトリ全体のスキャンを実行します。セットアップ(エージェント スペース、ロール、バケット)は setup-security-agent スキルで処理されます。.security-agent/config.json がない場合、スキャン ワークフローが最初にセットアップを自動実行します。
| ユーザーの意図 | ワークフロー |
|---|---|
| 直接スキャンをリクエスト(「コードをスキャンして」「脆弱性を見つけて」) | フル スキャン |
| スキャンの状況確認(「スキャンの進み具合は」「進捗状況は」) | ステータス ワークフロー |
| 検出結果を表示(「何が見つかったの」「結果を表示して」) | 検出結果 ワークフロー |
| スキャンを一覧表示(「最近のスキャン」「スキャン一覧」) | .security-agent/scans.json を読み込み |
| スキャンを停止 | aws securityagent stop-code-review-job |
.security-agent/config.json から agent_space_id と region を読み込みます。config.json がない場合は、ユーザーに1行だけ表示 — 「このワークスペースでの初回スキャン — セットアップを実行します。」 — その後 setup-security-agent ワークフローをインラインで実行してから続行します。初回スキャンは「そのまま動作」するはずです。
スキャンを .security-agent/scans.json に記録します(最新50件を保持)。ワークスペースごとの CodeReview ID は config.json → code_reviews[<abs_path>] に保存されるため、その後のスキャンで同じ CodeReview を再利用できます。
以下の CLI 例ではプレースホルダーを使用しています。スキャン開始時に各値を解決してください:
| プレースホルダー | 解決方法 |
|---|---|
<id>(エージェント スペース) |
config.agent_space_id |
<region> |
config.region(デフォルト us-east-1) |
<account> |
aws sts get-caller-identity --query Account --output text(ターン全体でキャッシュ) |
<role-arn> |
arn:aws:iam::<account>:role/SecurityAgentScanRole |
<bucket> |
security-agent-scans-<account>-<region> |
<cr-id> |
code_review_id(config.json → code_reviews[<abs_path>]) |
<job_id> |
codeReviewJobId(start-code-review-job で返却) |
<WORKSPACE_ID> |
printf '%s' "$(pwd)" | md5sum | cut -c1-12 |
これらは設定に保存されず、その都度導出されるため、実態とのズレが生じません。
config.json を読み込む。 不在の場合 → setup-security-agent ワークフローをインラインで最初に実行してから続行します。
エージェント スペースがまだ存在するか確認:
aws securityagent batch-get-agent-spaces --agent-space-ids <id>
レスポンスで存在しないことが示された場合、config.json から agent_space_id をクリアしてから setup-security-agent を再度実行します。
アカウント、ロール ARN、バケット名を解決します。上の表を参照してください。
ワークスペース ID を生成:
WORKSPACE_ID=$(printf '%s' "$(pwd)" | md5sum | cut -c1-12)
変更されたコードのスキャンのみの場合、diff-scanning-with-aws-security-agent スキルを使用してください。脅威モデリング仕様の場合は、threat-modeling-with-aws-security-agent を使用します。
上記のスキャン前チェックを実行します。
ワークスペースを ZIP 圧縮します。 よくあるビルド/キャッシュ ディレクトリは除外します。.gitignore を考慮します。ZIP が 2 GB を超える場合は中止します。
cd <absolute-workspace-path>
zip -r /tmp/source.zip . \
-x ".git/*" \
-x ".security-agent/*" \
-x "node_modules/*" \
-x "__pycache__/*" \
-x ".venv/*" -x "venv/*" \
-x "dist/*" -x "build/*" -x "target/*" \
-x ".mypy_cache/*" -x ".pytest_cache/*" -x ".tox/*" \
-x ".next/*" -x "cdk.out/*" \
-x ".DS_Store" -x "Thumbs.db" \
-x "*.pyc" -x "*.pyo"
ZIP_BYTES=$(stat -f%z /tmp/source.zip 2>/dev/null || stat -c%s /tmp/source.zip)
if [ "$ZIP_BYTES" -gt 2147483648 ]; then echo "Zip too large (>2GB)"; exit 1; fi
ワークスペース固有の安定キーにアップロードします(以前のアップロードを上書き):
aws s3 cp /tmp/source.zip s3://<bucket>/security-scans/source/<WORKSPACE_ID>/source.zip --expected-bucket-owner <account>
ワークスペースごとの CodeReview を取得または作成します。 config.json → code_reviews[<abs_path>] を確認します。
存在する場合、その code_review_id を使用します。
不在の場合、作成します:
aws securityagent create-code-review --agent-space-id <id> --title <title> \
--service-role <role-arn> \
--assets sourceCode=[{s3Location=s3://<bucket>/security-scans/source/<WORKSPACE_ID>/source.zip}]
codeReviewId をキャプチャして config.json → code_reviews[<abs_path>] に保存します。
タイトルのデフォルト:pre-cr-<git-branch>(git rev-parse --abbrev-ref HEAD を使用)。スペースをハイフンに置き換えます。
ジョブを開始します:
aws securityagent start-code-review-job --agent-space-id <id> --code-review-id <cr-id>
ResourceNotFoundException の場合:CodeReview が外部で削除されました。再作成して(ステップ 4)リトライします。codeReviewJobId をキャプチャします。scan-<8-hex> のようなローカル scan_id を生成します。scans.json に追加します:
{
"scan_id": "scan-...",
"code_review_id": "cr-...",
"job_id": "cj-...",
"agent_space_id": "as-...",
"scan_type": "FULL",
"title": "pre-cr-main",
"path": "/abs/path",
"started_at": "2026-06-01T20:00:00Z",
"status": "IN_PROGRESS"
}
ユーザーに通知:「フル スキャンを開始しました(scan_id: {id})。約45分かかります。5分ごとに確認します — 「ポーリング停止」と言えばスキップできます。」
以下の ポーリング ループ を sleep 300 で実行します。
スキャン開始後:
sleep 300(5分)。これより高速にポーリングしないでください。
ステータスを呼び出します:
aws securityagent batch-get-code-review-jobs --agent-space-id <id> --code-review-job-ids <job_id>
現在の status を前回見たステータスと比較します。ステータスが変化した場合(例:IN_PROGRESS → COMPLETED)またはターミナル状態(COMPLETED、FAILED、STOPPED)に到達した場合のみ、ユーザーに応答します。
「処理中」を何度も報告しない — それはノイズです。
ユーザーが「ポーリング停止」または「後で確認」と言った場合 → ループを停止して通知:「いつでも『スキャンステータス』または『結果を表示』と言ってください。」
COMPLETED の場合 → 検出結果 ワークフローを実行します。
FAILED の場合 → ジョブのエラー情報を取得し(statusReason が存在する場合)、ユーザーに通知して、簡潔な失敗メモを .security-agent/findings-{scan_id}.md に記録します。
ユーザーが「スキャン ステータス」「スキャンの進み具合は」と言います:
scan_id を指定した場合はそれを使用。指定がない場合は scans.json の最新エントリを使用します。batch-get-code-review-jobs を1回呼び出します。scans.json のステータス フィールドを更新します。スキャン完了後(またはユーザーがリクエストした場合):
aws securityagent list-findings --agent-space-id <id> --code-review-job-id <job-id>
nextToken が返却された場合、--next-token <token> で再度呼び出し、尽きるまで繰り返します。
aws securityagent batch-get-findings --agent-space-id <id> --finding-ids <id1> <id2> ...
ユーザーが最小重要度を指定した場合(例:「重大と高」)、そのレベルでフィルタリングします:
重要度でグループ化。ファイル パスと行番号を表示:
🟣 CRITICAL: {name}
ファイル: {filePath}:{lineStart}
{description}
🔴 HIGH: {name}
ファイル: {filePath}:{lineStart}
{description}
🟡 MEDIUM: {name}
ファイル: {filePath}:{lineStart}
{description}
🟢 LOW: {name}
ファイル: {filePath}:{lineStart}
{description}
.security-agent/findings-{scan_id}.md に記録します。返却されたすべてのフィールドを含めます(findingId、name、description、riskLevel、riskType、confidence、status、codeLocations の filePath/lineStart/lineEnd、および remediationCode が存在する場合)。
# セキュリティ スキャン レポート — {scan_id}
**スキャン種類**: FULL
**タイトル**: {title}
**開始日時**: {started_at}
**検出結果合計**: {count}
## 概要
| 重要度 | 件数 |
|------|-----|
| CRITICAL | N |
| HIGH | N |
| MEDIUM | N |
| LOW | N |
## 検出結果
### 🟣 CRITICAL: {name}
- **ID**: {findingId}
- **リスク種類**: {riskType}
- **信頼度**: {confidence}
- **ステータス**: {status}
- **場所**: `{filePath}:{lineStart}-{lineEnd}`
**説明**: {description}
**修復方法**:
{remediationCode または説明から抽出した修復ガイダンス}
(すべての検出結果について繰り返す)
ユーザーに通知:「詳細は .security-agent/findings-{scan_id}.md に記録しました」
次を尋ねます:
修復の場合:検出結果の説明とコード場所を読み、その後、編集ツールで修復を合成・適用します。
ユーザーが「スキャンを停止」と言います:
aws securityagent stop-code-review-job --agent-space-id <id> --
This skill handles full repository scans. Setup (agent space, role, bucket) is handled by the setup-security-agent skill — if .security-agent/config.json is missing, the scan workflow auto-runs setup inline first.
| User intent | Workflow |
|---|---|
| Direct scan request ("scan my code", "find vulnerabilities") | Full Scan |
| Scan status check ("how's the scan", "progress") | Status workflow |
| View findings ("what did it find", "show results") | Findings workflow |
| List scans ("recent scans", "show my scans") | Read .security-agent/scans.json |
| Stop a scan | aws securityagent stop-code-review-job |
Read .security-agent/config.json for agent_space_id and region. If config.json is missing, tell the user one line — "First scan in this workspace — running setup first." — and run the setup-security-agent workflow inline (steps from that skill's SKILL.md) before continuing. First-time scans should "just work."
Track scans in .security-agent/scans.json (keep last 50 entries). The per-workspace CodeReview ID is stored in config.json → code_reviews[<abs_path>] so subsequent scans reuse the same CodeReview.
The CLI examples below use placeholders. Resolve them at the start of every scan:
| Placeholder | How to resolve |
|---|---|
<id> (agent space) |
config.agent_space_id |
<region> |
config.region (default us-east-1) |
<account> |
aws sts get-caller-identity --query Account --output text (cache for the rest of the turn) |
<role-arn> |
arn:aws:iam::<account>:role/SecurityAgentScanRole |
<bucket> |
security-agent-scans-<account>-<region> |
<cr-id> |
code_review_id from config.json → code_reviews[<abs_path>] |
<job_id> |
codeReviewJobId returned by start-code-review-job |
<WORKSPACE_ID> |
printf '%s' "$(pwd)" | md5sum | cut -c1-12 |
These are derived rather than stored in config so they can never drift out of sync with reality.
Read config.json. If missing → run the setup-security-agent workflow inline first, then continue.
Verify agent space still exists:
aws securityagent batch-get-agent-spaces --agent-space-ids <id>
If response shows it doesn't exist, clear agent_space_id from config.json and run setup-security-agent again.
Resolve account, role ARN, and bucket name from the table above.
Generate workspace ID:
WORKSPACE_ID=$(printf '%s' "$(pwd)" | md5sum | cut -c1-12)
For scanning only changed code, use the diff-scanning-with-aws-security-agent skill instead. For threat modeling specs, use threat-modeling-with-aws-security-agent.
Run pre-scan checks above.
Zip the workspace. Exclude common build/cache directories. Honor .gitignore. Bail if zip > 2 GB.
cd <absolute-workspace-path>
zip -r /tmp/source.zip . \
-x ".git/*" \
-x ".security-agent/*" \
-x "node_modules/*" \
-x "__pycache__/*" \
-x ".venv/*" -x "venv/*" \
-x "dist/*" -x "build/*" -x "target/*" \
-x ".mypy_cache/*" -x ".pytest_cache/*" -x ".tox/*" \
-x ".next/*" -x "cdk.out/*" \
-x ".DS_Store" -x "Thumbs.db" \
-x "*.pyc" -x "*.pyo"
ZIP_BYTES=$(stat -f%z /tmp/source.zip 2>/dev/null || stat -c%s /tmp/source.zip)
if [ "$ZIP_BYTES" -gt 2147483648 ]; then echo "Zip too large (>2GB)"; exit 1; fi
Upload to the per-workspace stable key (overwrites any prior upload):
aws s3 cp /tmp/source.zip s3://<bucket>/security-scans/source/<WORKSPACE_ID>/source.zip --expected-bucket-owner <account>
Get or create the per-workspace CodeReview. Look up config.json → code_reviews[<abs_path>].
If present, use that code_review_id.
If absent, create:
aws securityagent create-code-review --agent-space-id <id> --title <title> \
--service-role <role-arn> \
--assets sourceCode=[{s3Location=s3://<bucket>/security-scans/source/<WORKSPACE_ID>/source.zip}]
Capture codeReviewId and persist to config.json → code_reviews[<abs_path>].
Title default: pre-cr-<git-branch> (use git rev-parse --abbrev-ref HEAD). Replace any spaces with hyphens.
Start the job:
aws securityagent start-code-review-job --agent-space-id <id> --code-review-id <cr-id>
ResourceNotFoundException: the CodeReview was deleted externally. Recreate it (step 4) and retry.Capture codeReviewJobId. Generate a local scan_id like scan-<8-hex>. Append to scans.json:
{
"scan_id": "scan-...",
"code_review_id": "cr-...",
"job_id": "cj-...",
"agent_space_id": "as-...",
"scan_type": "FULL",
"title": "pre-cr-main",
"path": "/abs/path",
"started_at": "2026-06-01T20:00:00Z",
"status": "IN_PROGRESS"
}
Tell user: "Full scan started (scan_id: {id}). Takes ~45 minutes. I'll check every 5 minutes — say 'stop polling' to opt out."
Run the Polling Loop below with sleep 300 between checks.
After starting a scan:
sleep 300 (5 minutes). Do not poll faster than this.
Call status:
aws securityagent batch-get-code-review-jobs --agent-space-id <id> --code-review-job-ids <job_id>
Compare status to last seen status. Only respond to the user when status CHANGES (e.g., IN_PROGRESS → COMPLETED) or on terminal state (COMPLETED, FAILED, STOPPED).
Do not report "still in progress" multiple times — that's noise.
If user says "stop polling" or "check later" → stop the loop and tell them: "Say 'scan status' or 'show findings' anytime."
On COMPLETED → run the Findings workflow.
On FAILED → fetch the job's error info (statusReason if present), tell the user, write a brief failure note to .security-agent/findings-{scan_id}.md.
User says "scan status" / "how's the scan":
scan_id, use it. Otherwise use the most recent entry in scans.json.batch-get-code-review-jobs once.scans.json status field.After a scan completes (or on user request):
aws securityagent list-findings --agent-space-id <id> --code-review-job-id <job-id>
If nextToken is returned, call again with --next-token <token> until exhausted.
aws securityagent batch-get-findings --agent-space-id <id> --finding-ids <id1> <id2> ...
If the user asked for a minimum severity (e.g., "high and above"), filter to that level:
Group by severity. File path + line for each:
🟣 CRITICAL: {name}
File: {filePath}:{lineStart}
{description}
🔴 HIGH: {name}
File: {filePath}:{lineStart}
{description}
🟡 MEDIUM: {name}
File: {filePath}:{lineStart}
{description}
🟢 LOW: {name}
File: {filePath}:{lineStart}
{description}
Write to .security-agent/findings-{scan_id}.md. Include EVERY field returned (findingId, name, description, riskLevel, riskType, confidence, status, codeLocations with filePath/lineStart/lineEnd, and remediationCode if present).
# Security Scan Report — {scan_id}
**Scan type**: FULL
**Title**: {title}
**Started**: {started_at}
**Total findings**: {count}
## Summary
| Severity | Count |
|----------|-------|
| CRITICAL | N |
| HIGH | N |
| MEDIUM | N |
| LOW | N |
## Findings
### 🟣 CRITICAL: {name}
- **ID**: {findingId}
- **Risk type**: {riskType}
- **Confidence**: {confidence}
- **Status**: {status}
- **Location**: `{filePath}:{lineStart}-{lineEnd}`
**Description**: {description}
**Remediation**:
{remediationCode or remediation guidance from description}
(repeat for every finding)
Tell user: "Full details written to .security-agent/findings-{scan_id}.md"
Ask:
For fixes: read the finding's description and code location, then synthesize and apply the fix via the Edit tool.
User says "stop the scan":
aws securityagent stop-code-review-job --agent-space-id <id> --code-review-job-id <job_id>
Update scans.json status to STOPPED.
User asks "show my recent scans" / "list scans":
Read .security-agent/scans.json. Show in a compact table:
| scan_id | type | title | status | started |
|---|---|---|---|---|
| scan-abc | FULL | pre-cr-main | COMPLETED | 2h ago |
| scan-def | FULL | pre-cr-feature-x | FAILED | 1d ago |
scans.json if the user doesn't name oneResourceNotFoundException from start-code-review-job, recreate the CodeReview and retry onceconfig.json missing → run setup-security-agent skill firstAccessDenied on s3 cp → bucket not registered on agent space, or trust policy wrong. Re-run setup.403 / ExpectedBucketOwner mismatch on s3 cp → the derived bucket is owned by a different account (bucket-squatting). The upload is rejected by design — do not retry without the guard. Re-run setup-security-agent, which aborts on foreign-owned buckets.ResourceNotFoundException on agent space → it was deleted. Re-run setup.batch-get-code-review-jobs output and tell user to escalate.原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。