Tools¶
Tools and utilities for Bedrock AgentCore SDK including browser and code interpreter tools.
bedrock_agentcore.tools.code_interpreter_client
¶
Client for interacting with the Code Interpreter sandbox service.
This module provides a client for the AWS Code Interpreter sandbox, allowing applications to start, stop, and invoke code execution in a managed sandbox environment.
CodeInterpreter
¶
Client for interacting with the AWS Code Interpreter sandbox service.
This client handles the session lifecycle and method invocation for Code Interpreter sandboxes, providing an interface to execute code in a secure, managed environment.
Attributes:
| Name | Type | Description |
|---|---|---|
region |
str
|
The AWS region being used. |
control_plane_client |
The boto3 client for control plane operations. |
|
data_plane_service_name |
str
|
AWS service name for the data plane. |
client |
str
|
The boto3 client for interacting with the service. |
identifier |
str
|
The code interpreter identifier. |
session_id |
str
|
The active session ID. |
Source code in bedrock_agentcore/tools/code_interpreter_client.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
identifier
property
writable
¶
Get the current code interpreter identifier.
session_id
property
writable
¶
Get the current session ID.
__init__(region, session=None)
¶
Initialize a Code Interpreter client for the specified AWS region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
region
|
str
|
The AWS region to use. |
required |
session
|
Optional[Session]
|
Optional boto3 session. |
None
|
Source code in bedrock_agentcore/tools/code_interpreter_client.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
create_code_interpreter(name, execution_role_arn, network_configuration=None, description=None, tags=None, client_token=None)
¶
Create a custom code interpreter with specific configuration.
This is a control plane operation that provisions a new code interpreter with custom settings including VPC configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name for the code interpreter. Must match pattern [a-zA-Z][a-zA-Z0-9_] |
required |
execution_role_arn
|
str
|
IAM role ARN with permissions for interpreter operations |
required |
network_configuration
|
Optional[Dict]
|
Network configuration: { "networkMode": "PUBLIC" or "VPC", "vpcConfig": { # Required if networkMode is VPC "securityGroups": ["sg-xxx"], "subnets": ["subnet-xxx"] } } |
None
|
description
|
Optional[str]
|
Description of the interpreter (1-4096 chars) |
None
|
tags
|
Optional[Dict[str, str]]
|
Tags for the interpreter |
None
|
client_token
|
Optional[str]
|
Idempotency token |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict
|
Response containing: - codeInterpreterArn (str): ARN of created interpreter - codeInterpreterId (str): Unique interpreter identifier - createdAt (datetime): Creation timestamp - status (str): Interpreter status (CREATING, READY, etc.) |
Example
client = CodeInterpreter('us-west-2')
Create interpreter with VPC¶
response = client.create_code_interpreter( ... name="my_secure_interpreter", ... execution_role_arn="arn:aws:iam::123456789012:role/InterpreterRole", ... network_configuration={ ... "networkMode": "VPC", ... "vpcConfig": { ... "securityGroups": ["sg-12345"], ... "subnets": ["subnet-abc123"] ... } ... }, ... description="Secure interpreter for data analysis" ... ) interpreter_id = response['codeInterpreterId']
Source code in bedrock_agentcore/tools/code_interpreter_client.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
delete_code_interpreter(interpreter_id, client_token=None)
¶
Delete a custom code interpreter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interpreter_id
|
str
|
The code interpreter identifier to delete |
required |
client_token
|
Optional[str]
|
Idempotency token |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict
|
Response containing: - codeInterpreterId (str): ID of deleted interpreter - lastUpdatedAt (datetime): Update timestamp - status (str): Deletion status |
Example
client.delete_code_interpreter("my-interpreter-abc123")
Source code in bedrock_agentcore/tools/code_interpreter_client.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
get_code_interpreter(interpreter_id)
¶
Get detailed information about a code interpreter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interpreter_id
|
str
|
The code interpreter identifier |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict
|
Interpreter details including: - codeInterpreterArn, codeInterpreterId, name, description - createdAt, lastUpdatedAt - executionRoleArn - networkConfiguration - status (CREATING, CREATE_FAILED, READY, DELETING, etc.) - failureReason (if failed) |
Example
interpreter_info = client.get_code_interpreter("my-interpreter-abc123") print(f"Status: {interpreter_info['status']}")
Source code in bedrock_agentcore/tools/code_interpreter_client.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
get_session(interpreter_id=None, session_id=None)
¶
Get detailed information about a code interpreter session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interpreter_id
|
Optional[str]
|
Interpreter ID (uses current if not provided) |
None
|
session_id
|
Optional[str]
|
Session ID (uses current if not provided) |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict
|
Session details including: - sessionId, codeInterpreterIdentifier, name - status (READY, TERMINATED) - createdAt, lastUpdatedAt - sessionTimeoutSeconds |
Example
session_info = client.get_session() print(f"Session status: {session_info['status']}")
Source code in bedrock_agentcore/tools/code_interpreter_client.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
invoke(method, params=None)
¶
Invoke a method in the code interpreter sandbox.
If no session is active, automatically starts a new session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
The name of the method to invoke. |
required |
params
|
Optional[Dict]
|
Parameters to pass to the method. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
The response from the code interpreter service. |
Example
List files in the sandbox¶
result = client.invoke('listFiles')
Execute Python code¶
code = "import pandas as pd\ndf = pd.DataFrame({'a': [1,2,3]})\nprint(df)" result = client.invoke('execute', {'code': code})
Source code in bedrock_agentcore/tools/code_interpreter_client.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
list_code_interpreters(interpreter_type=None, max_results=10, next_token=None)
¶
List all code interpreters in the account.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interpreter_type
|
Optional[str]
|
Filter by type: "SYSTEM" or "CUSTOM" |
None
|
max_results
|
int
|
Maximum results to return (1-100, default 10) |
10
|
next_token
|
Optional[str]
|
Token for pagination |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict
|
Response containing: - codeInterpreterSummaries (List[Dict]): List of interpreter summaries - nextToken (str): Token for next page (if more results) |
Example
List all custom interpreters¶
response = client.list_code_interpreters(interpreter_type="CUSTOM") for interp in response['codeInterpreterSummaries']: ... print(f"{interp['name']}: {interp['status']}")
Source code in bedrock_agentcore/tools/code_interpreter_client.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
list_sessions(interpreter_id=None, status=None, max_results=10, next_token=None)
¶
List code interpreter sessions for a specific interpreter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interpreter_id
|
Optional[str]
|
Interpreter ID (uses current if not provided) |
None
|
status
|
Optional[str]
|
Filter by status: "READY" or "TERMINATED" |
None
|
max_results
|
int
|
Maximum results (1-100, default 10) |
10
|
next_token
|
Optional[str]
|
Pagination token |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict
|
Response containing: - items (List[Dict]): List of session summaries - nextToken (str): Token for next page (if more results) |
Example
List all active sessions¶
response = client.list_sessions(status="READY") for session in response['items']: ... print(f"Session {session['sessionId']}: {session['status']}")
Source code in bedrock_agentcore/tools/code_interpreter_client.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 | |
start(identifier=DEFAULT_IDENTIFIER, name=None, session_timeout_seconds=DEFAULT_TIMEOUT)
¶
Start a code interpreter sandbox session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
Optional[str]
|
The interpreter identifier to use. Can be DEFAULT_IDENTIFIER or a custom interpreter ID from create_code_interpreter. |
DEFAULT_IDENTIFIER
|
name
|
Optional[str]
|
A name for this session. |
None
|
session_timeout_seconds
|
Optional[int]
|
The timeout in seconds. Default: 900 (15 minutes). |
DEFAULT_TIMEOUT
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The session ID of the newly created session. |
Example
Use system interpreter¶
session_id = client.start()
Use custom interpreter with VPC¶
session_id = client.start( ... identifier="my-interpreter-abc123", ... session_timeout_seconds=1800 # 30 minutes ... )
Source code in bedrock_agentcore/tools/code_interpreter_client.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
stop()
¶
Stop the current code interpreter session if one is active.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if successful or no session was active. |
Source code in bedrock_agentcore/tools/code_interpreter_client.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
code_session(region, session=None, identifier=None)
¶
Context manager for creating and managing a code interpreter session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
region
|
str
|
AWS region. |
required |
session
|
Optional[Session]
|
Optional boto3 session. |
None
|
identifier
|
Optional[str]
|
Interpreter identifier (system or custom). |
None
|
Yields:
| Name | Type | Description |
|---|---|---|
CodeInterpreter |
CodeInterpreter
|
An initialized and started code interpreter client. |
Example
Use system interpreter¶
with code_session('us-west-2') as client: ... result = client.invoke('listFiles') ...
Use custom VPC interpreter¶
with code_session('us-west-2', identifier='my-secure-interpreter') as client: ... # Secure data analysis ... pass
Source code in bedrock_agentcore/tools/code_interpreter_client.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | |
bedrock_agentcore.tools.browser_client
¶
Client for interacting with the Browser sandbox service.
This module provides a client for the AWS Browser sandbox, allowing applications to start, stop, and automate browser interactions in a managed sandbox environment using Playwright.
BrowserClient
¶
Client for interacting with the AWS Browser sandbox service.
This client handles the session lifecycle and browser automation for Browser sandboxes, providing an interface to perform web automation tasks in a secure, managed environment.
Attributes:
| Name | Type | Description |
|---|---|---|
region |
str
|
The AWS region being used. |
control_plane_client |
The boto3 client for control plane operations. |
|
data_plane_service_name |
str
|
AWS service name for the data plane. |
client |
str
|
The boto3 client for interacting with the service. |
identifier |
str
|
The browser identifier. |
session_id |
str
|
The active session ID. |
Source code in bedrock_agentcore/tools/browser_client.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
identifier
property
writable
¶
Get the current browser identifier.
session_id
property
writable
¶
Get the current session ID.
__init__(region)
¶
Initialize a Browser client for the specified AWS region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
region
|
str
|
The AWS region to use for the Browser service. |
required |
Source code in bedrock_agentcore/tools/browser_client.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
create_browser(name, execution_role_arn, network_configuration=None, description=None, recording=None, browser_signing=None, tags=None, client_token=None)
¶
Create a custom browser with specific configuration.
This is a control plane operation that provisions a new browser with custom settings including Web Bot Auth, VPC, and recording configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name for the browser. Must match pattern [a-zA-Z][a-zA-Z0-9_] |
required |
execution_role_arn
|
str
|
IAM role ARN with permissions for browser operations |
required |
network_configuration
|
Optional[Dict]
|
Network configuration: { "networkMode": "PUBLIC" or "VPC", "vpcConfig": { # Required if networkMode is VPC "securityGroups": ["sg-xxx"], "subnets": ["subnet-xxx"] } } |
None
|
description
|
Optional[str]
|
Description of the browser (1-4096 chars) |
None
|
recording
|
Optional[Dict]
|
Recording configuration: { "enabled": True, "s3Location": { "bucket": "bucket-name", "keyPrefix": "path/prefix" } } |
None
|
browser_signing
|
Optional[Dict]
|
Web Bot Auth configuration (NEW FEATURE): { "enabled": True } |
None
|
tags
|
Optional[Dict[str, str]]
|
Tags for the browser |
None
|
client_token
|
Optional[str]
|
Idempotency token |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict
|
Response containing: - browserArn (str): ARN of created browser - browserId (str): Unique browser identifier - createdAt (datetime): Creation timestamp - status (str): Browser status (CREATING, READY, etc.) |
Example
client = BrowserClient('us-west-2')
Create browser with Web Bot Auth enabled¶
response = client.create_browser( ... name="my_signed_browser", ... execution_role_arn="arn:aws:iam::123456789012:role/BrowserRole", ... network_configuration={"networkMode": "PUBLIC"}, ... browser_signing={"enabled": True}, ... recording={ ... "enabled": True, ... "s3Location": { ... "bucket": "my-recordings", ... "keyPrefix": "browser-sessions/" ... } ... } ... ) browser_id = response['browserId']
Source code in bedrock_agentcore/tools/browser_client.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
delete_browser(browser_id, client_token=None)
¶
Delete a custom browser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
browser_id
|
str
|
The browser identifier to delete |
required |
client_token
|
Optional[str]
|
Idempotency token |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict
|
Response containing: - browserId (str): ID of deleted browser - lastUpdatedAt (datetime): Update timestamp - status (str): Deletion status |
Example
client.delete_browser("my-browser-abc123")
Source code in bedrock_agentcore/tools/browser_client.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
generate_live_view_url(expires=DEFAULT_LIVE_VIEW_PRESIGNED_URL_TIMEOUT)
¶
Generate a pre-signed URL for viewing the browser session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expires
|
int
|
Seconds until URL expires (max 300). |
DEFAULT_LIVE_VIEW_PRESIGNED_URL_TIMEOUT
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The pre-signed URL for viewing. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If expires exceeds maximum. |
RuntimeError
|
If URL generation fails. |
Source code in bedrock_agentcore/tools/browser_client.py
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | |
generate_ws_headers()
¶
Generate the WebSocket headers needed for connecting to the browser sandbox.
Returns:
| Type | Description |
|---|---|
Tuple[str, Dict[str, str]]
|
Tuple[str, Dict[str, str]]: A tuple containing the WebSocket URL and headers. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no AWS credentials are found. |
Source code in bedrock_agentcore/tools/browser_client.py
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 | |
get_browser(browser_id)
¶
Get detailed information about a browser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
browser_id
|
str
|
The browser identifier |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict
|
Browser details including: - browserArn, browserId, name, description - createdAt, lastUpdatedAt - executionRoleArn - networkConfiguration - recording configuration - browserSigning configuration (if enabled) - status (CREATING, CREATE_FAILED, READY, DELETING, etc.) - failureReason (if failed) |
Example
browser_info = client.get_browser("my-browser-abc123") print(f"Status: {browser_info['status']}") if browser_info.get('browserSigning'): ... print("Web Bot Auth is enabled!")
Source code in bedrock_agentcore/tools/browser_client.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
get_session(browser_id=None, session_id=None)
¶
Get detailed information about a browser session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
browser_id
|
Optional[str]
|
Browser identifier (uses current if not provided) |
None
|
session_id
|
Optional[str]
|
Session identifier (uses current if not provided) |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict
|
Session details including: - sessionId, browserIdentifier, name - status (READY, TERMINATED) - createdAt, lastUpdatedAt - sessionTimeoutSeconds - sessionReplayArtifact (S3 location if recording enabled) - streams (automationStream, liveViewStream) - viewPort |
Example
session_info = client.get_session() print(f"Session status: {session_info['status']}") if session_info.get('sessionReplayArtifact'): ... print(f"Recording available at: {session_info['sessionReplayArtifact']}")
Source code in bedrock_agentcore/tools/browser_client.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | |
list_browsers(browser_type=None, max_results=10, next_token=None)
¶
List all browsers in the account.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
browser_type
|
Optional[str]
|
Filter by type: "SYSTEM" or "CUSTOM" |
None
|
max_results
|
int
|
Maximum results to return (1-100, default 10) |
10
|
next_token
|
Optional[str]
|
Token for pagination |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict
|
Response containing: - browserSummaries (List[Dict]): List of browser summaries - nextToken (str): Token for next page (if more results) |
Example
List all custom browsers¶
response = client.list_browsers(browser_type="CUSTOM") for browser in response['browserSummaries']: ... print(f"{browser['name']}: {browser['status']}")
Source code in bedrock_agentcore/tools/browser_client.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
list_sessions(browser_id=None, status=None, max_results=10, next_token=None)
¶
List browser sessions for a specific browser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
browser_id
|
Optional[str]
|
Browser identifier (uses current if not provided) |
None
|
status
|
Optional[str]
|
Filter by status: "READY" or "TERMINATED" |
None
|
max_results
|
int
|
Maximum results (1-100, default 10) |
10
|
next_token
|
Optional[str]
|
Pagination token |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict
|
Response containing: - items (List[Dict]): List of session summaries - nextToken (str): Token for next page (if more results) |
Example
List all active sessions¶
response = client.list_sessions(status="READY") for session in response['items']: ... print(f"Session {session['sessionId']}: {session['status']}")
Source code in bedrock_agentcore/tools/browser_client.py
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | |
release_control()
¶
Release control by enabling automation stream.
Source code in bedrock_agentcore/tools/browser_client.py
558 559 560 561 562 563 564 565 566 | |
start(identifier=DEFAULT_IDENTIFIER, name=None, session_timeout_seconds=DEFAULT_SESSION_TIMEOUT, viewport=None)
¶
Start a browser sandbox session.
This method initializes a new browser session with the provided parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
Optional[str]
|
The browser sandbox identifier to use. Can be DEFAULT_IDENTIFIER or a custom browser ID from create_browser. |
DEFAULT_IDENTIFIER
|
name
|
Optional[str]
|
A name for this session. |
None
|
session_timeout_seconds
|
Optional[int]
|
The timeout for the session in seconds. Range: 1-28800 (8 hours). Default: 3600 (1 hour). |
DEFAULT_SESSION_TIMEOUT
|
viewport
|
Optional[Dict[str, int]]
|
The viewport dimensions: |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The session ID of the newly created session. |
Example
Use system browser¶
session_id = client.start()
Use custom browser with Web Bot Auth¶
session_id = client.start( ... identifier="my-browser-abc123", ... viewport={'width': 1920, 'height': 1080}, ... session_timeout_seconds=7200 # 2 hours ... )
Source code in bedrock_agentcore/tools/browser_client.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
stop()
¶
Stop the current browser session if one is active.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if successful or no session was active. |
Source code in bedrock_agentcore/tools/browser_client.py
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
take_control()
¶
Take control of the browser by disabling automation stream.
Source code in bedrock_agentcore/tools/browser_client.py
546 547 548 549 550 551 552 553 554 555 556 | |
update_stream(stream_status, browser_id=None, session_id=None)
¶
Update the browser automation stream status.
This is the new UpdateBrowserStream API for dynamic stream control.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stream_status
|
str
|
Status to set: "ENABLED" or "DISABLED" |
required |
browser_id
|
Optional[str]
|
Browser identifier (uses current if not provided) |
None
|
session_id
|
Optional[str]
|
Session identifier (uses current if not provided) |
None
|
Example
Disable automation to take manual control¶
client.update_stream("DISABLED")
Re-enable automation¶
client.update_stream("ENABLED")
Source code in bedrock_agentcore/tools/browser_client.py
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | |
browser_session(region, viewport=None, identifier=None)
¶
Context manager for creating and managing a browser sandbox session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
region
|
str
|
AWS region. |
required |
viewport
|
Optional[Dict[str, int]]
|
Viewport dimensions. |
None
|
identifier
|
Optional[str]
|
Browser identifier (system or custom). |
None
|
Yields:
| Name | Type | Description |
|---|---|---|
BrowserClient |
BrowserClient
|
An initialized and started browser client. |
Example
Use system browser¶
with browser_session('us-west-2') as client: ... ws_url, headers = client.generate_ws_headers() ...
Use custom browser with Web Bot Auth¶
with browser_session('us-west-2', identifier='my-signed-browser') as client: ... # Automation with reduced CAPTCHA friction ... pass
Source code in bedrock_agentcore/tools/browser_client.py
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 | |