Running authored Python workflows safely
Each step runs in a bubblewrap sandbox with no network or secrets, a pinned clock and seeded randomness. Accepted results replay; we say what is not yet proven.
Each step runs in a bubblewrap sandbox with no network or secrets, a pinned clock and seeded randomness. Accepted results replay; we say what is not yet proven.
Record each turn as a run, lease every attempt with a fenced heartbeat, keep agent state in Electric's durable streams, and never replay a tool call to recover.
Test AI like software: real cases, code checks for what must hold, a calibrated LLM judge for the rest, human audits, and a release gate on every change.
A recurring report. A slow review. A prototype that needs to work in the real world.
When an agent or an analyst writes Python for a recurring workflow in the Company Twin (a small, reviewed program that runs a repeatable piece of business work step by step), every step executes in its own bubblewrap sandbox with no network, no secrets and no writable filesystem, under hard caps on time, memory and payload size. We pin the clock, reject unseeded randomness, and store every accepted result so a replay reuses it instead of recomputing.
We're blunt about where it stands. A production-readiness audit on 25 October 2026 judged the engine not ready for unattended, production-critical business workflows, while finding the sandbox and secrets handling sound within their stated limits. Most of the work it called for has since landed; the final gate (a full product run with injected failures and a release transition) is still ahead of us. What follows is the contract the engine keeps today, and the evidence behind it.
Key takeaways
A finance team matching supplier invoices every morning doesn't want a model improvising the rules each day. It wants a procedure that produces the same answer on the same inputs, that someone can read in plain sight, and that can be tested against yesterday's documents before it touches today's. Models have a clear place inside that procedure (reading a messy PDF or judging a near match) without becoming the procedure itself.
So a workflow in the Twin is Python plus a manifest declaring the steps, the sources they read, the effects they can have and the trigger that kicks them off. The Twin's agent can draft one from a sentence, but what actually runs is the code, saved as an immutable version. Its human owner switches it on, never the agent that wrote it. That's the principle from skills, not prompts, extended to recurring work.
Every node runs as its own short-lived process, launched by the executor's sandbox role over a private socket. Bubblewrap starts the process with every namespace unshared, leaving it with no network, no visibility into other processes and no access to host files beyond a read-only system directory and a fresh /dev. Its environment is wiped clean so no credential can slip in through a variable, and neither the executor's socket nor any workspace is mounted.
| Limit | Value | How it's enforced |
|---|---|---|
| CPU time | 2 seconds | Kernel resource limit inside the sandbox |
| Wall time | 5 seconds | The parent kills the process |
| Address space | 256 MiB | Kernel resource limit |
| New processes, file writes | None | Resource limits set to zero |
| Input | 512 KiB | Refused before the sandbox starts |
| Output | 256 KiB | The parent stops reading and kills the process |
| The role as a whole | 1 CPU, 1 GiB, 128 processes, no network | Declared on the container that runs the sandbox |
The last row is a declaration in our runtime configuration. The audit pointed out that a declaration isn't a live-host check; verifying it on a real host is part of the remaining gate.
Before any code runs, the harness parses it without executing it. Imports are restricted to json, math, decimal, datetime, statistics and re. Private attributes and dunder names are refused, along with classes, async functions and globals. The top level can only hold functions, imports and docstrings, keeping step wiring in the manifest rather than hidden in decorators. The check returns the first broken rule with its line and step so the author can fix it before saving.
from decimal import Decimalfrom datetime import datetime def match(invoice, purchase_orders): """Pair an invoice with the open purchase order it settles, or say why not.""" candidates = [po for po in purchase_orders if po["supplier"] == invoice["supplier"] and po["status"] == "open"] for po in candidates: if abs(Decimal(po["amount"]) - Decimal(invoice["amount"])) <= Decimal("0.01"): return {"po": po["id"], "matched_at": datetime.now().isoformat()} return {"po": None, "reason": f"{len(candidates)} open orders, none within a penny"}That datetime.now() doesn't read the host clock; it returns the run's pinned evaluation time.
A replayed step should give back what it produced the first time. Python won't guarantee that out of the box, so the harness removes the usual sources of drift:
datetime is swapped for a version whose now, utcnow and today return the evaluation time pinned by the run. The inherited bounds (base-class objects that could still reach the real clock) are replaced too. Reading the clock without a pinned time raises an error.statistics.NormalDist().samples(3) and got different answers. Sampling now demands an explicit seed and fails without one, while deterministic statistical functions such as cdf and inv_cdf stay open.Each run also stamps a compatibility identity for the runtime that started it. A step from an older run resumes only on a runtime declaring the same identity; anything else stops visibly before causing an effect and waits for a reviewed new activation. There's no quiet fallback running old state on new code.
It's tempting to call a workflow engine exactly-once. Ours isn't, and we don't claim it is. A step's Python, source read or model call runs first and is then accepted: its output is persisted against the node, stage, effect key and a SHA-256 hash of the canonical request before any later step can act. If the process dies before acceptance, the step can run again. Once accepted, that result is immutable and any replay with the same request reuses it; a replay presenting a different request under the same identity fails.
| Boundary | What we promise | What we don't |
|---|---|---|
| Python, reads and model calls | An accepted result never changes and is reused on replay | That a step runs only once before acceptance, or that a model gives the same answer twice |
| Worker lease | A late worker can't commit ordinary effects; owner, attempt and expiry are checked | That an orphaned item completes automatically |
| Local database writes | The write, its receipt and the authority check share one transaction; reusing an identity with other input fails | One execution per business document across separate activations |
| External creates (a draft bill, say) | One create attempt; uncertain outcomes are reconciled by a stable business key and a verified readback | That a lost response can be resolved without a readback |
| Source reads | Current access is checked at every start, read and memo retrieval | That every intermediate upstream revision between two polls is seen |
| Secrets | Provider credentials stay in host adapters; Python receives only declared inputs | That source data itself contains nothing sensitive |
Retries follow the same discipline. Only typed transient failures (429, 502, 503 or 504) on pure reads or receipt-carrying commands get retried, up to five attempts with backoff from a quarter of a second to four seconds. Permanent errors are surfaced immediately instead of looping through retries that will never work.
Workflows read through declared sources: a connected system, a channel's records, or the organisation's graph. Each source rechecks current grants at run start, on every read and whenever a memoised result is fetched, so access revoked yesterday won't slip through from a cache today. A graph source uses the run's current warehouse grant, renewed as it nears expiry, and every answer carries the engine's certificate (described in certified answers from a Rust graph engine). It's the rule from context is a security boundary: policy decides what a step can see, never the code asking for it.
The 25 October audit traced the engine end to end through three independent read-only passes plus isolated tests. Its bar was unforgiving: an area passes only with code evidence and zero blocking defects, and the overall verdict stays "not ready" while any gap remains. It turned up ten issues and ranked nine slices of work.
| What it found | What we changed | Status, November 2026 |
|---|---|---|
| Replacing a workflow's active version could strand unfinished work | Every pending and running item is accounted for exactly once at hand-off | Landed |
| A pause or replacement could strand an external write with an unknown outcome | Uncertain postings keep a receipt or an explicit block, with one create attempt | Landed |
| An accepted upload had no recovery if dispatch failed | Dispatch intent is kept in the intake transaction | Landed |
| Temporary failures could become permanent manual work | Typed retry eligibility, and scheduler phases isolated from each other | Landed |
| Older failures could fall out of history and alert no one | Paginated history and one actionable notice to the owner | Landed |
| Replay had no release compatibility contract; sampling wasn't deterministic | A compatibility identity, refusal before effects, seeded sampling | Landed |
| A capacity cap wasn't fairness between tenants | Tenant-aware sandbox admission and claim shares, measured under noisy load | Landed |
| One response could hold totals and rows that disagreed | Rows and totals come from one observation | Landed |
| No full product run with crashes, revocation and a release transition | A disposable, exact-commit acceptance run with injected failures | Outstanding |
Two of those fixes are worth looking at closely. For fairness, we ran 100 rounds of 32 noisy jobs from one tenant, one quiet job from another and one cancelled waiter through a single sandbox slot: in every round the quiet job waited behind none of the noisy ones. For consistency, the audit had caught a single response whose two rows summed to 30 while its totals reported 10, simply by committing a row between two statements; rows and totals now come from one observation. When those slices landed, the integration suite ran 309 PostgreSQL and 96 sandbox and runtime readiness tests with none skipped.
The remaining slice is the one that actually earns unattended trust: an isolated stack on the exact commit, driven through the real product surfaces, with crashes injected before and after each durable step, a source revoked mid-run, a duplicate upload, and an upgrade and rollback while work is in flight. Until that passes, we don't call the engine ready for unattended, production-critical work, and we wouldn't ask you to.
Most clients we work with have a handful of recurring jobs (matching, chasing, reconciling, reporting) that people still do by hand because the last automation broke too quietly to trust. We'd start with one, and qualify it the same way we qualify our own engine.
Qualifying an automated workflow
For finance teams, our earlier piece on agentic workflows on Xero shows the kind of work this is built for, and evaluating AI systems at scale covers testing the model calls sitting inside a workflow.
We turn recurring operational work into reviewed, sandboxed code with an explicit contract, and tell you plainly what is and isn't proven yet. Read how we qualify automations →