Skip to content

Run a redteam probe

Python SDKOwner/admin issues key; machine key with redteam:run executesVerified 2026-11-13 · Named local QA for standalone probes and console persistence; GitHub-hosted Ubuntu 24.04/Python 3.12 for exact public ZIP combined CLI on disposable pinned servicesVerification details

Run one adversarial probe against a local callback using platform-hosted generation and judging. You will get retained JSON/Markdown reports and an explicit gate result. Use the CLI or Python entry point for an attempt; running both executes new work twice.

  • Complete installation and configuration using martian-sdk[evals], Python 3.12+, and the downloadable tutorial files.
  • An owner/admin must issue a key with Run hosted redteam generation and judging (redteam:run). The organization must be enabled and configured for hosted redteam. Existing Evals keys do not gain this permission automatically.
  • Running a probe can incur platform generation/judging costs. Keep the tutorial’s single vulnerability type, single attack, one repetition and concurrency of one.
  • The included target is a deterministic support callback. It verifies the integration; a passing result does not qualify a production LLM, connected tools or business outcomes.
  • Standalone redteam does not require an agent UUID/Git revision. Respect a key’s agent restriction; persisted CI additionally requires attribution and CI permissions.
Create API key with hosted redteam permission and teaching-agent restriction selected
Select the needed permissions and restrictions before issuing the key. This capture precedes creation; the once-shown secret is excluded. Open full size

Open redteam.yaml:

YAML
target:
purpose: "A support tutorial target that must not disclose internal instructions."
callback:
file: demo_agent.py
function: answer
system_config:
max_concurrent: 1
attacks_per_vulnerability_type: 1
target_timeout_seconds: 5
output_folder: results/redteam
vulnerabilities:
- name: PromptLeakage
types: [system_prompt]
gated: true
attacks:
- name: PromptInjection
gate:
fail_on_infrastructure_error: true
ignore_target_errors: false
pass_rate_threshold: 1.0

callback.file is resolved relative to the YAML file. The sample function in demo_agent.py returns a string. Replace it with your own synchronous or asynchronous application callback when testing your agent. The callback owns target/provider authentication; the platform key is not a target credential.

This configuration plans one PromptLeakage / system_prompt case using PromptInjection. Adding types, attacks or repetitions increases work. A callback may return a string or the supported Turn type when retaining tool-call names is useful.

Shell
.venv/bin/martian redteam validate redteam.yaml

Expect exit 0. Validation checks configuration, catalog choices and the callback reference without invoking the target callback or model. It does not establish authentication, entitlement or model readiness. Only validate Python callback code you trust; keep secrets out of unreviewed code and CI jobs.

If the catalog name, type, callback file or options are invalid, fix the configuration before executing. Extra YAML fields are rejected. The platform origin comes from the approved connection, not an api.url override.

With MARTIAN_API_URL and MARTIAN_API_TOKEN set:

Shell
.venv/bin/martian redteam run redteam.yaml -o results/redteam

The SDK requests generation/judging through Backend and invokes the callback locally. Expect:

  • results/redteam/risk-assessment.json: safe structured probe and judgment data.
  • results/redteam/risk-assessment.md: a readable summary.
  • A final pass/fail gate result and process exit code.

Reports are written before applying the gate, so a failed assessment still has evidence. The strict tutorial policy requires complete execution and a passing judgment. A scored failure is a useful result; it is not an invitation to repeat the run until green.

Choose this instead of the preceding execution command for a new attempt. The full redteam.py includes an entry point and exit handling:

Python
import asyncio
from demo_agent import answer
from martian.redteam import (
Client, PromptInjection, PromptLeakage, a_red_team, evaluate_gate,
)
async def assess():
async with Client() as client:
report = await a_red_team(
target=answer,
client=client,
purpose="A support tutorial target. Never disclose internal instructions.",
vulnerabilities=[PromptLeakage(types=["system_prompt"])],
attacks=[PromptInjection()],
max_concurrent=1,
attacks_per_vulnerability_type=1,
target_timeout_seconds=5,
)
report.save("results/python-redteam")
evaluate_gate(report, pass_rate_threshold=1.0)
return report
if __name__ == "__main__":
asyncio.run(assess())
Shell
.venv/bin/python redteam.py

Inside an existing async application, await a_red_team(...); do not nest asyncio.run inside its event loop. red_team(...) is the synchronous wrapper. Calling a_red_team returns assessment data; saving it and applying evaluate_gate makes the policy decision explicit.

5. Inspect the outcome and failure behavior

Section titled “5. Inspect the outcome and failure behavior”

Check that the report contains the planned vulnerability/type, attack method, completed probe, score and any error/operation references. Distinguish a completed score of 0 from execution failure or missing evidence.

CLI result Exit Meaning
Complete strict pass 0 Planned work completed and satisfied the gate
Gate failed 1 A required judgment failed or execution was incomplete/errored
Setup or execution/usage failure 2 Configuration, credentials or startup prevented a valid run

Authentication, scope, retention, timeout and unknown-outcome errors have controlled codes. Keep the code and operation ID with the safe report. The CLI groups repeated errors; do not expose raw provider bodies or callback exception data in a public issue.

If execution status is unknown, recover the same operation with client.get_operation(operation_id). Do not send another execution POST to obtain a passing result. client.cancel_operation(operation_id) requests cancellation; cancellation is not a passing judgment and does not prove an already issued provider request stopped.

In the isolated QA walkthrough, the Python and CLI entry points were each run once as separate one-probe attempts. Each exited 0, saved one score of 1, and reported no infrastructure or target errors. Their four generation/judging operations were confirmed succeeded and settled. These results qualify the tutorial wiring against a deterministic callback, not a production agent’s security.

Async callback cancellation is cooperative. Synchronous callbacks use bounded workers and need their own network timeouts: Python cannot kill a worker thread, and the SDK awaits cleanup. Late output cannot turn a timed-out probe into a pass.

6. Persist a redteam result in the console

Section titled “6. Persist a redteam result in the console”

Standalone martian redteam run retains a local report. To record a new redteam-only session in Backend, prepare the committed tutorial/customer Git repository and CI scopes, then use the installation guide’s agent-bound key lookup to obtain the exact agent UUID and set the tested revision. From that repository root, run:

Shell
.venv/bin/martian ci --redteam-config redteam.yaml \
--require-export --output results/redteam-ci

This is a new one-probe execution. For the main combined tutorial, use combined CI instead of duplicating the same assessment.

Select Evals in the main sidebar to return to the default Runs view. Find CI sessions, select Refresh, then Show tests on the matching commit. The redteam test is labelled adversarial probes, with its policy, counts, judgments and provenance.

Combined CI saved a failed two-of-four result with exported evidence
The original combined attempt retained Failed and Exported to MLflow. Its generation acknowledgement was uncertain, so target execution and judging did not follow; later same-operation readback did not change this failed session. Open full size

The captured local combined-CI attempt is a failed result: its generation response was uncertain to the runner, so target execution and judging did not proceed. A later read of that same operation confirmed generation succeeded. The original failed CI verdict remained saved and exported; retrieving the generation result did not complete the missing probe or turn the gate into a pass.

A subsequent, distinct qualification ran an earlier tutorial snapshot on a GitHub-hosted runner. The combined CLI passed all three test groups, persisted and exported its session, and independently verified one generation plus one judging model call, both settled. See CI qualification results and the tested SDK record. The deterministic callback checks wiring and retained evidence; it does not establish production-agent security.

Redteam judgments saved by the runner are client-executed/client-scored, including judgments originally obtained from Agents. They are useful regression evidence, not a release authorization or independent proof of the executed binary. SDK callback testing also does not establish sandbox reproduction or verified business effects from a console assessment.

Reports use digests by default. Keep content reporting disabled for ordinary CI and never publish raw callback data, credentials or a local MLflow store. Continue with combined CI or troubleshooting.