1. A computer-implemented method of selecting virtual machine instances on which to execute user-specified code within an on-demand code execution environment, the on-demand code execution environment comprising a plurality of virtual machine instances executing an initialized operating system and awaiting requests to execute user-specified code within that operating system, the method comprising: as implemented by one or more computing devices configured with specific computer-executable instructions, generating a first risk profile for a first task associated with the on-demand code execution environment, the first task corresponding to a first set of user-defined executable code, wherein the risk profile for the first task indicates a risk that execution of the first task on a virtual machine instance will compromise security of other tasks executing on the virtual machine instance, wherein the first risk profile for the first task is determined based at least in part on at least one of one or more function calls included within the first set of user-defined code, one or more libraries included within the first set of user-defined code, one or more computing resources expected to be utilized during execution of the first set of user-defined code, or one or more permissions requested for execution of the first set of user-defined code; obtaining a request to execute the first task on the on-demand code execution environment; selecting the virtual machine instance from the plurality of virtual machine instances on which to execute the first task at least partly by: obtaining a second risk profile for a second task assigned to be executed on the virtual machine instance, the second task corresponding to a second set of user-defined executable code, wherein the risk profile for the second task indicates a risk that execution of the second task on the virtual machine instance will compromise security of other tasks executing on the virtual machine instance; and determining, based at least in part on the first risk profile and the second risk profile, that a risk level associated with execution of both the first task and second task on the virtual machine instance does not exceed a threshold value; and assigning the virtual machine instance to execute the first task.