Skip to main content

What You’ll Learn

  • How to upload a multi-file Python project into a sandbox to simulate a repository
  • How to run a test suite before and after a fix to demonstrate a regression cycle
  • How to apply a targeted code fix by reading, patching, and writing a file
  • How to show a simple diff of the change inside the sandbox

Prerequisites

  • Declaw running locally or in the cloud (see Deployment)
  • DECLAW_API_KEY and DECLAW_DOMAIN set in your environment
This example is available in Python. TypeScript support coming soon.

Code Walkthrough

1. The buggy repository

The simulated repository contains two modules and a test file. string_utils.py has a deliberate bug — the count_vowels function is missing 'u' from the vowel set:
The test file has cases that will fail due to the bug:

2. Upload and run tests before the fix

3. Apply the bug fix

The fix script reads the file, applies a targeted string replacement, and writes it back:

4. Show the diff

5. Run tests after the fix

Expected Output

Extending to Real Git Repositories

The example simulates a repository by uploading files. To work with a real git repository, install git first and then clone:
When cloning a public repository, set network={"allow_out": ["github.com"]} so the sandbox can reach GitHub but nothing else. For private repositories, pass a personal access token as an environment variable and restrict the allow-list to github.com only.