Harness Engineering for Legacy Code: A New Approach to AI-Driven Modernization
An AI agent can write perfectly valid code and still make a completely wrong change.
The problem is not necessarily in the code itself. It can be hidden business logic, an undocumented dependency, or a rule that exists only because the system has worked that way for 15 years.
As AI becomes more capable and autonomous, its potential value and the consequences of getting it wrong also increase.
- A 2025 study on security risks detected security vulnerabilities in AI-generated patches, associated mainly with processes giving AI more autonomy.
- A 2026 study of AI coding agents adoption in open-source repositories revealed that the agents significantly increased development velocity, while introducing persistent quality problems.
- 69% of the frequent users of AI coding tools said AI-generated code caused deployment problems at least half the time.
For legacy systems with tightly coupled components, undocumented dependencies, implicit business rules, and tribal knowledge, those risks are even higher.
This is where harness engineering comes in, building on prompt and context engineering and expanding them to a broader environment for AI operation.
This article explores how harness engineering treats legacy code and how it can enhance AI-driven modernization by adding capacity, predictability, and practical value.
What Is Harness Engineering?
An AI harness is the system of inputs built around an AI agent. It is designed to help an agent fulfill engineering tasks in a controlled and repeatable way.
A software harness doesn’t just give the model an instruction and access to a codebase. It determines what the agent can see, what it can do, which tools it can use, how its work is checked, and when a human needs to get involved.
Harness engineering includes relevant code and documentation, tools for analysis and development, testing and validation, access controls, guardrails, and human oversight.
Harness engineering vs. prompt and context engineering
- Prompt engineering is the most direct way to guide an intelligent model. It focuses on what we ask AI to do and what we expect in return. For example, a prompt might ask an agent to convert a specific COBOL procedure to Java while preserving its existing behavior.
- Context engineering determines what information the model needs to perform that task correctly. Apart from giving the agent a prompt, we provide the relevant code, dependencies, database structures, documentation, test results, or other relevant information.
- Harness engineering operates at a broader level. It defines the environment in which the agent works. Specifically, it combines the prompt and context, and connects them with tools, permissions, execution environments, testing, validation, and human control.
Therefore, these three operate together, while a harness shapes the foundation for more powerful and comprehensive results. It enables agents to improve code quality, but most importantly, AI harness engineering creates the conditions in which an AI agent can safely perform meaningful engineering tasks.
Why Legacy Code Needs More Than an AI Model
AI models have proven to be very good at reading and generating code. But legacy modernization usually includes not only coding.
The real challenge lies in understanding what the system actually does and what must not change.
Complex dependencies
Legacy applications may contain tightly coupled components, shared databases, old APIs, batch jobs, and integrations that have tangled interdependencies. Changing one module can cause undesired effects on several others.
“When we work with legacy systems, the hardest part is often figuring out what else depends on that code,” comments Igor Omelianchuk
Missing or outdated documentation
Existing architecture diagrams, API descriptions, and technical documentation may not be fully relevant. If an AI agent works only with available documentation, it can make improper decisions based on an incomplete picture.
Hidden business logic
Legacy systems have most likely undergone numerous fixes and workarounds, which eventually turned the code into a repository of business rules. Some of them were simply built into the application without any documental traces. Removing or changing them without understanding their purpose can lead to breaks in data flows and changes in critical processes.
Insufficient test coverage
Many legacy applications lack automated tests. This hampers the work of an AI agent, since it cannot determine whether a modernization change preserves existing behavior. Here, tests act as an additional source of knowledge about what the system is supposed to do.
Risks of automated changes
As AI agents become more independent, their wrong assumptions may have a larger potential impact.
Andrew Lychuk explains: “We want AI to help us move faster. But if we give it poor inputs, it might only make the wrong changes faster.”
This is why a powerful AI model is only part of legacy modernization success. The other part includes the right context, analysis tools, validation mechanisms, guardrails, and, necessarily, human involvement at critical stages. This combination shapes a proper harness.
Moreover, a strong software harness is sometimes even more important than the model’s capacity.
Only harness engineering allowed LangChain to improve its coding agent from 52.8% to 66.5% on Terminal Bench 2.0, without changing the underlying model (gpt-5.2-codex). The changes to the surrounding harness included better system instructions, context injection, tool use, middleware for detecting problematic loops, and stronger self-verification.
How Harness Engineering Works with Legacy Systems
A legacy-code harness is not a distinct tool that we just install beside an AI model. It is a controlled process that determines a safe agent’s behavior. In practice, we surround the model with several layers.
How AI Gets Access to Code and Documentation
We fully manage the way an agent interacts with the legacy repository, without letting it search freely. The harness connects an agent to source code, architecture diagrams, API specifications, database schemas, tickets, technical documentation, and version history. Retrieval mechanisms then provide the parts relevant to the task. It’s possible to limit access by repository, service, environment, or operation.
As Andrew highlights, “We don’t need to give the agent the whole legacy system. A harness engineer should set the design that provides the right information at the right moment.”
This retrieval-based approach is what legacy systems particularly benefit from, since the useful context is often scattered across different places.
What tools does the agent use?
Apart from a text interface, the model needs different tools depending on the modernization task. The harness can connect it to code search and analysis tools, compilers, IDEs, Git repositories, database tools, dependency scanners, CI/CD pipelines, and migration utilities.
Let’s take COBOL to Java migration. An agent explores the COBOL program, traces its database calls, analyzes dependencies, generates the Java equivalent, and uses the compiler and automated tests to check the result.
How does AI validate its changes?
Treating “the code compiles” as proof that the modernization worked would be a mistake. The harness orchestrates automated unit and integration tests, static analysis, security checks, regression tests, and comparison tests to verify the legacy implementation.
We also identify areas where test coverage is weak and use AI to generate tests around existing behavior before proceeding to larger changes.
Where does a human need to interfere?
Every decision that requires business or architectural judgment is supervised by human engineers. They review the most significant changes, resolve ambiguous requirements, approve migration strategies, and analyze failures that automated checks cannot explain.
Igor underscores the engineering role: “In neither case are we trying to remove engineers from the process. We rather redirect their effort from repetitive code changes to architecture, business logic, and difficult decisions.”
Key components of a legacy code harness
Practical hardness engineering involves a combination of context, tools, checks, and human controls. This environment grants an AI agent everything it needs to work on legacy code without giving it unlimited freedom.
Context and documentation
The AI agent needs access to the information that explains how the system works. It includes source code, architecture diagrams, database schemas, API specifications, tickets, technical documentation, and version history.
The important task for a harness engineer is to provide relevant data instead of loading the entire codebase into context. Thus, the harness would retrieve the code, dependencies, and documentation related to the task.
Code analysis tools
Dedicated analysis tools can reveal relationships in legacy code that are difficult to extract from individual files. Static analyzers, dependency scanners, code search, call-graph tools, compilers, and database analysis tools can be used to help the agent understand which components a planned change may affect.
Testing and validation
Tests enable an AI agent to self-check its work. The software harness can initiate extensive testing, including unit, integration, regression, and characterization tests, as well as static analysis and security checks. For legacy applications with poor test coverage, AI can generate tests that explore existing behavior.
Guardrails
Guardrails set the boundaries for what the agent can do.
For example, an agent may be allowed to modify code in a development branch but not implement it to production. It may also require approval before critical steps, such as changing database schemas or security-related code.
Andrew adds a practical angle: “It’s not enough to tell an agent what not to do. A guardrail should make the safe path easier to follow than the risky one.”
Setting proper guardrails is particularly important for legacy systems, where one incorrect change can cause adverse effects to several tightly connected elements.
Human review
Core decisions should remain with experienced engineers. Human review is indispensable when requirements are ambiguous, business logic is undocumented, or changes affect critical system parts.
“AI can confirm whether the code passes the given checks. Only an experienced engineer can decide whether those checks are enough,” comments Igor.
How to Build a Harness for Legacy Code Modernization
A practical AI harness engineering process includes 6 fundamental steps:
Analyze → Build context → Connect tools → Modernize → Test → Validate
Analyze
Map the application before giving AI modernization any tasks. Identify primary components, dependencies, databases, external integrations, critical processes, and areas with limited test coverage. This analysis helps determine where it is safe to apply AI and where you need to attract humans.
Igor Omelianchuk warns: “We can’t automate the system we don’t understand. Otherwise we’ll have no idea of what this change might break.”
Build context
Unify the information the agent needs, including relevant source code, architecture documentation, database schemas, API definitions, tickets, test cases, and version history. A harness engineer should organize it in a way that an agent can access context relevant to a specific task, not receive the entire system at once.
Connect tools
Be careful to grant the agent controlled access to the tools the job requires. The tools may comprise code search, static analysis, dependency mapping, compilers, Git, databases, testing frameworks, and CI/CD pipelines. Set permissions based on the agent’s role and the risk of the specific operation.
Modernize
After the environment is completed, the agent can start making changes. It’s practical to split large modernization projects into smaller tasks that are easier to review. For instance, an individual task may include converting one module, replacing one dependency, or refactoring one service.
Test
Arrange the legacy code harness in a way that it runs the relevant tests and technical checks after each change. Compilation, unit and integration tests, regression testing, static analysis, and security checks can detect issues before they impact the system.
Validate
Avoid the temptation to perceive the modernization as correct directly after passing automated tests. Engineers should be involved at this stage, reviewing significant changes, comparing behavior with the original system, and confirming that business requirements are met.
Andrew Lychuk illustrates: “AI makes a change, we test it, and an engineer checks the result. Only after that do we move to the next step. With each iteration, AI and the team have more information to work with.”
The benefit of the entire cycle lies in its continuity and the opportunity to gradually increase the scope of AI involvement, as we become more confident in the harness.
Harness Engineering Use Cases in Legacy Modernization
We can fully realize the value of AI harness engineering when it’s applied to actual modernization tasks.
COBOL to Java conversion
When transferring outdated COBOL to Java, a software harness can give an AI agent access to COBOL source code, copybooks, JCL, database schemas, business documentation, and dependency information before it generates Java code. Then, it can compile the result, run characterization and regression tests, and compare the new arrangement with the existing system.
It’s beneficial with legacy COBOL, when business logic is dispersed across programs and supporting components.
Mainframe modernization
Mainframe modernization often requires much more than converting one programming language.
The role of the legacy code harness here can include assistance in mapping batch jobs, datasets, transaction flows, integrations, and dependencies. AI can efficiently analyze these relationships and fulfill tasks, such as adding APIs, splitting large processes into smaller parts, or planning the migration.
Engineers remain responsible for key architecture decisions.
Legacy Java/.NET modernization
For older Java and .NET applications, a careful analysis and gradual modernization are paramount.
A harness can connect AI to static analysis, dependency scanners, test suites, and version control. This way, the agent becomes able to identify outdated libraries, tightly coupled components, and refactoring opportunities. Changes then can be performed in small, testable phases without risky rewrites.
Database migration
Database migrations need a particularly cautious approach.
Application behavior often depends on schemas, stored procedures, queries, and undocumented data relationships. A harness helps to understand these tangled systems by providing access to schema analysis, SQL conversion tools, data-validation scripts, and migration testing environments.
AI can speed up repetitive conversion work, and automated checks verify results against the source database.
Automated documentation and testing
Sometimes the safest first step in modernization is to understand and document the existing system before changing its code.
AI can analyze legacy applications and create documentation, dependency maps, API descriptions, and characterization tests. This is a significant part of future transformation, as it shapes the required context and reduces reliance on knowledge held by a few experienced engineers.
Igor highlights the importance of proper preparation: “For us, making a legacy system more understandable is one of the strongest AI use cases. Better documentation and test coverage grant a much safer start.”
The Future of AI-Driven Legacy Modernization
The next stage is about creating a controlled environment where AI can maximize its capacity in legacy software modernization.
AI does not replace legacy engineers
AI agents excel in code analysis, tracing dependencies, and running repetitive tests much faster than a human. But they cannot replace the engineer who understands why the system behaves that way, which business rules are critical, or which architectural compromises are safe.
Andrew summarizes: “AI doesn’t know the business and the system’s history necessary to make strategic engineering decisions.”
Harness makes AI safer to use
An appropriately designed software harness guides the AI effectively.
While giving access to the right code, documentation, and tools, it also puts clear boundaries around what an agent can change. Automated tests, validation, permissions, version control, and human review create feedback loops that spot issues before they reach production.
This is controlled automation that eliminates excessive risk.
From coding assistants to managed AI agents
The role of AI gradually expands. We are moving from AI tools that generate individual functions to comprehensive, managed AI agents that can deal with larger modernization workflows. They can analyze a legacy component, trace its dependencies, propose a change, implement it, test, evaluate the results, and direct uncertain decisions to an engineer.
This evolution doesn’t imply a shift from humans to AI.
This is a transition from AI that generates code to AI that participates in an engineered process.
In legacy modernization, the goal is not to let AI change more code on its own, but rather to build an effective environment where it can safely perform routine tasks, while engineers control architecture, business logic, and risk.
The real productivity gains lie in giving human experts the most capable tool they’ve ever had.
If you’d like to engage AI to work on your legacy system, let us analyze your software, identify modernization opportunities and risks, and build a safe harness that delivers real modernization value.