Detection collision can be done in many, many ways.
For example if you approximate your cube with an AABB and your walls with simple planes, it’s possible to perform very fast collision detection via a basic AABB/plane intersection tests. Another option is to put at each side of your cube a ray and perform ray intersection tests with the geometry of your wall. This approach is more flexibel but also more costly.
An other option from game development is to use a navigation mesh in order to restrict the movement of game entities or the player in a modern fashion. There are a lot of scenarios where such an approach is sufficient (and faster) than using a collider system or physics engine. And it can be also used for pathfinding (well, that is the primary purpose of a nav mesh^^).