C.W.K.
Stream
Lesson 06 of 08 · published

Security and Privacy at the SDK Boundary

~14 min · security, privacy, secrets, logging

Level 0Observer
0 XP0/64 lessons0/13 achievements
0/150 XP to next level150 XP to go0% complete

What leaves your process

Every SDK call sends prompts, system instructions, attached files, and tool definitions to Anthropic's servers (or Bedrock/Vertex). The reverse-direction surface is what the model can do — read files, run shell, hit URLs. Both directions are part of your security model.

Secrets discipline

API keys belong in environment variables and secret managers, never in code, never in prompts, never in tool descriptions. JSONL logs are particularly dangerous — value-pattern keys (sk-ant-...) leak into git history if you log the system prompt or request body unredacted.

Data residency and retention

Anthropic's default API does not train on your inputs. Bedrock and Vertex respect their cloud's data residency commitments. Zero Data Retention (ZDR) is a feature available on certain plans and changes the privacy story for regulated workloads. Know what your account has signed up for before classifying data as 'safe to send'.

Principle: Treat the SDK boundary as a public boundary. What you send and what you log are both audit trails.

Code

Redact API keys from any structured log·python
import re

KEY_PATTERN = re.compile(r"\bsk-ant-[A-Za-z0-9_-]{20,}\b")

def redact(text: str) -> str:
    return KEY_PATTERN.sub("sk-ant-***REDACTED***", text)

# Always run logged payloads through redact() — even in private repos.
log_line = '{"prompt": "hi", "key": "sk-ant-api03-abcdef0123456789"}'
print(redact(log_line))
Pre-commit hook to refuse staged files containing key patterns·bash
#!/usr/bin/env bash
# .git/hooks/pre-commit
set -euo pipefail
if git diff --cached -U0 | grep -E 'sk-ant-[A-Za-z0-9_-]{20,}' >/dev/null; then
  echo 'refusing to commit: detected an Anthropic key pattern in staged content'
  exit 1
fi

External links

Exercise

Audit one place in your code that logs an SDK request or response. Add a redaction filter for API key patterns and any user PII. Confirm with a unit test that a faked key never survives the filter.
Hint
sk-ant- is the prefix to match; the suffix is variable length but always alphanumeric plus dashes.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.