The prisoner's dilemma does not have same result if some of the details are different. If the prisoners (or countries) can talk with each other and plan for the future, they might both decide to cooperate (not betray) because they hope that will make the other country help them in the future. In game theory, this is called a "repeated game." If the players are altruistic (if they care about each other), they might be okay with going to jail so they can help the other person.