setSession
Sets the session ID for the sandbox environment. This method allows you to restore or switch between existing sandbox sessions.
Method signature
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
sessionId | string | Yes | The session ID to set for the sandbox environment. Must be a valid session identifier from a previously created session. |
Return value
Type | Description |
---|---|
Promise<void> | This method doesn’t return a value but resolves when the session is successfully set |
Examples
Basic Usage
Session Switching
Session Restoration
Multi-Project Workflow
Error handling
The method throws errors in the following cases:
Initialization Error
- Condition: When the agent is not properly initialized
- Error Message: “Agent not initialized”
- Solution: Verify your configuration includes valid credentials and the agent is properly set up
Invalid Session Error
- Condition: When the provided session ID is invalid or expired
- Behavior: May throw sandbox-specific errors or fail silently depending on the underlying implementation
Configuration requirements
Use cases
Session Persistence Across App Restarts
Multi-User Session Management
Project-Based Session Isolation
Related methods
getSession
- Retrieve the current session IDgenerateCode
- Generate code (creates a session if none exists)
Notes
- Session Validation: The method doesn’t validate if the session ID exists or is accessible until subsequent operations
- Session Switching: You can switch between sessions at any time using this method
- State Isolation: Each session maintains its own sandbox state and file system
- Cross-Agent Support: This functionality works with both Codex and Claude agents
- No Return Value: The method resolves with
void
when successful - Immediate Effect: The session change takes effect immediately for subsequent operations