The sustainable design and optimization of agricultural spatial environments involves a commitment to the environment, focusing on the preservation and conservation of irreplaceable and non-renewable natural resources. Designers need to approach the construction of agricultural spatial environments from a new perspective, considering environmental carrying capacity, land function management, and land division methods. The use of artificial intelligence (AI) and virtual reality (VR) technology allows for the assessment of design conditions, such as orientation, layout, and proximity to nearby buildings. This technology can then make reasonable adjustments to optimize elements introduced into the agricultural spatial environment, ultimately improving the physical space structure and environmental performance. This paper introduced methods and principles of multi-scale data preprocessing and three-dimensional visualization modeling. It analyzed the technical architecture and application function of agricultural spatial environment design, proposes strategies for agricultural spatial environment design based on AI and VR technology, discusses the component elements and scene layout of agricultural spatial environment optimization, and expounds on schemes for agricultural spatial environment optimization based on AI and VR technology. Lastly, it carried out a case simulation and analyzes the results. The study results indicated that the agricultural spatial environment design model presented in this paper views space planning and layout as a collection of agents formed by the interaction and cooperation of multiple units. Each space unit is considered a unit with multiple attributes, such as sunlight constraints, spacing constraints, and unit performance. AI and VR technology can effectively integrate the design and optimization of agricultural spatial environments with the real environment, providing users with visual, auditory, tactile, and other sensory simulations to improve the overall sense of space and experience.