Who Owns the Code I Write (Graduate Student)?
As indicated, this is a legal question and  not an academic one, however I do get asked this frequently by students.

Intellectual property questions are never simple. When you do work at a university, the idea that created the work may have come from a member of the academic staff. Ideas and techniques that are incorporated in the work come from classes created by other academic staff. Some of their ideas come from their education and books and papers they used. The university (their current employer) and perhaps some past employers may have contributed to that knowledge.

Then the student creates some artefact from that. Does the student wholly own everything intellectual in that artefact? Probably not, unless there is an agreement that says they do.

Without any agreement it would be for the courts to decide who owns what fraction of the intellectual property. Normally no one bothers, but when it is a valuable idea or artefact then the lawyers will follow.

There can be no simple answer to this question.