Cron Mode Workarounds for VisualAgent
Problem
When running as a scheduled cron job on Android, execute_code is blocked because it runs arbitrary Python that could bypass shell-string approval checks. This prevents the natural approach of writing a Python script to monitor command files, parse JSON, and execute operations in a loop.
Error Signature
BLOCKED: execute_code runs arbitrary local Python (including subprocess calls that bypass shell-string approval checks). Cron jobs run without a user present to approve it. Use normal tools instead, or set approvals.cron_mode: approve only if this cron profile is intentionally trusted.
Workarounds
Option 1: Shell-Only Workflow (Recommended)
Use terminal tool with shell commands for all operations. Android's shell environment has sufficient utilities:
# Check for command files
su -c "ls -1 /sdcard/VisualAgent/commands/*.json 2>/dev/null || echo 'NO_FILES'"
# Read a command file (use cat + su)
su -c "cat /sdcard/VisualAgent/commands/cmd_001.json"
# Parse JSON with python3 one-liner (if available)
python3 -c "import json,sys; d=json.load(sys.stdin); print(d['type'])" < /tmp/cmd.json
# Or use jq if installed
jq -r '.type' /sdcard/VisualAgent/commands/cmd_001.json
Option 2: Direct MCP Tool Calls
For each discovered command file, make individual tool calls rather than batching in a script:
terminalto list files in commands directoryterminalto read each command file- Parse the JSON from the terminal output (it's in the response)
- Based on the
commandfield, call the appropriate MCP tool:mcp_android_phone_screenshotmcp_android_phone_tapmcp_android_phone_swipemcp_android_phone_input_textmcp_android_phone_open_app
terminalto write the result JSON file
Option 3: Hybrid Approach (Shell + MCP)
For simple monitoring, use shell commands. For actual UI operations, use MCP tools:
# In terminal: find all .json files
su -c "find /sdcard/VisualAgent/commands/ -name '*.json' -type f"
Then for each file, call the appropriate MCP tool based on the command type.
Writing JSON Results from Shell
Since execute_code is unavailable, construct JSON via shell:
# Simple approach: use printf with careful escaping
RESULT='{"status":"success","output":"screenshot saved"}'
su -c "echo '$RESULT' > /sdcard/VisualAgent/results/cmd_001_result.json"
# For complex JSON, use python3 one-liner
python3 -c "
import json
result = {'status': 'success', 'output': 'done'}
print(json.dumps(result))
" > /tmp/result.json
su -c "cp /tmp/result.json /sdcard/VisualAgent/results/"
Key Constraints in Cron Mode
| Tool | Available? | Notes |
|---|---|---|
terminal |
Yes | Primary tool for shell operations |
mcp_android_phone_* |
Yes | All Android phone tools work |
execute_code |
No | Blocked for safety |
read_file / write_file |
Yes | For local files, but may need su for /sdcard/ |
Practical Pattern: Single-File Processing
For a cron job that processes one command per run:
- List command files with
terminal - If no files → respond
[SILENT] - If files found → read the first one with
terminal - Parse JSON from terminal output
- Execute with appropriate MCP tool
- Write result with
terminal - Log processed file with
terminal(append to processed.log)
This avoids needing loops or complex logic within a single tool call.