The Claude Agent SDK embeds the agent loop and tools that power Claude Code in a Python or TypeScript application. Its query() interface streams lifecycle, assistant, tool-result, and final messages. Start in a disposable directory with read-only tools, a turn limit, and an API key—then inspect every message type before allowing edits.
You will install the Python SDK, run a repository summary agent, handle final results, and explain how the SDK differs from a direct Claude API client.
The Python package is claude-agent-sdk; the TypeScript package is @anthropic-ai/claude-agent-sdk. Both bundle a native Claude Code binary for supported platforms, so a separate Claude Code install is not normally required.
The SDK reads the key from the process environment and does not automatically load .env files. Production credentials should come from a secrets manager or short-lived credential path.
Create README.md with a short fictional project description, then create first_agent.py:
allowed_tools auto-approves listed tools; disallowed_tools blocks the dangerous tools even if other settings would permit them. The process working directory defines the default file scope, so run the lab only inside the disposable folder.
Trace this run: query() starts a session, emits initialization, loops through assistant/tool messages, and ends with ResultMessage. Iterate the stream to completion; some lifecycle events can follow the result.
Run with the key unset and confirm a clear configuration failure. Run from the wrong directory and stop immediately rather than granting broad file access to “make the demo work.”
Wrap query() in a domain boundary that emits normalized run.started, tool.observed, and run.completed events without logging file contents.