Ancient Egypt
Yes, even the ancient peoples, Egyptians including, they had the problem of avoiding sexually transmitted diseases and unwanted pregnancies, and having neither too much knowledge about it, nor many means at their disposal, they managed as they could, putting all their inventiveness to the test.
The Egyptians, you won't believe it, used condoms, or rather a facsimile , which also performed the function of protecting the private parts from dangerous external contamination, always lurking in a country with a torrid climate.
It was a rudimentary “bag” to be tightened with a cord , that's all.
A simple but, it seems, effective system.