Spheres are best, but cylinders are easiest to manufacture
For the most internal volume compared to the surface area, and hence the smallest possible mass, a sphere is the ideal shape for a spacecraft. The orbital module of the Soyuz spacecraft is approximately a sphere:
Most construction techniques in use are based on metal plates. Therefore, spacecraft shaped like cubes or cylinders (a bent plate) are easy to manufacture. The sharp edges are however less optimal than the sphere to withstand internal pressure.
For long stays in space, it is beneficial to have some sort of artificial gravity induced by rotation. Cylinders and toruses are then good options. They are also rather easy to inflate. (that is a launch constraint, but an important one)
A spacecraft with artificial gravity must not necessary have to be of a curved shape, two spacecraft, or one spacecraft and a counterweight with a tether in between can basically do the same thing.
For some types of propulsion, most importantly nuclear-electric, solar sails, or solar-electric, huge areas of radiators, sails, or solar cells are necessary. That pretty much determines their shape.
(huge but flat, with a long truss-segment in the middle)
Different parts of a spacecraft has different requirements, hence, you may use different shapes for them instead of an all-in-one trade off. Again, the Soyuz is an excellent example of geometry, using a sphere for the orbital module, an aerodynamically blunt body shape for the return capsule, and a cylinder for the equipment module.
Landers
One of the top priorities for a lander is to have a large base to prevent it from tipping when landing on the surface. Despite initial surveys from unmanned probes in orbit of for example the Moon, you can never be totally sure about the usefulness of a particular landing site. The Apollo 11 did for example change the target landing site in flight. Therefore, landers are typically very wide, so they do not fall over. The descent stage is often-shaped like a polygonal prism, with a symmetry depending on the number of landing legs. (three for a minimum configuration, four for a little more stability , or five or more for redundancy and extra stability).
The Apollo lunar module descent stage had an octagonal shape, corresponding to its four-fold symmetry: