Mine was like this, if not much much worse to be honest! My boyfriend, brother and I bore the scars to attest! I dreaded visitors, apologised for him constantly, locked myself in rooms but loved him deeply so I stuck with it 😂
I'd really give encourage you to give it time and patience. It's likely he is very young and needs to learn to play without teeth or claws. If it persists he could be overstimulated, stressed, bored, or territorial and there are great Jackson Galaxy videos if so. He is very young and it's great that he is affectionate the rest of the time! That would lead me to think this is play and maybe needs more stimulation.
If he is indoors only he needs A LOT of interaction. I remember finishing work (from home) when he was younger, absolutely bolloxed and having to play for the whole evening on and off, because that's when he would come to life. If I was beyond tired I was on the couch rolling up tiny balls of tinfoil and throwing them across the room for him to chase.
He did settle a lot after time went on. But the biggest difference was him being able to go outside when I moved home from my apartment, and just having more interest and space to explore.
He wouldn't have a clue how to cat outside so he only goes out on a harness throughout the day in the back garden but all the sniffing and bird watching really tires him out. Be prepared to put in a lot of work though as a harness is NEVER fully escape proof so they need to be really comfortable with it on before you even think about stepping outside. Our garden is impossible to cat proof but we make sure to leave the door open so he can bolt inside if he gets spooked (by wind usually). Catio is a great option, I'm planning on getting one so he can get a bit of fresh air when he wants but will likely still need to patrol the perimeter of the garden on the regular.
Sorry this is so long but he seems like a character, I hope you can figure it out. My cat sat on a lap that wasn't mine for the first time 2 weeks ago and we're still talking about it now, he's come so far and I'm glad we all gave it our best!