This is a Snake Cube Puzzle

I am trying to understand the solution from mathematical point of view. Someone even wrote a solver: https://github.com/markfickett/snakepuzzle but I can't really read the code. I can imagine a solver that would iterate through all combinations until it finds one that is 3x3x3 in size but that is not really a "solution".
What would be the equation and how would I approach solving it?