Your main tool is the 2nd level Ritual Spell, Magic Mouth
I'm going to borrow the basics from The Arcane Programmer Guide, but I highly recommend reading the whole thing if you want some properly comprehensive rules on this subject.
The essence of how Arcane Programming works, RAW, in 5th edition D&D, is that the spell Magic Mouth has the following very important properties:
- It lasts until being dispelled
- The Mouth can activate in response to any stimuli it can observe in range (30 feet) to the limit of what you stipulate
- Nearby Mouths can react to the behavior of other nearby mouths
- It can say up to 25 words, at the volume of your choosing, delivered over up to 10 minutes.
Using these principles, we can build logic gates.
A Basic Example
For example, to build a Remote Alarm:
- Set a mouth near the area you want to monitor, instruct it that if it sees someone enter through that area, it should, very quietly, say the letter "A".
- Set a mouth no more than 30 feet away from the first mouth; if it hears the letter "A", say the letter "B" quietly
- Set a mouth no more than 30 feet away from the last mouth; if it hears the letter "B", say the letter "C" quietly
- Another mouth, says "A" in response to "C"
- Another mouth, says "B" in response to "A"
- And so on, and so forth, until you reach your destination
- At the destination, A mouth should be put near a lever, and it should respond if two things are true:
- The lever is pulled up, and
- It hears a letter "A", "B", or "C" (base it on whatever was the last mouth you set)
- It should shout, as loudly as possible, "INTRUDER!", 25 times, once every 24 seconds (4 rounds)
We've created an alarm system that also has a safety switch: if you want to allow someone through, you push the lever down, let them through, and then raise the lever again.
We can improve. For example, create two Magic Mouths. Instruct one to, when it hears "I", say "O", and the other, upon hearing "O", say "I". Then, speak in the same tone used to create the second one, "I", and now, both mouths will alternate between saying "I" and "O" over and over, indefinitely. You now have a clock.
So the alarm system mentioned earlier? Scatter monitoring mouths around the base, and put clocks in range of them. Then, their trigger is
When it hears the letter "I" and sees someone in their presence, say "A"
So now the alarm will trigger indefinitely, unless shut off. No more 10 minute time limit!
OR Gate. When it hears the letter "A", or the letter "B", speak the letter "C"
AND Gate. When it hears the letter "A" and the letter "B" within a second, speak the letter "C"
XOR Gate. When it hears the letter "A" or the letter "B", but not both within a second, speak the letter "C"
NOT Gate. If it goes one second without hearing the letter "A", speak the letter "B"
Glyph of Warding spells are one-time-use only, but if there's an intruder inside the base, that's probably the situation they're called for. Glyph of Warding spells are also able to take complex instructions, so long as they're still primed to react to someone, so for example:
Glyph of Warding (Hold Person). When someone walks into an area, and the letter "D" has been heard in the last second, activate.
So like with the Alarm example, set up a magic mouth (or several...) to repeat, while a lever is up, the letter "D", and only stop while the lever is down. You now have a Glyph of Warding that will only trigger so long as the safety is off.
The limitation on this spell pretty much comes down to the physical limitations of the spell (which can be easily circumvented) and your own personal creativity. So experiment and read the guide I linked above, and figure out what you can do.