Skip to main content

Method signature

Parameters

This method takes no parameters.

Return value

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:
  • setSession - Set a specific session ID for the sandbox
  • generateCode - 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