Is it okay to share work submitted for undergraduate assessment online? I'm an undergraduate theoretical physics student in the UK nearing the end of my degree. Over the course of my studies, I've produced a lot of computational code and written reports that I think would add a lot to my portfolio. For this reason, I'd like to publish them on my personal website.

All the work was performed solo, but I usually followed a lab script. These were just a series of tasks to complete and a few useful hints, so there wasn't much to copy other than standard physical equations, but there may be an issue with the similarity between what I've done and what I was asked to do.

I'm also concerned about academic misconduct: It's likely that similar assignments are set every year, and I'm concerned that publishing my work will lead to accusations that I'm helping students in lower years cheat. Since I'm interested in an academic career, I don't want academic misconduct on my record and I don't want to get on the university's bad side.

Are there precedents of people getting in trouble for saying "Hey, look what I made at uni" online?
Although your intent is benign, you ought to consult this with your department, specifically the course instructor and the department head regarding this matter.  With their permission sought out, this would make a pretty good impact on your visibility.