Method signature
Parameters
This method takes no parameters.Return value
Type | Description |
---|---|
Promise<void> | The method completes successfully when the sandbox is paused |
Behavior
Thepause()
method performs the following actions:
- Agent Type Validation: Verifies that the current agent is of type “codex”
- Initialization Check: Ensures the CodexAgent instance is properly initialized
- Sandbox Pausing: Calls the underlying
pauseSandbox()
method to pause the active sandbox
Examples
Basic Usage
With Error Handling
Resource Management Pattern
Auto-Pause on Inactivity
Error handling
The method throws errors in the following cases:Agent Type Error
Initialization Error
Example Error Handling
Use cases
Cost Optimization
Pause sandboxes during periods of inactivity to reduce resource costs:Batch Processing with Breaks
Pause between processing batches to manage resource usage:Conditional Resource Management
Pause based on system conditions:State preservation
When a sandbox is paused, its state is preserved including:
- File system contents
- Environment variables
- Running processes (suspended)
- Network connections (may timeout)
Notes
- State Preservation: Pausing preserves the sandbox state, unlike
kill()
which destroys it - Resource Savings: Paused sandboxes consume significantly fewer resources
- Resumable: Use
resume()
to continue from exactly where you left off - Best Practice: Pause during periods of inactivity to optimize resource usage and costs
- Automatic Cleanup: Consider implementing auto-pause mechanisms for long-running applications