There is a hierarchy of complexity in evolution, with molecules cooperating to form cells, bacterial cells cooperating to form eukaryotes, cells cooperating to form animals and organs, and animals cooperating to form societies.
Altruism seems contrary to the principles of evolution since survival of self and progeny trumps everything else. Why would those first primitive molecules that could self-reproduce, however imperfectly, sometimes sacrifice themselves to help produce others molecules? Nonetheless, that's exactly what happens in every living cell. Of course we know why this works - because this sacrifice ends up producing more molecules like themselves, virtual if not precisely actual copies. What is hard, though, is seeing how the cooperation could develop in the first place.
We know these altruistic steps seem hard. It took a couple of billion years for eukaryotes to develop from bacteria and another billion or so for the first animals and plants. It would seem that that first step would have been the hardest, for molecules to learn to cooperate to make cells, but it does seem to have been relatively quick, as the first bacteria emerged shortly after the planet became capable of supporting life.
E O Wilson and others have identified what they consider a central principle of the development of eusocial animal societies, like termites, ants, naked mole rats and people, the formation of the defensible nest. A similar principle should apply at lower levels of organization - the animal or plant, the organ, the eukaryotic cell, and the bacterial cell can each be seen as fortified nests of a sort. It seems that something like cell membranes can form easily and naturally if conditions are right. Inside we likely have the first fortified "nests" in which molecules can mix, cooperate, and learn to practice molecular altruism.