Method signature
Parameters
This method takes no parameters.Return value
Type | Description |
---|---|
Promise<string | null> | The current session ID if one is set, or null if no session is active |
Examples
Basic Usage
Session Management Workflow
Error handling
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
Use cases
Session Persistence
Store and retrieve session IDs to maintain continuity across application restarts:Multi-User Applications
Track different user sessions in multi-user environments:Related methods
setSession
- Set a specific session ID for the sandboxgenerateCode
- Generate code (creates a session if none exists)
Notes
- Session Auto-Creation: Sessions are automatically created when you first use
generateCode()
with either agent - Session Persistence: Sessions persist across multiple
generateCode()
calls until explicitly changed or the sandbox is terminated - Null Return: Returns
null
when no session has been established yet - Cross-Agent Support: This functionality works with both Codex and Claude agents