Skip to main content
Background execution allows you to start code execution and return immediately, without waiting for completion. This is ideal for long-running tasks that you want to monitor and manage separately.

Prerequisites

Before you begin, make sure you have:
  • Active sandbox - A running sandbox (see Creating Sandboxes)
  • Understanding of synchronous execution - Familiarity with Synchronous Execution is helpful
  • Long-running task - Code that takes more than a few minutes to complete

Overview

Background execution is perfect for:
  • Long-running computations (>5 minutes)
  • Tasks that don’t need immediate results
  • Parallel processing of multiple tasks
  • Workflows where you want to check status periodically
Background execution returns immediately with a process_id. Use Process Management to check status and manage background processes.

Starting Background Execution

Start code execution in the background:

Checking Process Status

Check the status of background processes:

Process Naming

Name your processes for easier identification:

Environment Variables

Pass environment variables to background execution:

Timeout Configuration

Set timeout for background execution:

Complete Example

Here’s a complete example showing background execution workflow:

Best Practices

1

1. Use Descriptive Names

Always name your background processes for easier identification when listing and managing them.
2

2. Set Appropriate Timeouts

Set timeouts based on expected execution time. Default is 5 minutes, but you can extend for longer tasks.
3

3. Monitor Status Regularly

Check process status periodically to track progress and handle completion or failures.
4

4. Clean Up Completed Processes

Remove completed processes to keep your process list manageable. Use Process Management for cleanup.
5

5. Handle Failures

Always check for failed status and handle errors appropriately. Access stderr for error details.

Implementation

Next Steps