If it's not valid BASIC or machine code, what is it? Random garbage could be anything, so it's impossible to guarantee that it won't look like valid code.
The technique I used was to make a rule that the machine code must start with an opcode sequence that is not likely to occur 'accidentally'. On the 8051 the first 3 bytes are normally a jump to the initialization code. If you ensure that the init code is always at the same address then you can check for that, and then you have 3 bytes that must match. If the init address may vary then you will have to follow it and examine more code. Often the next 2 instructions set the stack pointer, so you could check for that. You could also 'sanity check' the target addresses to eliminate obvious errors.
Of course if your EEPROM has random garbage in it then there is still a small chance of misidentifying it as valid code, in which case the machine will crash. If this is unacceptable then embed a signature at a known location somewhere in the EEPROM. For added security include a checksum or CRC that covers the signature or even the entire EEPROM.
If you are creating the code that goes in the EEPROM then this is the obvious solution. Things get trickier if you allow other users to load it with random data. My solution was to simply reject anything that doesn't follow my rules. To make it easier to comply I provided a macro that is added to the user's source code.