Task Lifecycle
1. Task Creation
Operators enqueue tasks using thetask command:
- Validates the session exists and is active
- Creates a unique task UUID
- Adds the task to the session’s queue
- Persists the task to the database
- Returns the task ID to the operator
2. Task Dispatch
When the agent beacons:- Server checks for pending tasks for that session
- Retrieves the next
PENDINGtask from the queue - Sends the task to the agent
- Marks the task as
DISPATCHED
3. Task Execution
The agent:- Receives the task payload
- Executes the command using
agent/executor.py - Captures stdout, stderr, exit code, and duration
- Returns the result on the next beacon
4. Result Storage
The server:- Receives the result from the agent
- Marks the task as
COMPLETE - Stores the result in the database
- Makes it available via the
resultscommand
Executing Tasks
Basic Task Syntax
Command Arguments
Arguments are space-separated and passed as a list to the agent:Task Timeout
All tasks have a default timeout of 30 seconds:TIMEOUT in stderr.
Task Status States
Tasks progress through four states:PENDING
Task is queued but not yet sent to the agent:DISPATCHED
Task has been sent to the agent and is awaiting execution.COMPLETE
Task executed successfully (regardless of exit code). Result is available.ERROR
Task encountered an error during execution or transmission.Command Blocklist
Certain commands are blocked for safety and compliance:BLOCKED: prohibited command in stderr:
Blocklist Implementation
The blocklist check is case-insensitive and matches command names with or without arguments:agent/executor.py:23
Command Execution
Commands are executed using Python’ssubprocess module with shell=False for security:
- Prevents shell injection attacks
- Ensures safe argument handling
- Provides timeout protection
- Captures stdout and stderr separately
agent/executor.py:80
Exit Codes
The framework uses standard exit codes:| Exit Code | Meaning | Example |
|---|---|---|
| 0 | Success | whoami completed successfully |
| 1-125 | Command-specific errors | ping to unreachable host |
| 126 | Blocked command | nmap or other prohibited commands |
| 127 | Command not found | nonexistent_command |
| 124 | Timeout | Command exceeded 30 second limit |
Exit Code Examples
Task Queue Architecture
TheCommandQueue class manages task distribution:
Per-Session Queues
Each session has its own asyncio queue:Task Registry
All tasks are indexed by task_id for O(1) lookups:Task Enqueueing
server/command_queue.py:49
Task Peeking
The server peeks at the next pending task without removing it:server/command_queue.py:82
Task Data Model
Tasks are represented by theTask dataclass:
server/command_queue.py:24
Output Size Limits
Command output is capped at 64 KB to prevent memory issues:agent/executor.py:9
Task Persistence
All tasks are persisted to the database when enqueued:Database Recovery
If the server restarts, pending tasks are automatically reloaded:server/command_queue.py:94
Task Execution Best Practices
1. Start with Safe Commands
Test connectivity with simple commands:2. Check Results Promptly
Always verify task results:3. Handle Long-Running Commands
Commands that exceed 30 seconds will timeout. For long operations:- Break into smaller tasks
- Use background execution on the target system
- Consider modifying the timeout in the code
4. Respect the Blocklist
The blocklist exists for safety and compliance. Do not attempt to bypass it.5. Monitor Task Status
Check task completion by reviewing results regularly:Error Handling
Invalid Session
list.
Inactive Session
Blocked Command
common/config.py.
Command Not Found
Logging
All task operations are logged:logs/ for detailed task execution history.