2424class SessionInfo :
2525 """
2626 Information about a code interpreter session.
27-
27+
2828 This dataclass stores the essential information for managing active code
2929 interpreter sessions, including the session identifier, description, and
3030 the underlying Bedrock client instance.
31-
31+
3232 Attributes:
3333 session_id (str): Unique identifier for the session assigned by AWS Bedrock.
3434 description (str): Human-readable description of the session purpose.
@@ -44,43 +44,43 @@ class SessionInfo:
4444class AgentCoreCodeInterpreter (CodeInterpreter ):
4545 """
4646 Bedrock AgentCore implementation of the CodeInterpreter.
47-
47+
4848 This class provides a code interpreter interface using AWS Bedrock AgentCore services.
4949 It supports executing Python, JavaScript, and TypeScript code in isolated sandbox
5050 environments with custom code interpreter identifiers.
51-
51+
5252 The class maintains session state and provides methods for code execution, file
5353 operations, and session management. It supports both default AWS code interpreter
5454 environments and custom environments specified by identifier.
55-
55+
5656 Examples:
5757 Basic usage with default identifier:
58-
58+
5959 >>> interpreter = AgentCoreCodeInterpreter(region="us-west-2")
6060 >>> # Uses default identifier: "aws.codeinterpreter.v1"
61-
61+
6262 Using a custom code interpreter identifier:
63-
63+
6464 >>> custom_id = "my-custom-interpreter-abc123"
6565 >>> interpreter = AgentCoreCodeInterpreter(
66- ... region="us-west-2",
66+ ... region="us-west-2",
6767 ... identifier=custom_id
6868 ... )
69-
69+
7070 Environment-specific usage:
71-
71+
7272 >>> # For testing environments
7373 >>> test_interpreter = AgentCoreCodeInterpreter(
7474 ... region="us-east-1",
7575 ... identifier="test-interpreter-xyz789"
7676 ... )
77-
78- >>> # For production environments
77+
78+ >>> # For production environments
7979 >>> prod_interpreter = AgentCoreCodeInterpreter(
8080 ... region="us-west-2",
8181 ... identifier="prod-interpreter-def456"
8282 ... )
83-
83+
8484 Attributes:
8585 region (str): The AWS region where the code interpreter service is hosted.
8686 identifier (str): The code interpreter identifier being used for sessions.
@@ -97,24 +97,24 @@ def __init__(self, region: Optional[str] = None, identifier: Optional[str] = Non
9797 identifier (Optional[str]): Custom code interpreter identifier to use
9898 for code execution sessions. This allows you to specify custom code
9999 interpreter environments instead of the default AWS-provided one.
100-
100+
101101 Valid formats include:
102102 - Default identifier: "aws.codeinterpreter.v1" (used when None)
103103 - Custom identifier: "my-custom-interpreter-abc123"
104104 - Environment-specific: "test-interpreter-xyz789"
105-
105+
106106 Note: Use the code interpreter ID, not the full ARN. The AWS service
107107 expects the identifier portion only (e.g., "my-interpreter-123" rather
108108 than "arn:aws:bedrock-agentcore:region:account:code-interpreter-custom/my-interpreter-123").
109-
109+
110110 If not provided, defaults to "aws.codeinterpreter.v1" for backward
111111 compatibility. Defaults to None.
112-
112+
113113 Note:
114114 This constructor maintains full backward compatibility. Existing code
115115 that doesn't specify the identifier parameter will continue to work
116116 unchanged with the default AWS code interpreter environment.
117-
117+
118118 Raises:
119119 Exception: If there are issues with AWS region resolution or client
120120 initialization during session creation.
@@ -152,20 +152,20 @@ def cleanup_platform(self) -> None:
152152 def init_session (self , action : InitSessionAction ) -> Dict [str , Any ]:
153153 """
154154 Initialize a new Bedrock AgentCore sandbox session.
155-
155+
156156 Creates a new code interpreter session using the configured identifier.
157157 The session will use the identifier specified during class initialization,
158158 or the default "aws.codeinterpreter.v1" if none was provided.
159-
159+
160160 Args:
161161 action (InitSessionAction): Action containing session initialization parameters
162162 including session_name and description.
163-
163+
164164 Returns:
165165 Dict[str, Any]: Response dictionary containing session information on success
166166 or error details on failure. Success response includes sessionName,
167167 description, and sessionId.
168-
168+
169169 Raises:
170170 Exception: If session initialization fails due to AWS service issues,
171171 invalid identifier, or other configuration problems.
@@ -219,8 +219,8 @@ def init_session(self, action: InitSessionAction) -> Dict[str, Any]:
219219 f"Failed to initialize session '{ session_name } ' with identifier: { self .identifier } . Error: { str (e )} "
220220 )
221221 return {
222- "status" : "error" ,
223- "content" : [{"text" : f"Failed to initialize session '{ session_name } ': { str (e )} " }]
222+ "status" : "error" ,
223+ "content" : [{"text" : f"Failed to initialize session '{ session_name } ': { str (e )} " }],
224224 }
225225
226226 def list_local_sessions (self ) -> Dict [str , Any ]:
0 commit comments