CubeSpec is an ESA in-orbit-demonstration mission, based on a 6U CubeSat, targeting high-resolution astronomical spectroscopy. It is developed and funded in Belgium and scheduled for launch at the end of 2024. The CubeSpec payload consists of an off-axis Cassegrain telescope with a rectangular aperture (186x82mm2 ) and a prism cross-dispersed echelle spectrograph. The telescope aperture almost completely covers the surface area of 2 CubeSat units and the entire optical system fits in 4 units (10x20x20cm) of the spacecraft. CubeSpec delivers a spectral resolution of R=55000 and covers the wavelength range from 420 to 620 nm. Furthermore, it is equipped with a fine-guidance system based on a fast beam-steering mirror and a fine-guidance sensor that provide accurate centering of the source image on the spectrograph slit to compensate for spacecraft pointing jitter. In this contribution, we present the optical design of the CubeSpec payload.