<!-- Copyright (c) 2026 defconxt. All rights reserved. -->
<!-- Licensed under AGPL-3.0 — see LICENSE file for details. -->
<!-- NERF is a trademark of defconxt. -->
# Code Protocol Templates — API Reference

## Code Protocol Execution

```bash
# Run code template (requires -code flag)
nuclei -u https://target.com -t code-template.yaml -code -json

# With timeout
nuclei -u https://target.com -t code-template.yaml -code -timeout 60
```

## Engine Specification

```yaml
code:
  - engine:
      - py         # Python (tries py, python, python3)
      - python3
    source: |
      # Python code here

  - engine:
      - go         # Go (compiles and runs)
    source: |
      package main
      // Go code here

  - engine:
      - js         # JavaScript (tries js, node)
      - node
    source: |
      // JavaScript code here
```

## Template Variables in Code

| Variable | Description | Example in Code |
|----------|-------------|-----------------|
| `{{BaseURL}}` | Full target URL | `target = "{{BaseURL}}"` |
| `{{Hostname}}` | Target hostname | `host = "{{Hostname}}"` |
| `{{Host}}` | Hostname with port | `addr = "{{Host}}"` |
| `{{Port}}` | Target port | `port = int("{{Port}}")` |
| `{{Scheme}}` | http or https | `scheme = "{{Scheme}}"` |

## Code Output Matching

```yaml
# Match stdout of code execution
matchers:
  - type: word
    words:
      - "VULNERABLE"
      - '"vulnerable": true'
    condition: or

# Regex match on output
matchers:
  - type: regex
    regex:
      - 'FOUND:\s+(.+)'
```

## Security Considerations

| Concern | Mitigation |
|---------|------------|
| Arbitrary code execution | Requires explicit `-code` flag |
| Network access | Code can make outbound connections |
| File system access | Code runs with nuclei process permissions |
| Resource exhaustion | Use `-timeout` to limit execution time |
| Dependency management | Document required packages in template |

## CLI Flags for Code Protocol

| Flag | Description |
|------|-------------|
| `-code` | Enable code protocol execution |
| `-timeout` | Execution timeout in seconds |
| `-system-resolvers` | Use system DNS resolvers |
| `-sandbox` | Run in restricted sandbox mode |
