I don,t know if i understand your question. I don,t know your situation. So my reaction to your question can be totally wrong.
People can not come into your head if you don,t let them. What,s in your head is your own and what you will find inside your head is yourself.
If possible i try to avoid people i dislike. If i can not avoid them i may try to ignore them. I do not like conflict but sometimes a confrontation can not be avoided. Sometimes a confrontation is the best or only possible solution to problems you may have with people.
It all depends on the situation and the person.
In my own life i don,t have many people trying to get into my head. Maybe it,s because i do not give them a reason to want to get into my head. I do not feed them with energy.
What some people do is put energy into controlling you or getting into your head. If you do not respond all the energy they put into it, will not pay off and they will look for another victim. If they try to make you upset for example and you do not let yourself get upset they will stop putting energy into you.
some people will do things for you or give you stuff with the aim of getting something back from you, or to manipulate you (get into your head)
Let them do things for you, take what the offer you. However do not do or give something back in return. When you don,t give something back to them they will lose interest in you. They will think you are not a good investment for there energy. When you do this you,ll send a signal to nasty people, and they will start to ignore you. Eventually people will stop trying getting into your head because they will feel your energy and figure out you are not playing there stupid game.