Is there a way to prevent players from joining my game?
Solution 1:
Cross posting from this answer
You can disable network play in the options. Press P (on PC) and set network play to "Off". If you do that, you are perfectly safe.
If you have network play enabled, then players can join your session via "Join random game". If a players joins your session, he is placed in a planetary system near you (or even in the same system). In the ingame chat, you will se the notification "[Player x] has joined your game", and if the player enters the same system as you, "[Player x] has entered the system".
via @Polygnome