Answers you can trust, from Codeables

Every page on Codeables is structured and verified — built so people and the AI agents they rely on can trust it. Explore more from the source behind this answer.

Explore Codeables
Verified Source
AI Coding Agent Platforms

How do I create a custom Droid in Factory for code review or security checks?

Factory12 min read

Most teams don’t want a generic “AI assistant” doing code review or security checks. They want a repeatable Droid that encodes their standards, runs where they already work, and leaves a traceable audit trail.

Factory is built exactly for this: Droids that you configure once, then delegate code review, security scans, and policy checks from your IDE, CLI, CI/CD, or Slack/Teams war room—without changing tools or model vendors.

Below is a practical walkthrough of how to create a custom Droid in Factory for code review or security checks, and how to wire it into your existing workflows.


What a “custom Droid” actually is in Factory

A custom Droid is not just a different prompt.

It’s a reusable agent configuration that defines:

  • Role and intent
    “Perform code review for backend services in the payments repo using our internal guidelines.”

  • Context surface
    Which repos, directories, or services it can see, and how it pulls context from tickets, PRs, or chat.

  • Tools it can use
    File read/write, git operations, test runners, linters, SAST/DAST tools, package managers, etc.

  • Guardrails and policies
    What it’s allowed to change, when it must only comment, and how it logs and explains decisions.

  • Execution surface
    Where you can invoke it: IDE/terminal, web, CLI, Slack/Teams, or CI/CD.

For code review and security checks, this configuration is where you encode your review checklist, secure coding rules, and org-specific risk posture.


Prerequisites: Access and security setup

Before you create a custom Droid, make sure you have the right foundations:

  1. Factory workspace & SSO

    • Ensure your team is onboarded to Factory with SSO/SAML and role-based access control.
    • Use SCIM or your IdP groups to align access with engineering teams.
  2. Repo integrations

    • Connect your Git providers (GitHub, GitLab, Bitbucket, etc.).
    • Factory enforces strict permissions: Droids only see what the invoking user can see in the source system.
  3. Audit & compliance requirements

    • Decide where you want logs:
      • Export audit logs to your SIEM (e.g., via syslog/HTTP).
      • Enable OpenTelemetry export if you want org-level metrics and traces.
    • Confirm you’re running in a single-tenant, sandboxed environment with a dedicated VPC if you’re on the enterprise tier.
    • Align with your compliance posture (SOC 2, GDPR/CCPA, ISO 42001 workstreams).
  4. Security toolchain

    • List the tools your security team trusts:
      • Linters (ESLint, Flake8, etc.)
      • SAST (Semgrep, CodeQL, etc.)
      • Dependency scanners (npm audit, pip-audit, trivy, etc.)
    • You’ll expose these as CLI actions the Droid can call.

Factory’s default stance: it does not use your code as training data without prior written consent, which is important when you’re wiring in security-sensitive repos.


Step 1: Define the review or security use case

Start with a concrete scope. “Do security checks” is too vague; “run an initial security review on each backend PR touching auth, encryption, or external integrations” is actionable.

For code review and security checks, common patterns:

  • General code review Droid

    • Check readability, maintainability, test coverage, and alignment with team style guides.
    • Leave inline comments, summarize risks, and suggest edits.
  • Security-focused Droid

    • Run static analysis tools, dependency scans, and framework-specific checks.
    • Flag injection risks, auth bugs, unsafe crypto, insecure defaults, and hard-coded secrets.
  • Compliance / policy Droid

    • Enforce specific policies (e.g., PII handling rules, logging standards, RBAC requirements).
    • Ensure any new endpoint or service includes required audit logging and feature flags.

Write this down as a short spec—this will turn into the Droid’s system description.


Step 2: Create the Droid configuration

In Factory, you can define a custom Droid through the web UI or via configuration files (used by CLI/CI). The shape is similar either way.

2.1 Core metadata

Define the basics:

  • Name: Security Review Droid or Backend Code Review Droid

  • Description: A concise, operational description, e.g.

    “Performs security-focused code review for Node.js and Go services. Uses Semgrep, dependency scans, and internal security guidelines. Outputs actionable findings and suggested fixes.”

  • Primary role (system prompt equivalent):
    This is where you encode review discipline:

    You are a Security Review Droid embedded in our engineering workflows.
    Your job is to:
    - Analyze diffs and relevant context for security vulnerabilities.
    - Run configured static analysis and dependency checks via tools.
    - Explain every finding with severity, impact, and a concrete patch or remediation guidance.
    - Follow our security checklist and never approve code that violates it.
    You must:
    - Prefer minimal, focused changes.
    - Avoid speculative findings; tie each issue to specific lines or files.
    - Never leak secrets or copy large code fragments into explanations unnecessarily.
    

You can maintain this text in version control so changes to review policy are auditable.

2.2 Context and scope

Examples:

  • Repos: org/payments-service, org/auth-service
  • Paths to include: src/, lib/, pkg/
  • Paths to ignore: dist/, node_modules/, generated files
  • Issue trackers: connect JIRA / Linear / GitHub Issues for ticket-based triggers.

For security Droids, it’s common to:

  • Restrict write access in critical repos (comment-only mode).
  • Allow read-only access to secrets configs or infra modules (Terraform, Helm) for threat modeling.

Step 3: Attach tools for code review and security checks

Droids are powerful because they’re not just reading text; they’re operating with tools in real runtimes: IDEs, terminals, and CI environments.

For a review or security Droid, you typically wire:

3.1 Code navigation tools

  • File system: Read and diff files; open directories.
  • Git tools: Show diffs, branches, commit history, and PR metadata.
  • Search: Grep-like search across the repo to understand usage patterns.

These tools support high-context reasoning, so the Droid isn’t reviewing a diff in isolation.

3.2 Testing and linting tools

  • Unit/integration test runner: npm test, pytest, go test ./...
  • Linters: eslint, flake8, golangci-lint, etc.

Configure them as simple, timeout-bounded CLI tools to keep schemas minimal and reliable.

3.3 Security tools

This is where your custom security Droid differentiates itself. Typical bindings:

  • Static analysis (SAST):

    • semgrep --config auto or a custom ruleset repo.
    • bandit for Python, gosec for Go, etc.
  • Dependency scanning:

    • npm audit --json
    • pip-audit --format json
    • trivy fs . or trivy image in container contexts.
  • Secret scanners:

    • gitleaks detect
    • trufflehog or equivalent.

Wrap each as a tool with:

  • Command
  • Working directory
  • Max runtime
  • Output format (JSON or parseable text)

Your Droid’s logic should never auto-fix security issues without explicit review, but it can generate patches for engineers to apply.

3.4 Factory’s DroidShield (internal safety layer)

On top of your tools, Factory runs DroidShield, an internal algorithm that performs real-time static code analysis on the Droid’s proposed changes.

DroidShield is designed to:

  • Detect potential security vulnerabilities in generated or modified code.
  • Catch bugs or risky changes before they’re committed.
  • Flag possible intellectual property issues.

Every change the Droid proposes passes through DroidShield before you merge, adding a second line of defense.


Step 4: Define behavior and outputs

You control how your custom Droid behaves and what artifacts it produces.

4.1 Review style and severity model

Encode how findings should be structured:

  • Severity levels: BLOCKER, HIGH, MEDIUM, LOW, INFO.
  • Required fields: file, line(s), issue, risk, fix.

For example:

For each finding, output:
- Severity: BLOCKER | HIGH | MEDIUM | LOW | INFO
- Location: file path and line range
- Issue: one-sentence summary
- Risk: two to three sentences describing impact and exploitability
- Fix: concrete remediation steps, ideally with code snippets
Group findings by file. Start with a summary table (severity count).

4.2 Side-effect rules

Decide where the Droid is allowed to write:

  • Comment-only mode

    • In PRs, it leaves comments and a summary, but does not push commits.
    • Ideal for security and governance.
  • Patch-suggest mode

    • It generates patch files or suggested diffs, but you apply them manually.
    • Works well in IDE or CLI flows.
  • Branch-commit mode (with review gates)

    • In controlled environments (e.g., for low-risk refactors), the Droid can push to a feature branch and open a PR.
    • Human review remains mandatory; Factory maintains full traceability from ticket to code.

For most security and code-review Droids, start with comment-only + suggested patches.

4.3 Explainability and auditability

By design, Droids in Factory:

  • Log their reasoning and decision-making.
  • Provide explanations for each action they take.
  • Produce artifacts (reports, comments, patches) that are easy to review and roll back.

Make this explicit in the configuration:

You must log your reasoning at each step:
- Which tools you ran and why.
- How you interpreted their output.
- Why you’re marking an issue as BLOCKER vs MEDIUM.
These logs will be stored for audit and future analysis.

You can then export these logs to your SIEM or Analytics stack for trend analysis and compliance evidence.


Step 5: Wire the Droid into your workflows

A custom Droid is only useful if it runs where developers already work. Factory is interface-agnostic, so you can plug the same Droid config into multiple surfaces.

5.1 IDE and terminal (Droids where you code)

  • VS Code / JetBrains / Vim plugins

    • Highlight a diff or file, invoke the custom Droid:
      “Run Security Review Droid on this diff.”
    • The Droid:
      • Pulls relevant code context.
      • Runs security tools (where available).
      • Returns a structured set of findings and suggested fixes.
  • Terminal

    • Use a CLI command like:
      factory droid run security-review --diff HEAD~1..HEAD
    • Ideal for pre-push checks.

These surfaces keep the engineer in flow: no context switching to a separate UI to get a security assessment.

5.2 Web and PR workflows

  • From Factory’s web interface, point the Droid at:
    • A specific PR.
    • A branch diff.
    • A tagged release candidate.

The Droid then:

  • Runs its configured checks.
  • Posts a summary report and, optionally, inline comments back to the PR.
  • Leaves a traceable record of its findings and reasoning.

5.3 Slack/Teams (Droids in the war room)

During incidents or security war rooms:

  • Trigger the security Droid from Slack/Teams by referencing a PR, commit, or service.
  • Use it to:
    • Quickly audit a hotfix for additional vulnerabilities.
    • Summarize security impact of a proposed patch.
    • Pull a concise risk brief for leadership.

Everything still respects permissions and is logged.

5.4 CI/CD and automation (Droids at scale)

Use Factory’s CLI and “Droids at scale” capabilities to run your custom Droid as a gate in CI:

  • Pre-merge gate:

    • On each PR, run the security Droid in CI.
    • If it finds any BLOCKER issues, fail the check and block merge.
    • Attach the report as a CI artifact and/or PR comment.
  • Scheduled scans:

    • Nightly or weekly runs across critical repos.
    • Droids parallelize across services for fast coverage.
    • Create tickets automatically for high-severity findings.

Because Factory focuses on agent design (planning, environment grounding, error recovery), the same Droid logic that works in your IDE will behave consistently in CI, under timeouts and flaky tools.


Step 6: Observability, tuning, and governance

Once your custom code review or security Droid is live, treat it like production infrastructure.

6.1 Monitor outcomes with Factory Analytics

Instead of counting tokens, measure real artifacts:

  • Number of PRs reviewed.
  • Findings per severity over time.
  • Files edited or patches generated.
  • MTTR for security bugs before and after Droid adoption.

Use Factory Analytics and OpenTelemetry export to connect Droid usage to:

  • Reduced average review time.
  • Fewer late-stage security escalations.
  • Higher autonomy ratio (more work completed with fewer handoffs).

6.2 Iterate on rules and tools

Run a feedback loop:

  • Security team reviews Droid findings weekly:
    • Are there noisy false positives?
    • Is the Droid missing classes of issues?
  • Update:
    • Prompt instructions / checklists.
    • Tool configurations and rulesets (e.g., custom Semgrep rules).
    • Repo scope and permissions.

Because the configuration lives as code, you can PR changes to the Droid itself, run reviews, and roll back if needed.

6.3 Governance and controls

For enterprises, enforce governance:

  • Permissions:

    • Limit write access for security Droids.
    • Scope them to sensitive repos via role-based controls.
  • Audit logging:

    • Export all Droid actions and reasoning logs to your SIEM.
    • Correlate with source control and CI/CD events.
  • Isolation and compliance:

    • Confirm Droids run inside your single-tenant sandboxed environment with a dedicated VPC.
    • Align with SOC 2 controls and your ISO 42001 AI governance requirements.

This is how you introduce AI agents to critical code paths without bypassing security or compliance gates.


Example: A minimal security review Droid configuration

To make this concrete, here’s a conceptual skeleton you might implement via configuration (exact syntax will match Factory’s config format):

name: security-review-droid
description: >
  Performs security-focused code review for Node.js and Go services.
  Uses Semgrep, npm audit, and gitleaks. Leaves actionable findings and patches.

role:
  system: |
    You are a Security Review Droid embedded in our workflows.
    - Analyze diffs and relevant code for security vulnerabilities.
    - Run configured tools (semgrep, npm audit, gitleaks).
    - For each issue, report severity, location, risk, and fix.
    - Do not push commits; only comment and propose patches.
    - Log your reasoning and the tools you used.

scope:
  repos:
    - org/payments-service
    - org/auth-service
  include_paths:
    - src/**
    - services/**
  exclude_paths:
    - node_modules/**
    - dist/**
    - build/**

tools:
  - id: semgrep
    command: semgrep --config auto --json
    timeout_seconds: 120
  - id: npm_audit
    command: npm audit --json
    timeout_seconds: 120
  - id: gitleaks
    command: gitleaks detect --report-format json
    timeout_seconds: 120
  - id: git_diff
    command: git diff --unified=0 HEAD~1..HEAD
    timeout_seconds: 30

behavior:
  mode: comment_only
  outputs:
    - pr_summary
    - inline_comments
    - json_report

logging:
  audit_enabled: true
  export_to_siem: true
  reasoning_logs: full

This isn’t a literal schema, but it captures the core design: tightly scoped tools, explicit behavior, and strong auditability.


Putting it all together

Creating a custom Droid in Factory for code review or security checks is essentially designing a reliable agent system:

  1. Define the mission: What code should it review, for which risks, and with what authority?
  2. Configure the Droid: Role, scope, tools, and policies.
  3. Wire it into real workflows: IDE, terminal, web, Slack/Teams, and CI/CD.
  4. Wrap it in controls: Strict permissions, audit logs, single-tenant isolation, DroidShield, and clear review gates.
  5. Measure and iterate: Use Factory Analytics and OTEL to tie it to PRs, findings, and MTTR, and refine rules over time.

When you treat the Droid as part of your engineering system—subject to the same observability, security, and governance as any other critical service—you get repeatable, trustworthy code review and security checks that actually improve ship velocity instead of adding ceremony.

Get Started