title: Advanced Sandbox: Transformation Engine description: Building a secure, high-performance data processing engine in an isolated sandbox. icon: material/inventory
Advanced Sandbox: Transformation Engine¶
This example features a Sandboxed plugin designed to handle massive data transformations using untrusted logic. It demonstrates how to push the limits of Xcore's isolation while maintaining strict control over system resources.
1. The Manifest (plugin.yaml)¶
We use the manifest to create a "digital cage" for the plugin, preventing it from consuming too much memory or performing illegal operations.
- Hard RSS memory ceiling.
- The plugin can write up to 100MB of temporary data.
- Kills any call taking > 5 seconds.
- Standard rate limiting to prevent DoS attacks from compromised plugins.
2. The Implementation (src/main.py)¶
A stateless transformation logic that utilizes local disk for buffering large payloads.
3. Advanced IPC Patterns¶
Calling from the Main App¶
When calling a sandboxed plugin from a FastAPI route, always handle potential resource violations gracefully.
4. Performance Tuning¶
Batching Calls¶
IPC communication has overhead. Instead of calling the sandbox 1,000 times for 1,000 items, pass a list of 1,000 items in a single call(). This reduces context switching between the main process and the sandbox worker.
Filesystem Buffering¶
If your payload is too large for JSON serialization (e.g., > 10MB), write the data to a shared volume in the plugin's data/ directory and pass the filename as the payload.
5. Troubleshooting Resource Limits¶
DiskQuotaExceeded
If the plugin writes more than max_disk_mb to data/, Xcore will block all further writes.
Fix: Implement a cleanup routine in your handle method or increase the quota.
Memory Ceiling (OOM)
If you see Exit Code 137 in the logs, the OS OOM killer terminated the sandbox.
Fix: Check for memory leaks or increase max_memory_mb.
See Also¶
- Security & Sandboxing
- Deep dive into the C++ AST scanner and resource enforcement.
- Middleware Pipeline
- Understand how the
RetryMiddlewarehandles sandbox crashes.