We provide necessary and sufficient conditions for optimality of mutual contracts for risk sharing under constraints on premiums or utility functions of participants of the agreement. These conditions are an extension of those of the Borch, Gerber and Bühlmann-Jewell ones. Some applications to optimal insurance contracts, optimal dividend sharing and optimal reinsurance are given.