How do I configure Cursor to automatically detect and fix Python errors when running a script from the terminal?

I’m using Cursor IDE and running a Python scripts main.py from the integrated terminal to test if my code works. How do I configure Cursor to automatically detect and fix Python errors from terminal output?

Workflow: I ask an agent to run a query by modifying my code, and then once it it done, I want an agent to run python main.py in the terminal integrated in Cursor and automatically detect and fix Python errors if any that can be seen terminal output.

Instead of trying to parse terminal output and auto-fix errors, you’ll probably get more reliable rsults with unit tests.

As part of your planning mode, ask the agent to include pytest for testing your scripts. This is more structured, and it gives the model a clear signal about what’s broken

Great suggestion from @Chris_C ! Using pytest is the ideal approach - structured test output gives the Agent much clearer signals about what’s broken and where.

If you don’t have tests set up yet, the workflow you described still works well - just ask the Agent to run python main.py and fix any errors, and it will read the terminal output and iterate automatically.

To streamline this:
Create a Project Rule (in .cursor/rules/) with alwaysApply: true instructing the Agent to always run your script after code changes and fix any errors - that way you won’t need to repeat the instruction each time

See the Terminal docs for more on auto-run modes and sandbox settings.