in a group is best, but costa rica is generally very safe, especially outside of the cities. if you dont know where youre going, downtown san jose can be sketchy, downtown limon can be sketchy, Jaco, a very touristy beach town that is more about partying, can be sketchy. try not to be too alone like on a beach, stuff like that, but in general you wont have issues. the sun rises early and sets early in costa rica, and generally its good to follow that vibe, early rise and early sleep. smaller towns and rural is generally very safe. people are so nice. and youll meet people at hostels or whatever, depending on where youre staying.
to summarize, dont hang out in downtowns of bigger cities, especially at night, generally limit being alone at night and limit being alone on beaches.
if you stay in san jose, lets say for one night because of traveling out of that airport the next day, i would recommend staying in an area called escazu, which is very modern with good food and coffee shops. there are some hotels near the airport i could recommend too, but it depends on budget and what youre looking for.