A new nonadditive three-body interaction potential for carbon dioxide was determined from supermolecular ab initio calculations up to the coupled cluster with single, double, and perturbative triple excitations [CCSD(T)] level of theory for 9401 configurations. A physically motivated analytical function with terms for describing nonadditive dispersion, induction, and exchange contributions was fitted to the calculated nonadditive three-body interaction energies. For the 7996 configurations with a total interaction energy of less than 3000 K, the mean absolute error of the analytical function is 0.32 K. The new nonadditive three-body potential was applied together with a previously published pair potential [R. Hellmann, Chem. Phys. Lett. 613, 133 (2014)] to calculate the third to seventh virial coefficients of CO at subcritical and supercritical temperatures up to 2000 K. The eighth virial coefficient was also calculated, but using only the pair potential and only at temperatures from 600 K to 2000 K because of the enormous computational costs. A simple analytical function was fitted individually to the calculated values of each virial coefficient, including previously determined values of the second virial coefficient, to obtain an analytical virial equation of state (VEOS). For densities at which the VEOS is converged, the agreement in pressure with the reference EOS of Span and Wagner [J. Phys. Chem. Ref. Data 25, 1509 (1996)] is mostly within ±0.5%. However, for temperatures above about 700 K, much larger deviations occur at higher densities, which we ascribe mainly to deficiencies of the reference EOS due to the lack of accurate data for these experimentally difficult conditions.