Skip to main content

maf-sandbox-drawio

PyPI Python License

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.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for maf-sandbox-drawio 0.3.0
File Size Uploaded
maf_sandbox_drawio-0.3.0.tar.gz 14.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for maf-sandbox-drawio 0.3.0
File Interpreter ABI Platform
maf_sandbox_drawio-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 29.7 kB

Release files / maf_sandbox_drawio-0.3.0.tar.gz

Download URL maf_sandbox_drawio-0.3.0.tar.gz
Size 14.0 kB
Tags Source
SHA-256 checksum
How to use checksums
43d9bd9d2f78daf32c61e8c76223747619b5accd6a25bc07bd13f62844324806
BLAKE2b-256 checksum
How to use checksums
9df02397da25b7aada792b86b98b83a80c6f21eaccd5138f95ea630b4e4e918a
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 21, 2026.

Transparency log

Release files / maf_sandbox_drawio-0.3.0-py3-none-any.whl

Download URL maf_sandbox_drawio-0.3.0-py3-none-any.whl
Size 15.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eb256508ff73eb553cf2510715b62e0146e64f9bc40c61e8211eeee4a57554a5
BLAKE2b-256 checksum
How to use checksums
f33ac580d4a300dc63c9529e9e46d7c2232989a2e0de191168fa938a7ec30da8
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 21, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.1

2 release files

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page