scalable/ai/agentcore/lesson 06 cph / /
lesson 06 / 08 · 12 min · updated ·

browser & code interpreter

two managed tools you get for free — when to reach for each.

two managed tools

some tools are worth building, some aren't. a managed browser and a managed code sandbox fall in the second category — every team has the same requirements (isolate, clean up, scale, record) and no team wants to run that infrastructure themselves. agentcore ships both as first-class primitives.

  1. browser a managed headless chromium the agent can drive — navigate, click, extract, screenshot. stateful within a session, torn down at the end. for tasks where the cleanest api is "click the button a human would."
  2. code interpreter a managed javascript/typescript sandbox. the agent writes code, runs it, gets the result. ephemeral filesystem, no network by default, strict memory/cpu limits. for math, parsing, transformation — the things llms are bad at doing in-head.

when to reach for each

the rule: use gateway (lesson 4) when a real api exists. reach for browser only when the clean path is through a human-facing ui. reach for code interpreter when the agent needs to compute something deterministic — stats, parsing, regex, data transformation — and you don't want the llm to fake its way through it.

browser — navigate, extract, close

visit two pages, extract text
ready

in the sandbox we pre-register fake pages so navigation has something to return. in production you just call navigate(url) and get the real thing. the api is intentionally small — navigate, extract, click, screenshot, close — because anything more elaborate belongs to the agent's logic, not the browser primitive. the real typescript sdk also ships PlaywrightBrowser for teams that want the full playwright surface on top.

code interpreter — exec, capture, return

run agent-generated code in an isolated function scope
ready

the contract: whatever the code returns is handed back to the caller. exceptions propagate, but only within the sandbox — your agent process is untouched. in production the sandbox is a firecracker microvm; here it's a plain AsyncFunction because we're already inside a worker.

why not just let the llm compute? because llms are bad at arithmetic and excellent at writing the code that does arithmetic. offload the deterministic work to a sandbox and you get reliable results and a clean audit trail — you can see exactly what code ran.

combined — browser feeds interpreter

the common pattern: fetch unstructured text with the browser, hand it to the code interpreter for parsing and computation. neither primitive alone is powerful; together they replace what used to take three third-party services.

browser extracts, interpreter parses
ready

read the trace end-to-end: app.invokebrowser.navigatebrowser.extract_textbrowser.closecode_interpreter.executecode_interpreter.resultapp.done. that's the shape of an agent that reads the web and reasons about numbers, with zero custom infrastructure.

isolation, scale, cleanup

the things you don't have to think about, per the managed contract: every browser session is isolated (no cross-session cookies, no shared state), scales out to thousands of concurrent instances, and tears down cleanly when the invocation ends. same for code interpreter: fresh namespace per call, ephemeral fs, resource caps enforced by the runtime.

next: observability — reading the trace, and adding your own.

scalable labs·cvr 30091604·github·linkedin·hello@scalable.dk