This paper intends to present an approach to the problem of the optimal cross-section topology of a retaining wall. We use the Solid Isotropic Material with Penalization (SIMP) method to solve this problem. An isotropic solid is divided into n quadrilateral finite elements, and each such element e is associated with a design variable xe which might be regarded as a material density. The notion of a virtual Young's modulus is introduced, and for each element it can be approximated as follows: , where p is a penalty, which is usually equal to 3; Emin is a small value of the modulus, which we use in order to avoid the singularity of a stiffness matrix; E0 is the Young's modulus of the material. Thus when the condition 0 ≤ xep ≤ 1 is satisfied Ee varies between a certain minimum value Emin and the usual Young's modulus E0. We regard a retaining wall with a solid cross-section in the form of a rectangle with a height to base ratio of 3:1 to demonstrate the proposed approach. Along its entire height the wall is under the pressure of soil, which varies linearly from 0 to 1. In general, this corresponds to hydrostatic pressure. From the standpoint of the theory of elasticity such a problem can be considered as planar. The problem of the optimal topology shrinks to the mathematical programming problem in the form of under certain conditions (here F is a vector of external forces, u(x) is a vector of displacements, x is a vector of densities). The objective function can be interpreted as the work done by external forces to deform the system, thus we tend to find the stiffest body of a certain volume. To solve mathematical programming problem we use Python programming language, and Numpy and Scipy packages. To eliminate the “checkerboard problem” (alternation of black and white cells) we apply a Gaussian filter from the Skimage package. The parameters of the obtained model are described in ANSYS Parametric Design Language and exported to Ansys Mechanical for further analysis. It is determined that the maximum von Mises stress in the structure with the optimal topology and the prescribed volume fraction of 60% does not exceed this value in the retaining wall with a base rectangular cross section.