maf-sandbox-document
Experimental. Releases before 1.0 may change or remove APIs. Importing this package emits
MafSandboxDocumentExperimentalWarning.
Read PDF, DOCX, PPTX and RTF files through a fixed converter in a disposable sandbox. The model chooses a listed file, output format and optional page range; it supplies no converter code. Parsers and archive/XML guards run in the guest.
This package is experimental and not yet published. Its first release requires the core release containing binary file-store reads; release core before this package. The image must also have a completed, currently eligible document release before the kind publishes.
Attach the tool
from maf_sandbox_document import make_document_tools
[document_read] = make_document_tools(
router,
file_store,
"document-reader",
context,
sink,
image=verified_document_image,
formats=("text", "markdown"), # Enable images only for a host that can consume them.
)
The host supplies a store with async read(name) -> bytes | None, and context.list_files(store) returns authorized ListedFile entries. Text-only AgentFileStore implementations need a binary adapter. Names are matched exactly, never interpreted as host paths, guest paths or URLs. The host must bound ingress bytes before the store returns them; the kind independently checks its 16 MiB input limit.
Use file_store_provenance for stores that may change during a call and requires_file_integrity when admission requires an established source label. Completion and the extracted/refused verdict are trusted. Document text, metadata, images, delivery references and converter diagnostics are guest-derived output. Core derives their effective label from the file read, model arguments and conversation.
The router must allow at least container isolation and supply POSIX EXEC, FILES_IN and FILES_OUT with closed egress. Every call requires its own sandbox and disposal, including refusal, failure and cancellation.
Tool contract
document_read(file, format="text", pages=None) accepts text, markdown or images. pages is a positive, 1-based inclusive range such as "2-5" or "3". PDF ranges select pages; PPTX ranges select slides. Both endpoints clamp to the available last page. DOCX has no reliable pagination without a layout engine, so an explicit range is refused. RTF ignores ranges.
| Input | Text / Markdown | Images | Limits |
|---|---|---|---|
| PDFium text in reading order; Markdown retains that text | PNG pages at the host's fixed DPI | Supported PDF subset below; no OCR | |
| DOCX | Mammoth text or Markdown conversion | Refused | No pagination or faithful layout |
| PPTX | Slide text, table cells and notes; Markdown slide headings | Refused | No office renderer |
RTF (application/rtf, text/rtf) |
striprtf text, also usable as plain Markdown | Refused | Page range ignored |
Outputs are document.txt (text/plain), document.md (text/markdown) or page-N.png (image/png), plus document.json (application/json). Image names preserve original page numbers. An extracted verdict requires delivery of every requested output. Guard refusals deliver only the metadata and diagnostic. Invalid arguments, missing files, acquisition failures, timeouts, operational exits and incomplete delivery return completed=False with no verdict.
Metadata schema version 1 contains media_type, format, supported_formats, pages (a page/slide count, or null), selected_pages, characters, truncated (always false), range_clamped, verdict, reason and files. A refusal never represents capped content as a successful extraction.
Host options and guards
| Option | Default | Allowed |
|---|---|---|
exec_timeout_seconds |
60 | Finite number greater than 0, at most 300 |
max_pages |
200 | 1–10,000 |
max_chars |
1,000,000 | 1–8,000,000 |
image_dpi |
96 | 1–600 |
max_image_pixels |
16,000,000 | 1–32,000,000 per page |
max_image_pages |
20 | 1–100 per call |
formats |
text, markdown, images | Nonempty tuple of distinct enabled formats |
OOXML is checked before Mammoth or python-pptx opens it: at most 2,048 ZIP entries, 16 MiB per expanded member, 64 MiB total, and a declared expansion ratio at most 200. Absolute/traversing/duplicate names, symlinks, encryption, unsupported compression and nested archives are refused. Bounded decompression verifies stream completion, actual lengths and CRCs independently of declared member sizes; converters receive a rebuilt, stored-only ZIP. XML preflight refuses DTDs and entity declarations, including UTF-16 declarations and XML in nonstandard member names. python-pptx uses a parser with entity resolution, DTD loading and network access disabled. Mammoth's pinned minidom path receives only the preflighted XML; external file access and embedded style maps are disabled.
PDF preflight admits a single classic cross-reference table, bounded objects and streams with no compression, Flate, ASCII85 or ASCIIHex. Each decoded stream is at most 32 MiB, with 64 MiB total. Drawing syntax is checked in page content, forms, annotation appearances, tiling patterns and Type 3 glyph programs, with at most 64 MiB of content including repeated uses; binary image and font bytes are not interpreted as drawing commands. Object/cross-reference streams, incremental or encrypted PDFs, external streams, inline images, other filters (including JPEG/JPEG2000) and decoding parameters are refused. ASCII85 streams containing NUL or form-feed whitespace are also refused because the pinned PDFium decoder stops at those bytes. This deliberately restricts compatibility: PDFium has no public per-stream allocation limit, so unsupported structures are not passed to it. A host can prepare an accepted PDF before ingress; this kind never silently falls back to an unbounded parser. Text is capped at 100,000 characters per PDF page or PPTX slide as well as the configured total.
Outputs are capped at 32 MiB per file and 64 MiB total including metadata, independently of backend transfer limits. The execution deadline covers preflight and conversion together. Backend resource limits remain necessary for native parser allocations, CPU and temporary storage; these guards do not establish immunity to parser exploits.
See the document contract and image guide for verification and release evidence.
Metadata
Release files for maf-sandbox-document 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| maf_sandbox_document-0.2.0.tar.gz | 18.2 kB | With provenance | Details for maf_sandbox_document-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| maf_sandbox_document-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for maf_sandbox_document-0.2.0-py3-none-any.whl |
Total release size: 38.2 kB
Release files / maf_sandbox_document-0.2.0.tar.gz
| Download URL | maf_sandbox_document-0.2.0.tar.gz |
|---|---|
| Size | 18.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8460199e3dcf5dc2f1e4da7da0d887300de7ac0ebfd5c7e40dbd5f5ae62c5c52
|
|
BLAKE2b-256 checksum How to use checksums |
35fa984ccb1864462db7c96fa6ee4c394e4c937e1d7acfb32e5e4d362514c235
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.
Transparency logRelease files / maf_sandbox_document-0.2.0-py3-none-any.whl
| Download URL | maf_sandbox_document-0.2.0-py3-none-any.whl |
|---|---|
| Size | 19.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6b43cbba4234754ba10b1740d92561b1c1cdb28937b84aa8354d58c95a3f592c
|
|
BLAKE2b-256 checksum How to use checksums |
346ba1e16d5583a673942eab0b98e25328968950923cddcba53c0afd8da45550
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.
Transparency logSecurity for maf-sandbox-document 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for maf_sandbox_document-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.