Skip to content

Commit 600028a

Browse files
committed
feat: Add proxy_configuration support to browser_session() and BrowserClient.start()
The Browser Proxy (BYOP) feature launched GA on Feb 10, 2026, but the SDK does not expose the proxyConfiguration parameter that the underlying StartBrowserSession API supports. This forces customers to drop down to raw Boto3 calls to use proxy configuration. Changes: - Add proxy_configuration parameter to BrowserClient.start() - Add proxy_configuration parameter to browser_session() context manager - Add ProxyConfiguration and related TypedDict definitions - Export ProxyConfiguration from tools package - Bump boto3/botocore minimum to >=1.42.54 (version that added proxyConfiguration to the bedrock-agentcore service model) - Add 7 unit tests for proxy config passthrough
1 parent 1bd22b7 commit 600028a

4 files changed

Lines changed: 311 additions & 5 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ classifiers = [
2626
"Topic :: Software Development :: Libraries :: Python Modules",
2727
]
2828
dependencies = [
29-
"boto3>=1.40.52",
30-
"botocore>=1.40.52",
29+
"boto3>=1.42.54",
30+
"botocore>=1.42.54",
3131
"pydantic>=2.0.0,<2.41.3",
3232
"urllib3>=1.26.0",
3333
"starlette>=0.46.2",

src/bedrock_agentcore/tools/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Bedrock AgentCore SDK tools package."""
22

3-
from .browser_client import BrowserClient, browser_session
3+
from .browser_client import BrowserClient, ProxyConfiguration, browser_session
44
from .code_interpreter_client import CodeInterpreter, code_session
55
from .config import (
66
BrowserConfiguration,
@@ -15,6 +15,7 @@
1515

1616
__all__ = [
1717
"BrowserClient",
18+
"ProxyConfiguration",
1819
"browser_session",
1920
"CodeInterpreter",
2021
"code_session",

src/bedrock_agentcore/tools/browser_client.py

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import secrets
1212
import uuid
1313
from contextlib import contextmanager
14-
from typing import Dict, Generator, Optional, Tuple
14+
from typing import Dict, Generator, List, Optional, Tuple, TypedDict
1515
from urllib.parse import urlparse
1616

1717
import boto3
@@ -29,6 +29,49 @@
2929
MAX_LIVE_VIEW_PRESIGNED_URL_TIMEOUT = 300
3030

3131

32+
class BasicAuth(TypedDict, total=False):
33+
"""Basic authentication credentials for a proxy server."""
34+
35+
secretArn: str
36+
37+
38+
class ProxyCredentials(TypedDict, total=False):
39+
"""Credentials for authenticating with a proxy server."""
40+
41+
basicAuth: BasicAuth
42+
43+
44+
class ExternalProxy(TypedDict, total=False):
45+
"""Configuration for an external proxy server."""
46+
47+
server: str
48+
port: int
49+
domainPatterns: List[str]
50+
credentials: ProxyCredentials
51+
52+
53+
class ProxyEntry(TypedDict, total=False):
54+
"""A single proxy entry in the proxy configuration."""
55+
56+
externalProxy: ExternalProxy
57+
58+
59+
class ProxyBypass(TypedDict, total=False):
60+
"""Domains that bypass all proxy servers."""
61+
62+
domainPatterns: List[str]
63+
64+
65+
class ProxyConfiguration(TypedDict, total=False):
66+
"""Proxy configuration for routing browser traffic through external proxy servers.
67+
68+
See: https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/browser-proxies.html
69+
"""
70+
71+
proxies: List[ProxyEntry]
72+
bypass: ProxyBypass
73+
74+
3275
class BrowserClient:
3376
"""Client for interacting with the AWS Browser sandbox service.
3477
@@ -289,6 +332,7 @@ def start(
289332
name: Optional[str] = None,
290333
session_timeout_seconds: Optional[int] = DEFAULT_SESSION_TIMEOUT,
291334
viewport: Optional[Dict[str, int]] = None,
335+
proxy_configuration: Optional[ProxyConfiguration] = None,
292336
) -> str:
293337
"""Start a browser sandbox session.
294338
@@ -302,6 +346,9 @@ def start(
302346
Range: 1-28800 (8 hours). Default: 3600 (1 hour).
303347
viewport (Optional[Dict[str, int]]): The viewport dimensions:
304348
{'width': 1920, 'height': 1080}
349+
proxy_configuration (Optional[ProxyConfiguration]): Proxy configuration for
350+
routing browser traffic through external proxy servers. See
351+
https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/browser-proxies.html
305352
306353
Returns:
307354
str: The session ID of the newly created session.
@@ -316,6 +363,20 @@ def start(
316363
... viewport={'width': 1920, 'height': 1080},
317364
... session_timeout_seconds=7200 # 2 hours
318365
... )
366+
>>>
367+
>>> # Use proxy configuration
368+
>>> session_id = client.start(
369+
... proxy_configuration={
370+
... "proxies": [{
371+
... "externalProxy": {
372+
... "server": "proxy.example.com",
373+
... "port": 8080,
374+
... "domainPatterns": [".example.com"],
375+
... }
376+
... }],
377+
... "bypass": {"domainPatterns": [".amazonaws.com"]}
378+
... }
379+
... )
319380
"""
320381
self.logger.info("Starting browser session...")
321382

@@ -328,6 +389,9 @@ def start(
328389
if viewport is not None:
329390
request_params["viewPort"] = viewport
330391

392+
if proxy_configuration is not None:
393+
request_params["proxyConfiguration"] = proxy_configuration
394+
331395
response = self.data_plane_client.start_browser_session(**request_params)
332396

333397
self.identifier = response["browserIdentifier"]
@@ -581,14 +645,19 @@ def release_control(self):
581645

582646
@contextmanager
583647
def browser_session(
584-
region: str, viewport: Optional[Dict[str, int]] = None, identifier: Optional[str] = None
648+
region: str,
649+
viewport: Optional[Dict[str, int]] = None,
650+
identifier: Optional[str] = None,
651+
proxy_configuration: Optional[ProxyConfiguration] = None,
585652
) -> Generator[BrowserClient, None, None]:
586653
"""Context manager for creating and managing a browser sandbox session.
587654
588655
Args:
589656
region (str): AWS region.
590657
viewport (Optional[Dict[str, int]]): Viewport dimensions.
591658
identifier (Optional[str]): Browser identifier (system or custom).
659+
proxy_configuration (Optional[ProxyConfiguration]): Proxy configuration for
660+
routing browser traffic through external proxy servers.
592661
593662
Yields:
594663
BrowserClient: An initialized and started browser client.
@@ -602,13 +671,22 @@ def browser_session(
602671
>>> with browser_session('us-west-2', identifier='my-signed-browser') as client:
603672
... # Automation with reduced CAPTCHA friction
604673
... pass
674+
...
675+
>>> # Use proxy configuration
676+
>>> with browser_session('us-west-2', proxy_configuration={
677+
... "proxies": [{"externalProxy": {"server": "proxy.corp.com", "port": 8080}}],
678+
... "bypass": {"domainPatterns": [".amazonaws.com"]}
679+
... }) as client:
680+
... ws_url, headers = client.generate_ws_headers()
605681
"""
606682
client = BrowserClient(region)
607683
start_kwargs = {}
608684
if viewport is not None:
609685
start_kwargs["viewport"] = viewport
610686
if identifier is not None:
611687
start_kwargs["identifier"] = identifier
688+
if proxy_configuration is not None:
689+
start_kwargs["proxy_configuration"] = proxy_configuration
612690

613691
client.start(**start_kwargs)
614692

0 commit comments

Comments
 (0)