© 2016 American Physical Society. Magnetic skyrmions are candidates for a new generation of information carriers due to their nanometric size and topologically protected stability. The study of the dynamics of such skyrmions in racetrack geometries and, in general, in confined geometries becomes essential to achieve these goals. Here we present analytical expressions for the trajectories of skyrmions in confined geometries (including long tracks and squared samples) when driven by polarized electric currents. The force exerted by the borders is derived as a function of the material parameters (anisotropy, Dzyaloshinskii-Moriya, and exchange constants) and incorporated in the equation of motion of the skyrmions. We find the general expressions for the trajectories in several possible scenarios, and we also find simple expressions for the stationary position, the velocity, as well as for the threshold velocity of the driving electrons that could overcome the edge repulsion. In fully confined geometries, the geometric edges can produce a naturally oscillating movement, allowing for dynamical resonances if the driving current is an ac current with adequate frequency. Numerical micromagnetic simulations considering typical experimental parameters are used to corroborate the theory.