Create a Target and Scan It
The first thing you do with the SDK is turn the agent you want to test into a target, then scan it. A target owns a recon profile — a structured description of your application that Red uses to tailor its attacks — so creating a target is really about deciding how that profile gets set.
This page focuses on that one decision. For the surrounding scaffolding (installing the SDK, initializing the client, handling sessions, retrieving results), see the Quickstart.
Choose how the profile is set
createOrGetTarget finds or creates a target by name and ensures it has a recon
profile. There are three ways to provide that profile:
- Pass
appContext— supply the profile directly as a structured object. No recon runs. - Pass
appContextFile— load the same profile from a YAML file. No recon runs. - Pass a handler and omit the context — the SDK runs a short reconnaissance phase, relaying prompts through your agent, and saves the discovered profile on the target.
A profile you pass with appContext or appContextFile always wins — it overwrites
whatever the target already held. Only when you omit the context does an existing
profile (from a previous run or the dashboard) get reused.
Reusing an existing target by its id, rather than by name, is covered in Reuse a Target Across Scans.
Provide the profile directly
Use this when you already know how to describe your application. It is the most predictable option — no recon phase, so target creation returns immediately.
TypeScript
Python
Or load the same profile from a YAML file:
Let recon discover the profile
Use this when you’d rather have Red build the profile for you. Omit the context and pass
a handler — the same handler signature you use for scan.run. Recon relays a few
prompts through your agent and saves the result on the target.
TypeScript
Python
Scan the target
However the profile was set, pass the returned target’s targetId to createScan. The
recon profile is read from the target, so the scan needs no further context.
TypeScript
Python
See Creating a Target in the SDK Reference for the full parameter list.