Enhancing Code Generation with Real-Time Execution in Amazon Q Developer

January 31, 2025 By Mark Otto Off

As AI continues to drive rapid innovation in software development, a reliable runtime environment for real-time testing is essential to promote high-quality code generation. Developers often face delays in feature delivery as they spend significant time debugging and iterating on AI-generated code to verify it meets project requirements. Previously, the Amazon Q Developer development agent focused on code generation. With its latest update, the agent can now build and test code in real time, validating changes before a developer’s review. This new capability directly addresses community feedback regarding code recommendation quality, detecting errors, keeping generated code in sync with the project’s current state, and accelerating the development process by streamlining both code generation and testing workflows.

With natural language input and project-specific context, the Amazon Q Developer agent is designed to assist in implementing complex multi-file features, bug fixes, and test suites. For example, a developer can request Amazon Q Developer agent to add a checkout feature to an e-commerce application. The agent then analyzes the existing codebase, makes all necessary code changes and tests within minutes, including running any unit tests and building the code to verify the code is ready for review. This approach significantly improves development efficiency and reduces errors. To use the Amazon Q Developer agent in your IDE, simply install the Amazon Q extension and use the /dev command in the chat window to initiate requests.

Once the /dev command is entered in the IDE, the agent packages the project and securely uploads it to Amazon Q, initiating project-specific code generation. The Amazon Q Developer agent not only focuses on code generation, but also maintains a real-time connection with the developer, providing updates throughout the process and delivering a polished patch or implementation for the requested feature.

This real-time execution is powered by a Devfile, which defines the development environment and commands the agent can use. If a project doesn’t already have a Devfile, Amazon Q Developer will prompt users to create one after their first run of /dev. Without a Devfile, the agent will develop solutions without the additional feedback provided by running builds or unit tests, limiting developers’ ability to receive real-time feedback during the development process.

Core enhancements in the latest Amazon Q Developer update

  • Customizable Commands: Developers can specify commands in a Devfile to control which commands the AI agent runs, reducing unnecessary steps and improving accuracy.
  • Flexible Environment Setup: Developers can use custom Docker images preloaded with dependencies for faster startup times, providing the agent has all necessary tools.
  • Sandboxed Security: Amazon Q Developer secures the execution within isolated environments, offering comprehensive logging and robust permission controls to safeguard any changes made.

With this setup, Amazon Q Developer can execute tests, apply migrations, and run installation commands directly within a sandbox, providing feedback to the agent for iterative improvements.

Security and isolation

Given the security-sensitive nature of executing AI-generated code, the Amazon Q Developer agent introduces several safeguards:

Environment Isolation: Commands are executed within an isolated, managed sandbox environment configured without credentials to access non-public internet resources, ensuring that only authorized actions are performed securely.
Devfile driven: This feature requires a Devfile, and the Devfile configuration allows developers to control which commands the agent uses during the development process.

Getting started with the Amazon Q Developer agent

To get started, you need to have an AWS Builder ID or be part of an organization with an AWS IAM Identity Center instance that allows you to use Amazon Q. To use Amazon Q Developer agent for software development in Visual Studio Code, start by installing the Amazon Q extension. Find the latest version of the extension on the Amazon Q Developer page. The extension is also available for JetBrains, Eclipse (Preview), and Visual Studio IDEs. For a detailed list of supported IDEs and the features available in each, refer to the Amazon Q Developer documentation.

Amazon_Q_Developer_AI_Assistant

After authenticating, you can invoke the feature development agent by entering /dev in Amazon Q’s chat window.

Amazon_Q_Developer_AI_Assistant_Dev

Amazon Q Developer leverages an isolated sandbox environment to securely execute code generated by the Amazon Q Developer agent. This keeps the generated code running safely and in sync with the original codebase. Here’s a breakdown of how the process works:

  • Initiating the Execution Environment: Upon receiving a prompt, the Amazon Q Developer agent initiates a sandbox instance or the customer specified docker container, which serves as a sandbox environment for code execution.
  • Executing Commands Safely: The Amazon Q Developer agent safely executes a curated list of shell commands based on customer specifications in a Devfile. Devfiles model the configuration and dependencies of a development environment, enabling consistent environment reproduction and reducing manual setup effort. Developers can define custom commands within the Devfile to control actions in the sandbox, such as installing dependencies, running tests, applying database migrations, or executing build scripts, improving accuracy and efficiency.
  • Feedback and Sync: After each command runs, changes to the code are tracked and the AI agent is provided with real-time feedback and enabling iterative improvements.

Use case example 1: Adding a test suite to an existing project

Let’s say you want to enhance the functionality of a React-based application, like the example react-solitaire from GitHub. As you add new features, it’s crucial to ensure that existing functionality remains intact and doesn’t break with each update. To achieve this, you aim to create a test suite for continuous testing and iteration of your code.

To illustrate this, we’ll clone the React project from GitHub and add a Devfile to define the environment and dependencies. The Devfile configures the sandbox to execute and test code changes safely, allowing updates to be made without affecting the working features.

Amazon_Q_Developer_AI_Assistant_Devfile

Once the repository is cloned, place the Devfile in the root of the project folder. Then, open the Amazon Q IDE in Visual Studio Code and enter the /dev command to prompt the creation of a tailored test suite for the repository.

Amazon_Q_Developer_AI_Assistant_Feature_Development

The Amazon Q Developer agent then begins analyzing your codebase, sharing real-time updates on the changes it’s making and files it’s working with. The agent starts by exploring the project structure, planning the necessary updates, and generating the test suite.

Amazon_Q_Developer_AI_Assistant_Summary_of_Changes

After a few steps, the agent has created the required test suites.

Amazon_Q_Developer_AI_Assistant_Chat

Then, the agent executes the tests, continuously monitoring for any failures. When an issue is detected, it doesn’t stop immediately—it actively improves the code based on feedback from the tests, repeating this process up to three times. If the issue remains unresolved after three iterations, the agent aborts the process. However, if the issue is fixed, it moves on to the next step. For instance, when the agent identified that Enzyme didn’t support React 18, it addressed the issue and re-ran the tests in the testing environment.

Amazon_Q_Developer_AI_Assistant_QDev

Once the issue was resolved, the agent moved on to the next step, displaying all the changes and files it has modified in the sandbox and asks if you want to accept the changes or provide feedback.

Amazon_Q_Developer_AI_Assistant_Accept_Code

If you are satisfied with the output, you can accept the changes or you can provide feedback to the agent and request that it regenerates the code again.

Use case example 2: Re-run tests when a feature is updated

After successfully creating and executing the tests, the agent was prompted to add a new feature that displays the name of the game in the UI. The agent analyzed the repository, identified the files requiring updates, and determined the precise locations to implement the changes.

Amazon_Q_Developer_AI_Assistant_Summary_of_Changes

After applying the updates, the agent executes tests to validate the new feature, promoting seamless integration with the existing codebase and maintaining reliability throughout the development process.

Amazon_Q_Developer_AI_Assistant_NPM_Install

Upon accepting the changes made by the agent, the index.html file is updated to include the text ‘Solitaire,’ integrating the new content smoothly into the existing project.

Amazon_Q_Developer_AI_Assistant_Solitaire

Conclusion

The launch of this new update in Amazon Q Developer marks a significant advancement in AI-driven development, transforming the Amazon Q Developer agent from a tool focused on code generation to a robust execution engine. By enabling developers to validate and test code changes in real-time, this enhancement can improve the accuracy and reliability of AI-generated files and fixes.

With flexible options to use AWS managed sandbox or bring custom environments, developers gain control to maximize the Amazon Q Developer agent’s potential. The new execution capability empowers teams to iterate faster, make informed adjustments, and leverage a secure, intelligent platform tailored to their needs.

You can try it out today by updating or installing your Amazon Q Developer extension on VS Code or JetBrains.