If the source language already has genders, then they will often be taken along to the host language, provided that people in the host language know a little bit about the source language. But there are countless other subtle, complex factors.
Dutch has a neuter article (het) and the fused/common gender masculine-femine (de). There are no definite rules for borrowed words, and we never learned any such rules. I would know if there were any, but no: genders are assigned subconsciously. For existing Dutch words, there are some rules, but I think perhaps half the words have genders that feel arbitrary (though fixed) to us. For example, a person will nearly always be masculine or feminine, and words on -heid are always feminine; but for most other words you just have to know. The difference between masculine and feminine only comes up with possessive adjectives (the fork and his?/her? prongs) and personal pronouns (not that fork: I saw her?/him? lying over there). Colloquially, we usually use masculine pronouns for de words; in writing, I often have to look up the gender of a word, unfortunately. In the south and in Belgium, I think they don't use masculine by default.
Because we have a word het huis in Dutch ("the house"), English safehouse will become het safehouse, as it is very similar. Usually the similarity is less direct; then a word with a similar meaning may be picked as the example. For instance, suppose that Japanese *inko means house (I'm just making this up), then I am more likely to say het inko.
However, a second factor is how the word sounds compared to words that sound remotely similar. Words on -o are probably more often masculine in Dutch, because of the many Italian and Spanish words on -o, like impresario, virtuoso, amigo, gringo, etc., so I am more likely to say de inko because of the sound.
Thirdly, I think many languages have a kind of "default" gender for (foreign) words. In German, I was taught that newly borrowed words are normally feminine. So it was easy to learn die CD and such (although, if this rule is valid in German, there must be many categories of exceptions). In Dutch, masculine and feminine have all but merged, that is, they have the same article, de. For that reason, de is much more frequent than het (neuter), so that de is more likely to be chosen for new words.
Fourthly, there is the possibility that the gender is taken from a third language, if that language has already adopted the word and assigned a gender to it. Dutch might follow German in some cases; I don't know how often this really happens.
To all these factors may be apportioned different weights in different circumstances, and they are somehow weighed by the subconscious of the first people who use the word, until at some point it has acquired a commonly accepted gender. It is often unpredictable in my experience.
Note also that it is perfectly possible for a borrowed word to remain of uncertain gender indefinitely. We even have some ancient native (inherited) words that we still bicker over (in a good-natured manner, of course). Now a few practical examples.
Dutch het net => het Internet. Since net means the same thing in Dutch as in English, this one was easy.
Het koekje => de/het cookie. I'm not sure about this one; I would probably say de cookie. Perhaps it is too new, but people do talk about this on a regular basis, have done so for at least a decade, and yet it is still not entirely decided. One would expect such a strong similarity to the Dutch word to lead to het cookie, and yet I would say de cookie. I feel that perhaps the default gender de is just too strong in Dutch. Or perhaps the fact that it is a small object: perhaps those have an extra strong tendency to be de words? Hard to say.
De router, de server: we have no similar words, but words on -er usually indicate an agent, a person even, and people are normally not neuter, so definitely de router, de server.
De absence: this is the French word, pronounced as in French. It was adopted into Dutch long ago, so I did not witness its introduction. My guess is that the ending -e had a strong influence, and simply the fact that it is obviously feminine in French.
Het communisme: this probably came from French. For some reason, (nearly?) all words on -isme are neuter in Dutch. I have no idea why, because I think they are masculine in all other languages, including French, which doesn't have a neuter gender at any rate. They come from Latin -ismus, which is masculine, from Greek -ismos, also masculine. Very strange.
De coating (as in paint). There is no Dutch equivalent. The ending -ing is nearly always feminine in Dutch for non-persons, so de (cognate to German -ung).
De axolotl: nothing at all sounds like or resembles an axolotl, but I think animals are by default de, because they are agents (even though we do have plenty of neuter animals).
De tsunami: probably de because -i sounds a bit like Italian or Latin masculine? There is also de golf "the wave", de vloed "the flood". I'm not sure.
Het DNA: hard to say. Perhaps because Acid was translated subconsciously as het zuur by the first Dutch scientists? Because substances are more likely to be het?