Before I answer the question I'll take a step back and explain what a DI Box is and what it's used for.
Most music and audio equipment which receives an analog audio signal, such as mixing consoles and PA amplifiers, are designed to receive that signal at Line Level. This is the level which is output by most equipment such as microphones, keyboards, samplers, drum machines etc.
However, guitar and basses produce a signal with a level of impedance which is far too high to be plugged directly into a line level input - this is where the DI Box comes in.
In its simplest form, a DI Box is a transformer which converts the high impedance instrument output of around 50,000 ohms to a line level output at around 100 to 200 ohms, and it also converts the signal from unbalanced to balanced.
This is all you really need to know about DI Boxes to decide whether or not you need one for recording with an audio interface - I'll leave the discussion about active vs passive DIs for another day.
Audio Interfaces with only Line Inputs
These are becoming less common these days, however if you have one like the higher-end Apollo 16, then you'll absolutely need a DI Box to record electric guitar or bass.
Audio Interfaces with both Instrument & Line Inputs
In this case a DI Box is technically not required - you can plug your guitar or bass straight into your audio interface and begin recording straight away.
But - you knew that but was coming didn't you :) - I recommend always using DI Boxes for recording guitar and bass if you're not mic'ing an amp. If you're using a microphone to record the sound coming from an amp then a DI Box is unnecessary because the mic is sending the correct line level already.
Here are the reasons why I recommend using a DI Box to plug your guitar or bass directly into your audio interface...
Firstly, some of the cheaper audio interface instrument inputs are too 'hot'. This means you get too much gain which can lead to unwanted clipping/distortion of the incoming signal.
Secondly, using a DI Box will give you a consistent signal when you change between guitars with different pickups.
Finally, if you need to run the cable over more than a few feet you'll benefit from the balanced signal which eliminates noise caused by electromagnetic interference hitting the cable - this type of noise gets cancelled out when using a balanced signal. BTW - I also use a DI Box for recording directly from keyboards in this scenario.
If you're primarily recording for fun at home or just making basic demos then you probably don't need one, but if you are making more important recordings to release to the public, even if it's just free YouTube videos rather than selling your music, then you're going to benefit from employing a DI Box in your signal chain.
NB: If you're using your computer, tablet, or smartphone (with something like the Ampkit Link HD) for amp modeling and effects while you practice guitar, then you don't need to bother plugging into a DI Box.