Skip to main content

Method signature

Parameters

Return value

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

  • getSession - Retrieve the current session ID
  • generateCode - 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