# 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: ```bash # 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: 1. `terminal` to list files in commands directory 2. `terminal` to read each command file 3. Parse the JSON from the terminal output (it's in the response) 4. Based on the `command` field, call the appropriate MCP tool: - `mcp_android_phone_screenshot` - `mcp_android_phone_tap` - `mcp_android_phone_swipe` - `mcp_android_phone_input_text` - `mcp_android_phone_open_app` 5. `terminal` to write the result JSON file ### Option 3: Hybrid Approach (Shell + MCP) For simple monitoring, use shell commands. For actual UI operations, use MCP tools: ```bash # 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: ```bash # 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: 1. List command files with `terminal` 2. If no files → respond `[SILENT]` 3. If files found → read the first one with `terminal` 4. Parse JSON from terminal output 5. Execute with appropriate MCP tool 6. Write result with `terminal` 7. Log processed file with `terminal` (append to processed.log) This avoids needing loops or complex logic within a single tool call.