Sun sensors represent a common and reliable technology for attitude determination, employed in many space missions thanks to their limited size and weight. Typically, two-axis digital Sun sensors employ an array of active pixels arranged behind a small aperture; the position of the sunlight's spot allows to determine the direction of the Sun. With the advent of smaller vehicles such as CubeSats and Nanosats, there is the need to further reduce the size and weight of such devices: as a trade-off, this usually results in the curtail of the performances. Nowadays, state of the art Sun sensors for CubeSats have resolutions of about 0.5°, with fields of view in the ±45° to ±90° range, with off-the-self prices of several thousands of dollars. In this work we introduce a novel low-cost miniaturized Sun sensor, based on a commercial CMOS camera detector; its main feature is the reduced size with respect to state-of-the-art sensors developed from the same technology, making it employable on CubeSats. The sensor consists of a precisely machined pinhole with a 10 μm circular aperture, placed at a distance of 7 mm from the CMOS. The standoff distance and casing design allow for a maximum resolution of less than 0.03°, outperforming most of the products currently available for nano and pico platforms; furthermore, the nature of the technology allows for reduced size and lightweight characteristics. The design, development and laboratory tests of the sensor are here introduced, starting with the definition of the physical model, the geometrical layout and its theoretical resolution; a more accurate model was then developed in order to account for the geometrical deviations and deformations of the pinhole-projected light-spot, as well as to account for the background noise and disturbances to the electronics. Finally, the laboratory setup is presented along with the test campaigns: the results obtained are compared with the simulations, allowing for the validation of the theoretical model.