The Stats Engine executes statistical queries on tabular data. All model-generated code runs inside a secure Docker sandbox — in-process execution paths (Wasm and restricted Python) are disabled.
Features
- Docker sandbox — Full container isolation for all statistical code execution
- Fail-closed execution — If Docker is unavailable, verification is blocked rather than falling back to in-process execution
- Pre-execution security validation — AST-based code analysis before Docker execution
- Live Docker health checks — The executor verifies Docker availability on each request, not just at startup
Prerequisites
The Stats Engine requires a running Docker daemon. Without Docker, all statistical verification requests return HTTP 503. See the deployment guide for setup instructions.
Usage
import pandas as pd
from qwed_sdk import QWEDClient
client = QWEDClient(api_key="qwed_...")
# Create sample data
df = pd.DataFrame({
"product": ["A", "B", "C"],
"sales": [100, 200, 150]
})
# Verify statistical claim
result = client.verify_stats(
query="What is the average sales?",
data=df
)
print(result.answer) # 150.0
Execution model
All generated statistical code is executed inside a Docker container with enforced memory and CPU limits. The engine does not fall back to in-process execution under any circumstances.
| Scenario | Behavior |
|---|
| Docker running | Code executes in an isolated container |
| Docker unavailable at startup | Requests return 503 Service Temporarily Unavailable |
| Docker becomes unavailable mid-operation | Request is blocked and returns 503 |
| Code fails AST security check | Request returns 403 Verification Blocked by Security Policy |
| Code generation fails | Request returns Internal verification error |
Previous versions of QWED offered Wasm and restricted Python fallbacks when Docker was unavailable. These fallback paths have been removed. You must have a running Docker daemon for statistical verification to work.
Error handling
When the Stats Engine encounters an internal failure — such as a code generation or translation error — it returns a generic "Internal verification error" message. Sensitive details like file paths, credentials, or stack traces are never included in the API response.
If you receive this error, check the server-side logs for diagnostic details. The engine logs the exception type for debugging while keeping the client response opaque.
Direct operations
For simple operations, bypass code generation:
result = client.compute_statistics(
data=df,
column="sales",
operation="mean" # mean, median, std, var, sum, count, min, max
)