The unconstrained ensemble describes completely open systems whose control parameters are chemical potential, pressure, and temperature. For macroscopic systems with short-range interactions, thermodynamics prevents the simultaneous use of these intensive variables as control parameters, because they are not independent and cannot account for the system size. When the range of the interactions is comparable with the size of the system, however, these variables are not truly intensive and may become independent, so equilibrium states defined by the values of these parameters may exist. Here, we derive a Monte Carlo algorithm for the unconstrained ensemble and show that simulations can be performed using chemical potential, pressure, and temperature as control parameters. We illustrate the algorithm by applying it to physical systems where either the system has long-range interactions or is confined by external conditions. The method opens up a new avenue for the simulation of completely open systems exchanging heat, work, and matter with the environment.