Biofuels provide an attractive alternative for satisfying energy demands in a more sustainable way than fossil fuels. To establish a biorefinery, an optimal plan must be implemented for the entire associated supply chain, covering such aspects as selection of feedstocks, location, and capacity of biorefineries, selection of processing technologies, production amounts and transportation flows. In this context, there are several parameters, including the availability of biomass, product demand, and product prices, which are difficult to predict because they might change drastically over the different seasons of the year as well as across years. To address this challenge, this work presents a mathematical programming model for the optimal planning of a distributed system of biorefineries that considers explicitly the uncertainty associated with the supply chain operation as well as the associated risk. The potential of the proposed approach is demonstrated through its application to the production of biofuels in Mexico, considering multiple raw materials and products.