maf-sandbox-drawio
Experimental. Releases before 1.0 may change or remove APIs. Importing this package emits
MafSandboxDrawioExperimentalWarning.
Create an editable diagram.drawio from model-supplied XML. The create_drawio(xml: str) tool validates draw.io cells, applies layout when needed and delivers the file through the host's OutputSink.
Requires Python 3.12–3.14.
pip install maf-sandbox-drawio
Attach the tool
from maf_sandbox_drawio import make_drawio_tools
tools = make_drawio_tools(
router,
agent_id="diagram-designer",
context=context,
sink=sink,
image="drawio-sandbox:local",
preserve_layout=True,
direction="TB",
)
The host supplies the router, CallerContext and sink. The model supplies only XML; storage and layout settings belong to the host.
Use make_file_system_sink(output_directory, existing="replace") to replace the previous diagram, or a per-call sink to retain separate outputs. The result contains the sink's display reference after delivery.
Build the image from the repository root:
docker build -t drawio-sandbox:local images/drawio-sandbox
The image needs Python and Graphviz. The kind requires a POSIX backend with EXEC, FILES_IN and FILES_OUT. It uses closed network access and the host's isolation floor. Core disposes after each call by default.
For Docker, use await DockerSandboxBackend.create(config) so the backend declares POSIX. The plain constructor does not declare an OS family.
Model input
Accepts one uncompressed mxGraphModel or an mxfile containing uncompressed pages:
<mxGraphModel>
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="a" value="Start" vertex="1" parent="1"/>
<mxCell id="b" value="Finish" vertex="1" parent="1"/>
<mxCell id="edge" edge="1" source="a" target="b" parent="1"/>
</root>
</mxGraphModel>
The output keeps native editable shapes, connectors, labels, styles, IDs, metadata and layers. It does not render a preview or fetch external resources. XML references remain in the artifact, so validation is not content sanitization.
Layout policy
| Input geometry | preserve_layout=True |
preserve_layout=False |
|---|---|---|
| Complete | Keep supplied positions and sizes | Apply automatic layout |
| Incomplete | Apply automatic layout | Apply automatic layout |
Complete geometry needs positive width and height for each vertex. Missing x or y means zero. Overlapping vertices are accepted. Missing connector waypoints do not trigger layout; missing edge geometry receives standard relative geometry.
Automatic layout handles flat flowcharts and component graphs, including cycles and disconnected components. direction="TB" places the graph top to bottom; "LR" places it left to right.
Graphviz chooses positions and connector paths. Supplied dimensions and rotation are retained; missing dimensions use 160 by 80. Automatic layout replaces routing hints while keeping appearance styles.
Nested groups, relative ports, edge-label vertices, collapsed cells and detached edges require complete geometry with preservation enabled. They are refused when automatic layout is needed.
The tool provides no sequence, BPMN or ER-specific layout, automatic label fitting or guarantee against every overlap. Give large labels explicit dimensions. Preserved geometry keeps its values, not byte-for-byte XML formatting.
Validation and limits
Every page is checked before and after layout. Invalid IDs, parent cycles, broken endpoints, unsupported geometry and non-finite coordinates are refused. DTDs, entities and compressed pages are refused too.
| Limit | Value |
|---|---|
| Input | 1 MiB, up to 8 pages and 1,000 cells per page |
| Automatic layout | Up to 200 vertices and 600 edges per page |
| Output | One file, at most 2 MiB |
| Execution | One deadline for all pages: 60 seconds by default, at most 300 |
| Diagnostics | At most 2,048 characters |
A failure on any page prevents delivery of the entire artifact. create_drawio returns separate content items: trusted completion and verdict, any fixed explanation, and untrusted sink display text or converter diagnostics. The verdict is created after delivery and refused for rejected XML or unsupported layout requests. Invalid tool arguments, execution failures, missing output and delivery failures remain incomplete with no verdict. The host sets confidentiality and destination policy.
Verify all four layout-policy cases against Docker from a repository checkout:
uv run python scripts/check_drawio_docker.py --image drawio-sandbox:local --output out/drawio
See the kind guide for accepted geometry and labels, and the image definition for pinned dependencies.
Release files for maf-sandbox-drawio 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| maf_sandbox_drawio-0.3.1.tar.gz | 14.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| maf_sandbox_drawio-0.3.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 29.7 kB
Release files / maf_sandbox_drawio-0.3.1.tar.gz
| Download URL | maf_sandbox_drawio-0.3.1.tar.gz |
|---|---|
| Size | 14.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2b5fe51adfd487f386b4b9bc92aa80ef54dd9e7820008019ae9e7bafdfa696db
|
|
BLAKE2b-256 checksum How to use checksums |
fca525a2c14c64114f5b8e77905e0159075f7ff4675e4330db94b314ed9c16cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 24, 2026.
Transparency logRelease files / maf_sandbox_drawio-0.3.1-py3-none-any.whl
| Download URL | maf_sandbox_drawio-0.3.1-py3-none-any.whl |
|---|---|
| Size | 15.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8863b03602ba26940639de179356554d634215d1343b78d8e74c1c18bf7cc2a9
|
|
BLAKE2b-256 checksum How to use checksums |
4490ae34c7d73d17a95bdb5c4677615e6e568e1ee3e2991fd1459baf0f599880
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 24, 2026.
Transparency log