Skip to main content
Document parsers process complex, attacker-controlled file formats. This example installs LibreOffice and Poppler once, snapshots the toolchain, and performs each conversion in a fresh worker with networking disabled.

Convert a document

1

Prepare the converter

Create one script to prepare the reusable toolchain:
prepare-office.sh
Create the workload script that each worker will run:
convert-document.sh
Install both scripts in the guest, then run the preparation script as the entrypoint:
Capture the prepared toolchain:
Verify the snapshot before using it:
Bookworm currently downloads roughly 130 MB and adds about 440 MB to the guest for this toolchain; package updates can change those numbers. The snapshot lets later workers skip that installation.
2

Start an offline worker

The example accepts a Word document named input.docx:
Copy the document into the running worker:
Make the copied input read-only:
3

Convert the document

Run the bounded conversion as the unprivileged converter user:
The worker boots before the document is copied because rootfs patches cannot be combined with --from-snapshot. The root-owned input directory prevents the unprivileged converter from replacing the document, while its home directory and /out hold the only workload-writable state. The untrusted conversion command sets its own process, file-descriptor, and per-file limits.
4

Export the PDF

Prepare a fresh artifact directory on the host:
Stop the worker before exporting its output:
Copy out only the generated artifacts:
Validate both exported files:
Stopping the worker prevents artifact races. The fresh private directory and checks require two nonempty regular files no larger than the conversion command’s 512 MiB per-file limit.
5

Clean up

Remove the prepared sandbox and worker:
Remove the reusable toolchain snapshot:
The checked output.pdf and preview.png remain in the artifact directory configured above.
A VM boundary reduces host exposure but does not make every document safe to publish or trust. Enforce input and output size limits before boot, cap concurrent conversions, reject unexpected file types, and scan retained artifacts according to your threat model.