Skip to content

API Reference parrot_tools.scraping.confine

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_tools.scraping.confine

View source

Host confinement of the scraping tools' own file and navigation access (PA-14).

A host (Agent Studio) builds WebScrapingToolkit(confine_paths=True, plans_dir=<tenant dir>): while a scrape or crawl runs, :data:FILES_ROOT holds <plans_dir>/files and every path an action reads or writes (screenshot output_path, upload source, download directory, move_to) must resolve inside it; relative paths are taken relative to it. Unset (the default) nothing changes. :func:check_navigation applies the PA-13 host check (canonicalised literals, internal names, names resolved through the guarded resolver) to navigate targets when the host enabled the egress guard.

Attribute FILES_ROOT

Type: contextvars.ContextVar[Optional[Path]]

Class PathConfinementError

A path escapes the server-set root.

Function check_navigation

Refuse url when the egress guard is on and it targets an internal name or a non-public address.

The host is canonicalised (127.1, 0x7f.0.0.1, 0177.0.0.1, localhost., full-width digits) and a NAME is resolved through the guarded resolver, so metadata.google.internal or a name that points at a private address is refused before the browser is asked to go there.

check_navigation(url: str) -> None

Parameter Type Default Description
url str

Function confine_to_files_root

Run an async method of a tool built confine_paths=True with :data:FILES_ROOT set to self.files_root.

The root is a context variable: tasks spawned inside the call inherit it. Checks run on the event loop (never in an executor thread, which would not see it).

confine_to_files_root(method)

Parameter Type Default Description
method

Function confined_file

The FINAL directory/filename of a file an action writes, inside :data:FILES_ROOT; None when unconfined.

filename must be a bare name: a path component (/, \, .., absolute, NUL) is refused, and the joined path is resolved and checked against the root, so neither half can leave it.

confined_file(directory: str | Path, filename: str) -> Optional[Path]

Parameter Type Default Description
directory str | Path
filename str

Returns: Optional[Path]

Function within_root

raw resolved inside :data:FILES_ROOT, None when no root is set (unconfined), error when it escapes.

within_root(raw: str | Path) -> Optional[Path]

Parameter Type Default Description
raw str | Path

Returns: Optional[Path]

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally