Agent Series (20): Harness in Production — From Single File to Reusable Package A developer refactored a 900-line demonstration file into a reusable Python package called 'harness', which includes modules for action registration, permission budgeting, input sanitization, audit logging, and rollback coordination. The package introduces a refund() method to correct a budget accounting flaw and supports integration as standalone Python or as a LangGraph graph embedding. Article 19 used a 900-line harness full demo.py to demonstrate eight defense layers. That file is good for explaining concepts, but not for reuse — all layers are coupled together, nothing can be tested in isolation, and nothing can be imported by another project. A production-grade Agent project needs something you can actually import : harness/ ├── init .py Public API exports ├── registry.py Layer 2: ActionRegistry + PermissionLevel ├── budget.py Layer 3: PermissionBudget with refund ├── sandbox.py Layer 4: sanitise input + sandboxed eval ├── audit.py Layer 6: ImmutableAuditLog hash-chained ├── rollback.py Layer 7: RollbackCoordinator └── harness.py Unified entry point: AgentHarness This article starts with package design, covers three key API decisions, and finishes with two integration styles: standalone Python and LangGraph graph embedding. class PermissionLevel Enum : READ = 1 WRITE = 2 ADMIN = 3 IRREVERSIBLE = 4 @dataclass class RegisteredAction: name: str level: PermissionLevel budget cost: int description: "str" handler: Any Callable or BaseTool class ActionRegistry: def register self, action: RegisteredAction - None: ... def get self, name: str - RegisteredAction: ... not found → PermissionError def is allowed self, name: str - bool: ... def names self - list str : ... get rather than getitem : raises a consistent PermissionError , without leaking the internal KeyError detail. php class PermissionBudget: def spend self, action name: str, cost: int - None: if self.remaining < cost: raise BudgetExhaustedError ... self.remaining -= cost def refund self, action name: str, cost: int - None: self.remaining = min self.total, self.remaining + cost The new refund method fixes a design flaw from Article 19: budget was deducted before approval, and never returned on rejection. The production package corrects this — when an IRREVERSIBLE action is intercepted, harness.py proactively calls refund to keep budget accounting accurate. INJECTION PATTERN = re.compile r" ignore. previous|above|prior |forget. instruction|" r"you are now|act as|jailbreak|bypass|" r"override. system|system. override|" both word orders covered r"