The same way that some mice and rats instinctively know to be terrified of snakes, despite having never encountered one in captivity before, or had the opportunity to learn to be afraid of one. Because snakes are not raised by their parents, much of what they do is entirely instinctive (like the scent or "movement signature" of one prey item being more appetizing than another).