Subchapter 14.1
references/browser.mdMarkdown10 KBView on GitHub
Add the AgentCore Browser tool so your agent can navigate web pages, fill forms, and extract information.
Scripts
Process Payment ToolDo NOT use this reference for:
agents-connect)code-interpreter.mdThe Browser tool is a managed Chrome instance, one per session, running in an isolated microVM. Your agent connects to it over WebSocket (via CDP — Chrome DevTools Protocol) and drives it with an automation framework. You pick the framework:
| Framework | When to use |
|---|---|
Strands AgentCoreBrowser | Agent-driven browsing inside a Strands agent. Highest-level, tool-use-native. |
| Nova Act | You want an LLM to decide the next action at each step (“click the search box, type X, press enter”). Best for open-ended tasks. |
| Playwright | Deterministic scripted automation. Best when you know the exact steps — login flows, scraping a known page structure. |
If you’re adding browsing to a Strands agent, use AgentCoreBrowser and skip the framework decision — it wraps Nova Act under the hood and fits the agent-tool mental model.
If you’re not using Strands, pick between Nova Act (reasoning-driven) and Playwright (script-driven) based on whether the task is open-ended or well-defined.
Sessions are ephemeral by default (reset after each use). Default timeout is 15 minutes, max 8 hours. You can run multiple concurrent sessions.
bedrock-agentcore SDK installedbedrock-agentcore:*Browser* actions (scope to your browser resource ARN in production)IAM policy skeleton (attach to the caller identity — your user, role, or AgentCore Runtime execution role):
{
"Version": "2012-10-17",
"Statement": [{
"Sid": "BrowserAccess",
"Effect": "Allow",
"Action": [
"bedrock-agentcore:CreateBrowser",
"bedrock-agentcore:GetBrowser",
"bedrock-agentcore:ListBrowsers",
"bedrock-agentcore:StartBrowserSession",
"bedrock-agentcore:StopBrowserSession",
"bedrock-agentcore:GetBrowserSession",
"bedrock-agentcore:ListBrowserSessions",
"bedrock-agentcore:ConnectBrowserAutomationStream",
"bedrock-agentcore:ConnectBrowserLiveViewStream"
],
"Resource": "arn:aws:bedrock-agentcore:<REGION>:<ACCOUNT_ID>:browser/*"
}]
}Check current IAM action names against the docs — the list evolves.
from strands import Agent
from strands_tools.browser import AgentCoreBrowser
browser_tool = AgentCoreBrowser(region="<REGION>")
agent = Agent(tools=[browser_tool.browser])
result = agent("Find the release date of the latest AgentCore SDK on GitHub.")
print(result.message["content"][0]["text"])Install: pip install bedrock-agentcore strands-agents strands-agents-tools
The agent decides when to use the browser, opens sessions on demand, and cleans them up. Under the hood, AgentCoreBrowser uses the AWS-managed aws.browser.v1 resource — no resource creation needed.
Dropping into an AgentCore Runtime entrypoint:
from bedrock_agentcore.runtime import BedrockAgentCoreApp
from strands import Agent
from strands_tools.browser import AgentCoreBrowser
from model.load import load_model # scaffolded by `agentcore create`
import os
app = BedrockAgentCoreApp()
REGION = os.getenv("AWS_REGION", "us-west-2")
@app.entrypoint
def invoke(payload, context):
browser_tool = AgentCoreBrowser(region=REGION)
agent = Agent(model=load_model(), tools=[browser_tool.browser])
result = agent(payload.get("prompt", ""))
return {"response": str(result)}
if __name__ == "__main__":
app.run()Use when the task needs an LLM to decide each click/type step.
from bedrock_agentcore.tools.browser_client import browser_session
from nova_act import NovaAct
def run_browser_task(prompt: str, starting_page: str, nova_act_key: str, region: str = "us-west-2"):
with browser_session(region) as client:
ws_url, headers = client.generate_ws_headers()
with NovaAct(
cdp_endpoint_url=ws_url,
cdp_headers=headers,
nova_act_api_key=nova_act_key,
starting_page=starting_page,
) as nova:
return nova.act(prompt)Install: pip install bedrock-agentcore nova-act boto3
The browser_session context manager handles start/stop. Do not leak sessions — always use the context manager or wrap raw BrowserClient calls in try/finally.
Credential handling: the Nova Act API key is a secret. If this is running inside an AgentCore Runtime agent, register it as a credential (agentcore add credential --name NovaAct --api-key ...) and retrieve it with @requires_api_key(provider_name="NovaAct"). Do not put it in runtime env vars. See agents-connect Path D.
Use when the steps are fixed and you want deterministic behavior (logins, scrapes, automated tests).
import asyncio
from bedrock_agentcore.tools.browser_client import browser_session
from playwright.async_api import async_playwright
async def scrape_title(url: str, region: str = "us-west-2") -> str:
async with async_playwright() as pw:
with browser_session(region) as client:
ws_url, headers = client.generate_ws_headers()
browser = await pw.chromium.connect_over_cdp(ws_url, headers=headers)
context = browser.contexts[0]
page = context.pages[0]
try:
await page.goto(url)
return await page.title()
finally:
await page.close()
await browser.close()
print(asyncio.run(scrape_title("https://example.com")))Install: pip install bedrock-agentcore playwright
Sync variant (sync_playwright) is also supported — pick based on whether your agent code is async.
Browser is observable by default:
/aws/bedrock-agentcore/browser/*AWS/BedrockAgentCore namespaceSession recording (DOM, clicks, console logs, network) is opt-in per browser. To enable:
aws.browser.v1) with recording configureds3:PutObject on your recording bucketThe managed aws.browser.v1 resource does not record. Use custom browsers when you need audit trails.
# Right — context manager
with browser_session(region) as client:
ws_url, headers = client.generate_ws_headers()
...
# Also right — explicit try/finally
client = BrowserClient(region=region)
client.start()
try:
...
finally:
client.stop()
# Wrong — leaked session
client = BrowserClient(region=region)
client.start()
... # if this raises, the session sits idle until its 15-minute timeoutSessions hold a microVM. Leaked sessions cost money until they time out. The context manager is non-negotiable for production.
If your agent runs in VPC mode, the Browser tool can also run in VPC. See vpc.md for the subnet + security group pattern (the same service-linked role covers Browser ENIs). Browser in VPC requires a NAT gateway for public-internet sites — public subnets don’t give Browser internet access.
“Access denied” starting a session: IAM is missing StartBrowserSession on the browser resource ARN. Check aws sts get-caller-identity matches the identity you attached the policy to.
“Model access denied” from a Strands agent: The browser tool itself is fine, but the agent’s model isn’t enabled. Go to Bedrock console → Model access → enable your model in the region.
Nova Act errors about API key: The key is US-amazon.com-accounts only at launch. If you’re outside the US or using a work account, you can’t use Nova Act yet — fall back to Playwright or Strands.
Browser session times out mid-task: Default is 15 minutes of idle time. Pass sessionTimeoutSeconds to StartBrowserSession (max 28800 = 8 hours). Don’t use this to cover up agents that are slow — fix the agent or chunk the work.
Live view doesn’t show your session: Live view requires ConnectBrowserLiveViewStream IAM permission. The session also has to be Ready, not Starting or Stopping.
browser/* in the account, not Resource: "*"agentcore add credential + @requires_api_key, not env vars.env.local, no credential provider) — typically by reading a local secret for development and the credential provider for production