Overview
Async webhook execution is perfect for:- ML model training (30+ minutes)
- Large dataset processing
- Video encoding/processing
- Long-running simulations
- Any task that exceeds normal timeout limits
Async webhook execution returns immediately with an
execution_id. The agent executes code in the background and POSTs results to your callback URL when complete.Basic Usage
Start async execution with a webhook callback:- Python
- JavaScript
Webhook Callback
Your webhook endpoint will receive a POST request when execution completes:- Python (Flask)
- JavaScript (Express)
Signature Verification
Verify webhook signatures for security:- Python
- JavaScript
Custom Headers
Include custom headers in webhook callbacks:- Python
- JavaScript
Complete Example
Here’s a complete example with ML model training:- Python
- JavaScript
Webhook Payload
The webhook payload structure:X-HopX-Signature: HMAC-SHA256 signature (if secret provided)X-HopX-Timestamp: Unix timestamp- Custom headers from
callback_headers
Best Practices
1
1. Always Verify Signatures
Use
callback_signature_secret and verify signatures in your webhook handler to ensure requests are authentic.2
2. Handle Timeouts
Set appropriate timeouts based on expected execution time. Default is 30 minutes, max is typically 1 hour.
3
3. Use Custom Headers
Include authentication tokens or identifiers in
callback_headers for secure webhook processing.4
4. Handle Both Success and Failure
Check the
status field in webhook payloads to handle both successful completions and failures.5
5. Store Execution IDs
Store
execution_id when starting async execution to correlate webhook callbacks with your records.Related
- Synchronous Execution - Basic code execution
- Background Execution - Long-running tasks
- Streaming Execution - Real-time output streaming
- SDK: sandbox.run_code_async() - Python SDK method
- API: POST /execute/async - VM Agent API endpoint
- CLI Code Execution - Execute code from CLI
Next Steps
- Learn about Background Execution for shorter tasks
- Explore Process Management for monitoring
- Review Synchronous Execution for immediate results

