Code execution method and device, equipment, medium and program product
By dynamically deploying the component library required by the target code in the sandbox, the problem of unpredictable code calling the component library is solved, and the instant execution of the target code and the stability and security of the server are achieved.
Patent Information
- Application Number
- CN202510898335.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-30
- Publication Date
- 2025-10-17
AI Technical Summary
In the existing technology, it is impossible to predict the component library called by the code generated by the language model in real time, resulting in the inability to execute the code in the sandbox or placing too much burden on the server.
By intelligently analyzing the calling situation of the target code, dynamically deploying the target component library called by the target code in the target sandbox, and combining the isolation mechanism of the sandbox environment, the stability and security of the server are ensured.
It achieves instant execution of target code, reduces server burden, and ensures server security and stability through real-time monitoring and isolation mechanisms.
Smart Images

Figure CN120805121A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates generally to the field of computers, and more specifically to a method, an apparatus, a device, a computer-readable storage medium, and a computer program product for executing code. BACKGROUND
[0002] In the field of computers, a sandbox can simulate real running scenarios while limiting the access of programs to system resources, thereby ensuring system security and stability. It is like a virtual "container" that limits various operations during program running within a specific range, preventing malicious software or programs with vulnerabilities from causing damage to the computer system, and avoiding mutual interference between different programs.
[0003] For developers, a sandbox is an indispensable tool. It provides a safe and independent test space where developers can run various types of code, observe the actual running effect of the program, and troubleshoot and repair potential problems without worrying about damaging the development environment or other systems. In addition, the sandbox can simulate different operating systems, hardware configurations, and network environments to help developers test the compatibility and stability of the software. SUMMARY
[0004] According to an example embodiment of the present disclosure, a method, an apparatus, a device, a computer storage medium, and a computer program product for executing code are provided.
[0005] In a first aspect of the present disclosure, a method for executing code is provided, which includes allocating a target sandbox according to a user request. The method further includes deploying a target component library called by a target code in the target sandbox based on the user request. The method further includes executing the target code in the target sandbox in response to the target component library being deployed.
[0006] In a second aspect of the present disclosure, an apparatus for executing code is provided, which includes a sandbox allocation module configured to allocate a target sandbox according to a user request. The apparatus further includes a component library deployment module configured to deploy a target component library called by a target code in the target sandbox based on the user request. The apparatus further includes a code execution module configured to execute the target code in the target sandbox in response to the target component library being deployed.
[0007] In a third aspect of the present disclosure, an electronic device is provided, which includes at least one processing unit, at least one memory coupled to the at least one processing unit and storing instructions for execution by the at least one processing unit, which when executed by the at least one processing unit cause the electronic device to perform the method described according to the first aspect of the present disclosure.
[0008] In a fourth aspect of the disclosure, there is provided a computer readable storage medium having stored thereon machine executable instructions, which when executed by a device, cause the device to perform the method described according to the first aspect of the disclosure.
[0009] In a fifth aspect of the disclosure, there is provided a computer program product comprising computer executable instructions, wherein the computer executable instructions, when executed by a processor, implement the method described according to the first aspect of the disclosure.
[0010] The summary is provided to introduce a selection of concepts that are further described in the detailed description below. It is not intended to identify key or essential features of the disclosure or to delineate the scope of the disclosure. Other features of the disclosure will be apparent from review of the disclosure herein. BRIEF DESCRIPTION OF DRAWINGS
[0011] Figure 1 A schematic diagram showing an example environment in which embodiments of the disclosure can be implemented;
[0012] Figure 2 A flow diagram showing a method for executing code according to embodiments of the disclosure;
[0013] Figure 3 A schematic diagram showing a system for executing code according to embodiments of the disclosure;
[0014] Figure 4 A schematic diagram showing a preparation process prior to executing code according to embodiments of the disclosure.
[0015] Figure 5 A schematic diagram showing a process of executing code according to embodiments of the disclosure;
[0016] Figure 6 A schematic diagram showing a monitor according to embodiments of the disclosure;
[0017] Figure 7 A schematic diagram showing a statistical performance indicator according to embodiments of the disclosure;
[0018] Figure 8 A schematic block diagram of an example apparatus according to some embodiments of the disclosure;
[0019] Figure 9 A block diagram of an example device that can be used to implement embodiments of the disclosure.
[0020] In all of the drawings, like or similar reference numbers can be used to denote the same or similar elements. DETAILED DESCRIPTION
[0021] The names of the messages or information exchanged between the plurality of devices in the embodiments of the present disclosure are only for illustrative purposes, and are not intended to limit the scope of the messages or information. It can be understood that, before using the technical solutions disclosed in the embodiments of the present disclosure, the type of personal information involved in the present disclosure, the use range, the use scenario, etc. should be informed to the user and the authorization of the user should be obtained in a proper manner according to relevant laws and regulations.
[0022] For example, in response to receiving an active request of a user, prompt information is sent to the user to explicitly prompt the user that the operation requested to be performed will require obtaining and using personal information of the user. Thus, the user can autonomously select whether to provide personal information to the software or hardware such as an electronic device, an application program, a server or a storage medium, etc. performing the operation of the technical solutions of the present disclosure according to the prompt information. As an optional but non-limiting implementation manner, in response to receiving an active request of a user, the manner of sending prompt information to the user may, for example, be a pop-up window manner, and the prompt information may, for example, be presented in the form of text in the pop-up window. In addition, the pop-up window may, for example, carry a selection control for the user to select “agree” or “disagree” to provide personal information to the electronic device.
[0023] It can be understood that the above notification and obtaining of user authorization process is only illustrative, and does not limit the implementation manners of the present disclosure, and other manners meeting relevant laws and regulations can also be applied to the implementation manners of the present disclosure.
[0024] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure can be implemented in various forms, and should not be interpreted as being limited to the embodiments set forth herein, but rather these embodiments are provided to more thoroughly and completely understand the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes, and are not intended to limit the scope of protection of the present disclosure.
[0025] In the description of the embodiments of the present disclosure, the term “comprising” and similar terms are understood to be open-ended, i.e., “including but not limited to”. The term “based on” is understood to mean “based, at least in part, on”. The term “one embodiment” or “the embodiment” is understood to mean “at least one embodiment”. The terms “a first”, “a second”, etc. can refer to different or same objects unless explicitly stated otherwise. Other explicit and implicit definitions can also be included below.
[0026] In the related art, when a developer sets up a sandbox for code that needs to be executed, the developer needs to determine in advance the component library (or module, or function library) called by the code, and then pre-deploy the component library in the sandbox, so that the code can be successfully executed in the sandbox, otherwise it cannot be executed. However, in some scenarios, the component library called by the code cannot be predicted, for example, when executing code generated in real time by a language model in a sandbox, it is impossible to predict which component library will be called by the language model in the code, resulting in the inability to execute the code in the sandbox. In addition, due to the large number of component libraries, no matter which component libraries are pre-deployed, the component library called by the code may be missed, resulting in the inability to execute the code in the sandbox. Even if all existing component libraries are deployed, it will bring excessive burden to the server.
[0027] To this end, the present disclosure proposes a method for executing code. After a target sandbox is allocated for a user request, the method dynamically deploys a target component library called by a target code in the target sandbox by intelligently analyzing the calling condition of the target code, thereby realizing intelligent deployment of the component library, and in addition, the sandbox environment can improve the stability and security of the server.
[0028] Embodiments of the present disclosure will be described in detail below with further reference to the accompanying drawings, in which Figure 1 A schematic diagram of an example environment 100 in which embodiments of the present disclosure can be implemented is shown. In the example environment 100, a user device 110, a server 120, and a content distribution network node 134 are included. In some embodiments, the user device 110 communicates with the server 120 through a network 130, and the server 120 communicates with the content distribution network node 134 through a network 140. The network 130 and the network 140 can include wired networks, wireless networks, or a combination thereof. In the present embodiment, the server 120 executes the method of the embodiments of the present disclosure.
[0029] As shown in FIG. 1, the user device 110 can show a user an upload interface for uploading code to a code library. The code library can be any purpose code library, for example, it can be a code library for a certain network application set up for the user. In some embodiments, the user device 110 can provide a "submit code" button 114 to interact with the user, facilitating the user to upload code 112 that needs to be run at the server 120 by triggering the button 114. Figure 1
[0030] The uploaded code 112 can be stored in the user device 110 or in other devices. In some embodiments, the user only needs to send a user request for executing the code 112 to the server 120, and fill in the address where the code 112 is stored in the request body of the user request, for example. In this way, the server 120 can obtain the code 112 by analyzing the user request.
[0031] In some embodiments, the server 120 allocates a sandbox 150 according to a user request. The server 120 often has high requirements for stability and security, and if the user uploaded code 112 is directly run in the server, it can destroy the stability and security of the server 120, so a sandbox 150 can be created in the server 120 for executing the code 112. For example, if the code 112 is too complex and falls into an infinite loop, it can cause the resources of the server 120 to be exhausted, and if the code 112 contains malicious code, it can destroy important files of the server 120. The sandbox 150 protects the security and stability of the server 120 through multiple mechanisms such as building an isolated environment, limiting resource access, and controlling program behavior. By creating a physically or logically isolated execution space, the program runs in an independent environment, blocking malicious programs from spreading to the system core and other programs. For example, by creating a lightweight virtual machine, the program is isolated from the host file system, registry, and other resources, and by assigning each application an independent ID, a process-level sandbox is implemented, so that different application processes cannot directly access each other's resources, ensuring the security of the server 120.
[0032] In some embodiments, based on a user request, the server 120 deploys a component library 136 (or function library, module) called by the code 112 in the sandbox 150. Generally, the code records the dependent component library through a specific syntax specification, and the server 120 parses the code 112 by using the syntax specification to extract the type, version, and other key information of the component library 136 depended by the code 112. The server 120 further queries the local component library cache area, and if the cache area contains the corresponding component library 136, it is packaged and transmitted to the sandbox 150 through the resource scheduling module. If there is no component library 136 in the cache area, the server 120 can initiate a download request to the content distribution network node 134, and the content distribution network node 134 sends a loading package of the component library 136 to the server 120. After completing the download and integrity check on the server 120 side, the component library 136 is injected into the sandbox 150. In some embodiments, the server 120 can also generate a deployment index file of the component library 136 for subsequent quick positioning when the code 112 is called.
[0033] In some embodiments, if the component library 136 is deployed, the server 120 executes the code 112 in the sandbox 150. In some embodiments, the server 120 is provided with a component library deployment state detection mechanism, and when the detection module confirms that the component library 136 has been successfully deployed to the sandbox 150, a deployment completion signal can be sent to the code execution control module. After the code execution control module receives the signal, the code 112 can be preprocessed, including syntax checking, dependency verification, and other operations to ensure that the code 112 has execution conditions in the running environment of the sandbox 150. In some embodiments, the code execution control module can call a language model to complete the preprocessing task. The server 120 can also allocate independent running threads and computing resources for the code 112, and start a code running container in the sandbox 150, load the preprocessed code 112 into the container for execution. During the execution of the code 112, the monitoring module of the sandbox 150 can monitor the calling of the code to the component library 136 in real time, and as soon as abnormal calling behavior is found, such as illegal access to unauthorized components, component version incompatibility, etc., the execution of the code 112 will be immediately interrupted, and abnormal information will be fed back to the server 120 for subsequent processing.
[0034] In some embodiments, after the code 112 is executed using the components provided in the component library 136, the server 120 can send the product 122 to the user device 110. The user device 110 can display the product 122 in the display device, allowing the user to directly view the execution result of the code 112. Compared with the traditional way, after the target sandbox is allocated for the user request, the target component library required by the target code is dynamically deployed by analyzing the calling of the target code, which not only reduces the burden of the server, but also allows the target code to be executed immediately after deployment. At the same time, the sandbox ensures the safety and stability of the server through isolation environment and other mechanisms, and the server pre-processes the code and monitors the calling in real time, and finally feeds back the execution product to the user device, facilitating the user to visually view the execution result of the code 112.
[0035] The network 130, 140 has a theoretical bandwidth, which refers to the maximum transmission speed supported by the network 130, 140, and represents the maximum amount of data that the network 130, 140 can transmit under ideal conditions, usually measured in bits per second (bps). For example, if the theoretical bandwidth of the network 130, 140 is 100 Mbps, it means that it can transmit one hundred megabits of data per second under ideal conditions. However, in reality, due to other factors in the network (such as signal interference, bandwidth sharing, transmission delay, etc.), the actual transmission speed may not reach 100 Mbps.
[0036] As understood by one of ordinary skill in the art, the instance of the server 120 can be a standalone physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDNs, and basic cloud computing services such as big data and artificial intelligence platforms. The servers can be directly or indirectly connected through wired or wireless communication, which is not limited in the present application.
[0037] The user device 110 can be any type of mobile computing device, including a mobile computer (e.g., a personal digital assistant, a laptop computer, a notebook computer, a tablet computer, a netbook, etc.), a mobile phone (e.g., a cellular phone, a smartphone, etc.), a wearable computing device (e.g., a smartwatch, a head-mounted device, including smart glasses, etc.), or other types of mobile devices. In some embodiments, the user device 110 can also be a stationary computing device, such as a desktop computer, a game console, a smart television, etc.
[0038] It should be understood that the architecture and functionality of the example environment 100 are described for illustrative purposes only and are not intended to be limiting of the scope of the present disclosure. Embodiments of the present disclosure can be applied to other environments with different structures and / or functionalities.
[0039] The processes according to embodiments of the present disclosure will be described below in detail with reference to other drawings. For ease of understanding, the specific data mentioned in the following description are all exemplary and do not serve to limit the protection scope of the present disclosure. It can be understood that the embodiments described below can also include additional actions not shown or can omit the actions shown, and the scope of the present disclosure is not limited in this respect.
[0040] Figure 2 A flowchart of a method 200 for executing code according to certain embodiments of the present disclosure is shown. In this embodiment, the present method can be performed by the server 120. At block 202, a target sandbox is allocated according to a user request. The user request is a code execution instruction sent by a user through a user device, containing request header, request body, and other information, and the request body contains code storage address, execution parameters, and other information. The target sandbox is an isolated execution environment dynamically allocated based on the user request, and process isolation and resource limitation are achieved through namespace, control group, and other technologies of the operating system kernel to prevent the target code from causing damage to the server system. In some embodiments, the server dynamically schedules the target sandbox from the sandbox service manager according to the current system load, the sandbox isolation level (such as whether network isolation is required), and the code type.
[0041] At block 204, based on the user request, a target component library called by the target code is deployed in the target sandbox. The component library is a third-party function library / module that the target code depends on at runtime, containing API interfaces, tool classes, and other resources required for code execution, and its deployment needs to match the code syntax specification (such as the dependencies declared by the import statement). Based on the user request, the target component library on which the target code depends is analyzed. In some embodiments, a package file containing the target component library is obtained from a content distribution network node and loaded into the server 120. The server 120 then extracts the target component library therefrom and injects it into the sandbox for use by the target code. In some embodiments, if the component library deployment fails (such as network timeout), the server 120 can return an error report to the user device 110, accompanied by an error cause and a solution (such as checking network connection).
[0042] At block 206, in response to the target component library being deployed, the target code is executed in the target sandbox. For example, the logic of the code 112 can be executed in the sandbox 150. When the code 112 needs to call a certain component in the component library when it executes to a certain progress, the component can be directly called from the sandbox 150, the corresponding result is obtained, and the subsequent code is executed based on the result until the code 112 completes execution. In some cases, the code execution can result in a certain product, such as a certain file, or no product, but only output data or calculation data. These results after execution can be sent to the user device 110 for display, allowing the customer to intuitively understand the execution result of the code. In some embodiments, the execution result of the code (such as output log, return value) is displayed in the form of a table / chart, and downloading the execution product is supported. According to the method of embodiments of the present disclosure, after the target sandbox is allocated for the user request, the target component library called by the target code is dynamically deployed in the target sandbox by intelligently analyzing the calling situation of the target code, thereby realizing intelligent deployment of the component library, and in addition, the sandbox environment can improve the stability and security of the server.
[0043] Figure 3 A schematic diagram of a system for executing code according to embodiments of the present disclosure is shown. The system includes two main modules, a service middleware layer 304 and a sandbox management system 316. The service middleware layer 304 is mainly responsible for receiving, parsing and processing components of external requests. It can convert the request of a user or client into an operation executable by the system and return the corresponding result.
[0044] In some embodiments, the service middleware layer 304 can assign a unique request identifier to the received user request 302, and the service middleware layer 304 can associate the processing of the user request 302 to the request identifier. Different user requests can be distinguished from each other by different request identifiers. In some embodiments, the user request 302 can be a request based on the Hypertext Transfer Protocol.
[0045] In some embodiments, the database service assigner 306 in the service middleware layer 304 can provide database service for the user request 302, e.g., create a database instance for the user request 302, record data related to the user request 302. In some embodiments, the service middleware layer 304 can determine the environment type of executing the target code according to the content in the user request 302. The environment type includes, for example, a debugging environment and a production environment. For the debugging environment, less resource is needed, and the processing data is often virtual data, rather than real data. The debugging environment allows frequent modification of code, called component library, etc., and needs to be equipped with special debugging tools in advance. The production environment needs to be configured with high-availability resources according to the actual business scale, to ensure performance and stability (such as multi-server cluster, real-time backup database), and does not need to be equipped with debugging tools.
[0046] In some embodiments, the service middleware layer 304 can determine the sandbox service according to the environment type. In some embodiments, the service middleware layer 304 can create a target sandbox by calling the sandbox service. During the sandbox creation process, the service middleware layer 304 can configure different resource limit parameters according to the environment type, and provide debugging tools, while the production environment does not need to be equipped with debugging tools.
[0047] In some embodiments, the domain name resolver 312 resolves the target domain name in the user request to obtain the target address. For example, a user can deploy a network application, and participants of the network application can upload code to the database corresponding to the network application. After uploading the code, the user can send a user request to the server 120, which contains the address (e.g., a uniform resource locator) of the database of the network application. The uniform resource locator is resolved to determine the IP address of the database. In some embodiments, the service middleware layer 304 can verify whether the network application is in a service state, and if so, can interact with it to obtain the target code. In some embodiments, the service middleware layer 304 can obtain the target code from the target address accordingly.
[0048] In some embodiments, the request processor 308 can prepare context information for the sandbox according to the user request 302. The request processor 308 can analyze the user request 302 to obtain request context, including request parameters (address information), information of the user device (such as database IP address), session data, security credentials (token, permission information), etc., which can be injected into the sandbox for use by the target code, to ensure that the execution logic is based on the correct context. In some embodiments, the request parameters support form data, i.e., the user can provide context data related to the code in the form of form data.
[0049] In some embodiments, the sandbox service manager 314 can assign a sandbox service for the user request 302, which can invoke a preset service code to create a sandbox 330. The sandbox 330 is created and managed by the sandbox management system 316.
[0050] In some embodiments, the monitor 310 can record the execution of the user request 302 in the service middleware layer 304, and record the execution in a database provided by the database service assignor 306 for the user request 302, for reference by the developer. In addition, the monitor 310 can also record the user request 302, the response time and response data of the service middleware layer 304 in response to the user request 302 in the database. In some embodiments, the monitor 310 can monitor the resources consumed by the sandbox management system in executing the target code, the intermediate results generated, the alarm information, the execution results, etc., and record in the database. The monitor 310 can use the monitored data to calculate the performance indicators of the target code, which include, for example, the execution time of the execution code, the resource usage, etc.
[0051] For the sandbox management system 316 of the system, it is responsible for managing the created sandbox 330. The sandbox management system can include a sandbox manager 318, a task tracker 320, a code executor 322. In some embodiments, the sandbox manager 318 can create a sandbox identifier for the sandbox 330, and perform environment preparation in the sandbox 330. For example, if the environment type of the sandbox 330 is a debugging environment, debugging tools need to be deployed in the sandbox 330 according to the user request 302. In addition, the sandbox manager 318 can also inject the request context for the sandbox 330.
[0052] In some embodiments, the task tracker 320 can track the entire life cycle of the sandbox 330 and the entire life cycle of the target code execution process, so that the user can understand the current state of the sandbox and the execution of the target code. In some embodiments, the code executor 322 can trigger the execution of the target code in the sandbox 330.
[0053] The sandbox 330 can be provided with a component library deployer 332, a resource monitor 334, and an event catcher 336. The component library deployer 332 is configured to receive component library related code from a server outside the sandbox 330 and deploy it locally. The resource monitor 334 is configured to detect the resources consumed, such as memory resources, the number of GPUs used, and the like, in the process of executing the code, and send the monitored data to the monitor 310. The event catcher 336 is configured to capture various events occurring in the execution process of the code, including exception events, execution completion events, and the like, and feed the events back to the task tracker 320 outside the sandbox 330, which can mark the state of the task accordingly.
[0054] The embodiments of the present disclosure realize the dual improvement of security and system flexibility through the decoupling design of the service middleware layer and the sandbox management system. The service middleware layer focuses on request analysis and processing, and the sandbox management system is mainly responsible for the execution logic of the sandbox and the code, so that resource scheduling, dynamic deployment of component libraries, and full life cycle monitoring can be flexibly implemented, avoiding the burden caused by module coupling, improving observability through decoupling of the monitor, and solving the problem of excessive burden and execution failure caused by pre-deployment through the dynamic component deployment mechanism.
[0055] Figure 4 A schematic diagram of a preparation process before executing code according to an embodiment of the present disclosure is shown. At 402, the database connection is initialized. When the target code runs in the sandbox, it usually needs to connect to the database to perform data operations (such as reading, writing, querying). If the sandbox does not initialize the database connection, the target code may not start normally or be tested. In some embodiments, a database service is started within the sandbox or an external database is connected. In some embodiments, the database connection information (such as IP address, port) is configured. In some embodiments, the database connection is initialized (through code or configuration file) to ensure that the sandbox is connected to the database.
[0056] At 404, the domain name is parsed and the target code is obtained. In some embodiments, the DNS resolver is used to parse the target domain name (such as www.example.com) in the user request to obtain the corresponding IP address. In some embodiments, the state of the network application service corresponding to the domain name is verified to prevent access to invalid addresses. In some embodiments, based on the parsed IP address and the uniform resource locator (URL), the target code is pulled from the database or the code storage service through the HTTP / HTTPS protocol.
[0057] At 406, different sandbox services are invoked based on the environment type (debug / production), thereby creating a sandbox. At 408, the target code is analyzed to generate a component library request, i.e., a request for a target component library is determined based on the target code. In some embodiments, a lexical analyzer is used to parse the code syntax, extracting import / require dependency declaration statements. For example, by parsing “import pandas as pd”, the component library name pandas and version number (if declared) are extracted. In some embodiments, a dependency manifest is generated, containing component library name, version range, dependency type. At 410, if the target component library is in a target manifest, the acquisition address of the target component library is determined. The target manifest is a whitelist for component libraries, only component libraries in the target manifest are allowed to be injected into the sandbox. In some embodiments, if the operation of detecting whether the target component library is in the target manifest and the operation of determining the acquisition address are serial operations, when it is detected that the target component library is in the target manifest, the action of determining the acquisition address of the target component library can be initiated. In some embodiments, if the operation of detecting whether the target component library is in the target manifest and the operation of determining the acquisition address are asynchronous parallel operations, when it is detected that the target component library is in the target manifest, the determination of the acquisition address of the target component library is not interrupted. In some embodiments, if the target component library is not in the target manifest, the determination of the acquisition address of the target component library is interrupted. In some embodiments, if the operation of detecting whether the target component library is in the target manifest and the operation of determining the acquisition address are serial operations, when it is detected that the target component library is in the target manifest, the action of determining the acquisition address of the target component library can not be initiated, and warning information is provided. In some embodiments, if the operation of detecting whether the target component library is in the target manifest and the operation of determining the acquisition address are asynchronous parallel operations, when it is detected that the target component library is not in the target manifest, the determination of the acquisition address of the target component library is immediately interrupted, i.e., the generation of the request for the component library is interrupted before the downloading starts, so that the component library can be prevented from being downloaded or loaded. If the acquisition address has been determined, the acquisition of the target component library can be interrupted, for example, the downloading process is interrupted and the downloaded component is deleted. In this embodiment, not only the execution of the code can be interrupted by the interruption mechanism, but also the loading of the target component library can be effectively controlled by the interruption mechanism, and such multiple interruption mechanisms can ensure the security of the server. In some embodiments, if the target component library is not in the target manifest, warning information is provided for the target code. The warning information indicates that the target code calls an unallowed component library. In some embodiments, when detecting whether the target component library is in the target manifest, a regular expression can be used for detection, i.e., as long as the name of the target component library meets the regular expression, it can be considered that the target component library is in the target manifest.
[0058] In some embodiments, the interrupt operation is captured by the event catcher 336 and transmitted to the task tracker 320, setting the state of the code to "suspended". This is beneficial for the user to intuitively understand the execution of the target code through the task tracker 320. In some embodiments, the alert information can also be sent to the task tracker 320 through the event catcher 336, and the task tracker can record the reason why the code is in the "suspended" state. This is beneficial for the user to understand the context information of the abnormal event.
[0059] In some cases, the target code can call the server built-in component library. Accordingly, the target manifest lists those components of the server built-in component library that are allowed to be called. For example, the server built-in component library can include a large number of components, and the target manifest can include a part of the components, and the target code is allowed to call the part of the components. In the server built-in component library, the components can be methods, functions, resource information, etc., which can be represented in the form of files, modules, etc. Since the server built-in component library can involve components related to security, the target manifest can be used to more finely control the calling objects of the target code and improve the security of the server side. In some embodiments, the target component of the server built-in component library called by the target code is determined based on the user request. In some embodiments, if the target component is recorded in the target manifest, the target component is deployed in the target sandbox. In some embodiments, if the target component is not recorded in the target manifest, an alert information is provided.
[0060] At 412, the target component library is obtained by the server according to the obtained address, and the target component library is installed at the server. In some embodiments, the address is the address of the content distribution network node storing the code of the component library provided by a certain manufacturer, and the server can download the package file containing the target component library from the content distribution network node, and the server extracts the code of the target component library from the package file to inject into the sandbox.
[0061] At 414, the component library is cached at the server. For example, the server can save the extracted target component library (i.e., the code content) in the cache area. In some embodiments, if other sandboxes (i.e., a second sandbox) also need to deploy the target component library, the target component library is injected into the other sandboxes. In this way, the target component library can be reused in different sandboxes, thereby improving the deployment efficiency of the target component library. At 416, the extracted target component library is injected into the sandbox. In this way, the code can call the functions in the target component library when executing. In this embodiment, during the preparation stage before executing the code, the component library is supervised through the manifest to ensure that a safe component library is loaded on the server side, thereby improving the security and stability of the server.
[0062] Figure 5 A schematic diagram of a process of executing code according to an embodiment of the present disclosure is shown.Figure 5 The left side of the equation is the execution process of the code, Figure 5 The right side of the equation is the task tracking process that covers the code execution process. At 502, the execution environment of the target code in the sandbox is prepared, such as the context information required for the target code to execute. At 504, the target code is preprocessed, including formatting and normalizing the code, and filtering out illegal syntax. In some examples, a language model can be called to implement the preprocessing of the target code. In some embodiments, the configured resources can also be checked. For example, if the target component library is not in the target manifest and is not deployed in the sandbox, the code cannot be executed. In some embodiments, the code is wrapped within the sandbox, such as adding try and catch statements, which can capture error events when the code execution has errors.
[0063] At 506, the index of the component library is linked to the target code, so that the target code knows the location of the component library in the sandbox. At 508, the target code is executed. The corresponding execution engine is started according to the code type, while the use of resources such as CPU, memory, etc. is strictly limited by the resources allocated to the target code to prevent abnormal consumption of system resources such as infinite loops. At 510, the execution result of the target code is obtained.
[0064] At the same time, Figure 3 The task tracker 320 shown in FIG. 3 can track the execution of the code in its entirety. At 512, a unique task identifier is generated for the target sandbox, and information related to the target sandbox is associated with the task identifier. At 514, the task status is recorded, including the operations at 502, 504, 506, and 510. In some embodiments, if the target code is being executed, the status of the task identifier is determined to be running. In some embodiments, if the target code is executed, the status of the task identifier is determined to be complete. In some embodiments, if the target code is interrupted by an interrupt operation, the status of the task identifier is determined to be aborted. In some embodiments, if the target code has an error during execution, the status of the task identifier is determined to be an error. In this way, the user can clearly see the status of the current task.
[0065] At 516, a timeout timer is set for the task identification, which stores the maximum execution time of the target code. In some embodiments, the time that the target code has executed is monitored during the execution of the code. In some embodiments, the timeout timer is used to detect whether the execution of the target code has timed out. In some embodiments, if the execution of the target code times out, the execution of the code is interrupted and an alert message is provided. In some embodiments, a differentiated timeout policy is set according to the type of environment, for example, the default timeout time for a debugging environment is 30 seconds and the timeout time for a production environment is 60 seconds. When it is detected that the execution time of the code exceeds the threshold, a signal is sent to the sandbox process to interrupt the execution, and a timeout event and a resource occupation snapshot are recorded in the database. In this embodiment, multiple interruption operations are used to interrupt the execution of the code in different dimensions (such as time, various hardware resources), which can improve the security of the server.
[0066] At 518, the status of the task identification is detected, and if the status is complete or error, the resources allocated to the target sandbox are recovered. At 520, all events tracked are reported to the user, including the timestamp of the status of each task, whether it times out, the resource cleaning situation, etc. This embodiment has multiple benefits through the double-flow design of code execution and task tracking. Through the syntax filtering and exception wrapping mechanism of the preprocessing stage, the code execution error rate is reduced. In addition, the overly complex target code is interrupted through the timeout control, ensuring the stability and security of the server.
[0067] Figure 6 A schematic diagram of a monitor according to an embodiment of the present disclosure is shown. The monitor 602 can include a time monitor 604, a memory monitor 606, a GPU monitor 608, an interrupter 610, and a resource overrun processor 612. The time monitor 604 can monitor the time from when the server receives a user request to when a response is made. The response can be a response to any action in the request, such as the timestamp of creating a sandbox, the timestamp of executing the code, and so on. The memory monitor 606 can monitor the memory resources consumed during the execution of the code. The GPU monitor 608 can monitor the number of GPUs consumed during the execution of the code.
[0068] In order to efficiently process the monitored data, the data can be stored in a database. In some embodiments, a database service is requested from the user. The database service can be used to create a database instance. In some embodiments, the target database is initialized using the database service. In some embodiments, the consumed target hardware resources are stored in the target database, such as the size of the consumed memory, the number of occupied GPUs, etc. In some embodiments, data for the target hardware resources is extracted from the target database in response to a query for the target hardware resources. In this way, the user can view the consumption of any resource.
[0069] Resource overrun processor 612 can manage the cooperation between memory monitor 606, GPU monitor 608, and interrupter 610. In some embodiments, memory monitor 606 uses a first application programming interface to obtain the target hardware resource consumed by the target code. In some embodiments, a limit for the target hardware resource is obtained. In some embodiments, if the consumption of the target hardware resource exceeds the limit, the execution of the target code is interrupted in the target sandbox. For example, memory monitor 606 uses a corresponding API to obtain the memory consumed during the execution of the code. Resource overrun processor 612 obtains the limit for the memory and determines whether the consumption of the memory exceeds the limit. If the limit is exceeded, resource overrun processor 612 instructs interrupter 610 to interrupt the execution of the code and records the reason for the interruption. In this embodiment, by setting the monitor, it can be ensured that the code in the sandbox does not occupy too many server resources and does not spend too much execution time, which can ensure the security and stability of the server.
[0070] Figure 7 A schematic diagram of a statistical performance indicator is shown according to an embodiment of the present disclosure. At 702, user requests are collected. In some embodiments, user requests are captured in real time by the service middleware layer. In some embodiments, request data contains complete HTTP / HTTPS protocol information, such as request method (GET / POST), URL path, request header (containing user authentication token, device identification), request body (code text or form data), etc. At 704, response information is collected. In some embodiments, a second application programming interface is used to determine the response time of the response information. For example, the time from receiving a user request to executing the code can be used as the response time. In addition, the response time of each sub-process can also be recorded, such as the response time of successfully creating a sandbox, etc. In some embodiments, a third application programming interface is used to determine the data volume of the response information. The data volume can be the data volume of various data of the sandbox response. In some embodiments, user requests, response time, and data volume are stored in a target database. In this way, users can understand the execution process of the code from the perspective of the whole life cycle.
[0071] At 706, user requests and response information are summarized, and user requests and response information (including response time of response information and data volume of response information) are aggregated in real time. In some embodiments, the request and response information of the same task are associated by request identification (such as UUID), and a complete transaction log is constructed. In some embodiments, for batch processing scenarios, aggregation is triggered according to a time window (such as every 5 minutes) or a data volume threshold (such as 100,000 records), to ensure data consistency. In some embodiments, the aggregation result is stored in a database for quick sorting and retrieval by timestamp.
[0072] At 708, performance indicators for the user request are calculated. In some embodiments, multiple performance indicators can be calculated. For example, basic indicators such as response time of each operation, maximum / minimum response time, throughput (number of requests processed per second) can be calculated. In some embodiments, resource indicators can be calculated, combining resource monitor data of the sandbox management system (such as CPU usage, memory occupation), to calculate resource consumption for the user request. In some embodiments, abnormal indicators can be calculated, counting the frequency of occurrence of different types of error codes. At 710, sensitive information is filtered, including filtering out the user's password, identity information and other private information, so that the remaining information complies with relevant regulations. At 712, the user request, response information, performance indicators and other data are stored in the database for the user to view. In this embodiment, a multi-faceted monitoring function is provided, which facilitates the user to monitor the execution of the code from multiple angles, thereby ensuring the security and stability of the server.
[0073] Figure 8 A schematic block diagram of an apparatus 800 for executing code according to some embodiments of the present disclosure is shown. The apparatus 800 for executing code can be implemented by software, hardware or a combination of both. As shown, the apparatus 800 includes a sandbox allocation module 810, a component library deployment module 820 and a code execution module 830. Figure 8
[0074] In some embodiments, the sandbox allocation module 810 can be configured to allocate a target sandbox according to a user request. The component library deployment module 820 can be configured to deploy a target component library called by a target code in the target sandbox based on the user request. The code execution module 830 can be configured to execute the target code in the target sandbox in response to the target component library being deployed.
[0075] In some embodiments, the sandbox allocation module 810 includes a first determination module configured to determine an environment type for executing the target code according to the user request, a second determination module configured to determine a sandbox service according to the environment type, and a creation module configured to create the target sandbox by invoking the sandbox service.
[0076] In some embodiments, the user request includes a target domain name, and the apparatus 800 further includes a resolution module configured to resolve the target domain name in the user request to obtain a target address, and a first acquisition module configured to acquire the target code from the target address.
[0077] In some embodiments, the component library deployment module 820 includes a second determination module configured to determine the request for the target component library based on the target code; a third determination module configured to determine the acquisition address of the target component library in response to the target component library being in the target list; a second acquisition module configured to acquire the target component library according to the acquisition address; and a first injection module configured to inject the target component library into the target sandbox.
[0078] In some embodiments, the apparatus 800 further includes a first interruption module configured to interrupt the determination of the acquisition address of the target component library in response to the target component library not being in the target list; and a first warning module configured to provide warning information for the target code.
[0079] In some embodiments, the apparatus 800 further includes a cache module configured to save the target component library in a cache area; and a second injection module configured to inject the target component library into the second sandbox in response to the second sandbox requiring the deployment of the target component library.
[0080] In some embodiments, the target code calls a target component of a server built-in component library, the target list includes a component list for the server built-in component library, and the component library deployment module 820 includes a fourth determination module configured to determine the target component of the server built-in component library called by the target code based on the user request; a second deployment module configured to deploy the target component in the target sandbox in response to the target component being recorded in the target list; and a second warning module configured to provide warning information in response to the target component not being recorded in the target list.
[0081] In some embodiments, the code execution module 830 includes a third acquisition module configured to acquire the target hardware resource consumed by the target code using a first application programming interface; a fourth acquisition module configured to acquire the limit for the target hardware resource; and a second interruption module configured to interrupt the execution of the target code in the target sandbox in response to the consumption of the target hardware resource exceeding the limit.
[0082] In some embodiments, the apparatus 800 further includes a second allocation module configured to request the allocation of a database service to the user; an initialization module configured to initialize a target database using the database service; a first storage module configured to store the consumed target hardware resource into the target database; and an extraction module configured to extract the data for the target hardware resource from the target database in response to a query for the target hardware resource.
[0083] In some embodiments, the apparatus 800 further comprises a fifth obtaining module configured to obtain response information for a user request; a fifth determining module configured to determine a response time of the response information using a second application programming interface; a sixth determining module configured to determine a data volume of the response information using a third application programming interface; and a second storing module configured to store the user request, the response time, and the data volume into a target database.
[0084] In some embodiments, the apparatus 800 further comprises an identification generating module configured to generate a task identification for a target sandbox; a first identification module configured to determine a state of the task identification as running in response to the target code being executed; a second identification module configured to determine the state of the task identification as completed in response to the target code being executed completely; a third identification module configured to determine the state of the task identification as aborted in response to the target code being interrupted by an interrupt operation; and a fourth identification module configured to determine the state of the task identification as error in response to the target code reporting an error during execution.
[0085] In some embodiments, the apparatus 800 further comprises a setting module configured to set a timeout timer for the task identification; a time monitoring module configured to monitor a time of execution of the target code; a timeout detecting module configured to detect whether the execution of the target code is timed out using the timeout timer; and a third interrupting module configured to interrupt the execution of the code and provide an alarm information in response to the execution of the target code being timed out.
[0086] In some embodiments, the apparatus 800 further comprises a state detecting module configured to detect a state of the task identification; and a recycling module configured to recycle resources allocated to the target sandbox in response to the state being completed or error.
[0087] The division of the modules or units in the embodiments of the present disclosure is illustrative, and is merely a logical function division. In actual implementation, another division manner can be used. In addition, each functional unit in the disclosed embodiments can be integrated into one unit, or can be physically separated, or two or more units can be integrated into one unit. The integrated unit can be implemented in the form of hardware, or in the form of a software functional unit.
[0088] Figure 9 A block diagram of an example device 900 that can be used to implement embodiments of the present disclosure is shown. It should be understood that Figure 9 The device 900 shown is merely an example and should not be construed as limiting the functionality and scope of the implementations described herein. For example, the device 900 can correspond to the servers described herein in connection with Figure 1 the implementations described above, and can be used to perform the functions described above. Figures 1-2 ,Figures 4-6 , and Figure 7 the process of the third aspect of the summary. For another example, the device 900 can correspond to the electronic device of the third aspect of the summary.
[0089] As shown in Figure 9 , the device 900 is in the form of a general-purpose computing device. Components of the device 900 can include, but are not limited to, one or more processors or processing units 910, a memory 920, a storage device 930, one or more communication units 940, one or more input devices 950, and one or more output devices 960. The processing unit 910 can be a real or virtual processor and is capable of executing various processing in accordance with programs stored in the memory 920. In a multi-processing system, multiple processing units execute computer-executable instructions in parallel to improve the processing power of the device 900.
[0090] The device 900 typically includes a plurality of computer storage media. Such media can be any available media that is accessible by the device 900 and includes both volatile and non-volatile media, removable and non-removable media. The memory 920 can be a volatile memory (e.g., registers, cache, random access memory (RAM)), a non-volatile memory (e.g., read only memory (ROM), electrically erasable programmable read only memory (EEPROM), flash memory), or some combination thereof. The storage device 930 can be a removable or non-removable media and can include machine-readable media such as a flash drive, a magnetic disk drive, or any other media that can be used to store information and / or data (e.g., training data for training) and that can be accessed by the device 900.
[0091] The device 900 can further include additional removable / non-removable, volatile / non-volatile storage media. Although not shown in Figure 9 , a disk drive for reading from or writing to a removable, non-volatile magnetic disk (e.g., a "floppy disk"), and an optical disk drive for reading from or writing to a removable, non-volatile optical disk (e.g., a CD-ROM) can be provided. In these instances, each drive can be connected to the bus (not shown) by one or more data media interfaces. The memory 920 can include a computer program product 925 having one or more program modules configured to carry out the various methods or actions of the various implementations of the present disclosure.
[0092] The communication units 940 enable communications with other computing devices over a communication medium. Additionally, the functionality of the components of device 900 can be implemented in a single computing cluster or a plurality of computer machines that are capable of communicating with each other through a communication connection. Thus, device 900 can operate in a networked environment using logical connections to one or more other servers, network personal computers (PCs), or another network nodes in the networking environment.
[0093] The input device 950 can be one or more input devices, such as a mouse, a keyboard, a trackball, etc. The output device 960 can be one or more output devices, such as a display, a speaker, a printer, etc. The device 900 can also communicate with one or more external devices (not shown) such as a storage device, a display device, etc. through the communication unit 940, as needed, communicate with one or more devices that enable a user to interact with the device 900, or any devices (e.g., a network card, a modem, etc.) that enable the device 900 to communicate with one or more other computing devices. Such communication can be carried out through an Input / Output (I / O) interface (not shown).
[0094] According to example implementations of the present disclosure, a computer readable storage medium is provided having computer executable instructions stored thereon, where the computer executable instructions are executed by a processor to implement the method described above. According to example implementations of the present disclosure, a computer program product is also provided that is tangibly stored on a non-transitory computer readable medium and includes computer executable instructions, where the computer executable instructions are executed by a processor to implement the method described above. According to example implementations of the present disclosure, a computer program product is provided having a computer program stored thereon, which when executed by a processor implements the method described above.
[0095] Various aspects of the disclosure are described herein with reference to flowchart illustrations and / or block diagrams of methods, apparatuses, and computer program products according to this disclosure. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer readable program instructions.
[0096] The computer readable program instructions can also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable apparatus or other device to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide processes for implementing the functions / acts specified in the flowchart and / or block diagram block or blocks.
[0097] The computer readable program instructions can also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable apparatus or other device to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide processes for implementing the functions / acts specified in the flowchart and / or block diagram block or blocks.
[0098] The computer readable program instructions can also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable apparatus or other device to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide processes for implementing the functions / acts specified in the flowchart and / or block diagram block or blocks.
[0099] The implementations of the disclosure have been described above with the intent to be illustrative rather than limiting. Although being shown in only a few of the various implementations, the principle of each implementation can be extended to any other implementation. Some of the present implementations have also been described with the intent to be illustrative rather than restrictive. Many modifications and variations of the described implementations are possible in light of the above teachings. It is therefore contemplated that the application can encompass modifications and variations provided they come within the scope of the following claims. It is also contemplated that the implementing specific electric circuitry such as, for example, application specific integrated circuits (ASICs) can implement one or more of the described implementations. It is therefore accurate that the claims are framed to encompass both the specific examples disclosed and also the generic implementations so disclosed.
Claims
1. A method for executing code, comprising: Assign target sandbox based on user request; Deploying a target component library called by the target code in the target sandbox based on the user request; as well as In response to the target component library being deployed, the target code is executed in the target sandbox.
2. The method according to claim 1, wherein allocating a target sandbox according to a user request comprises: Determining the environment type for executing the target code according to the user request; Determining a sandbox service based on the environment type; as well as The target sandbox is created by calling the sandbox service.
3. The method according to claim 1, wherein the user request includes a target domain name, and the method further comprises: Resolving the target domain name in the user request to obtain a target address; as well as The target code is obtained from the target address.
4. The method according to claim 1, wherein deploying the target component library called by the target code in the target sandbox based on the user request comprises: determining a request for the target component library based on the target code; In response to the target component library being in the target list, determining an acquisition address of the target component library; Acquire the target component library according to the acquisition address; as well as Inject the target component library into the target sandbox.
5. The method according to claim 4, further comprising: In response to the target component library not being in the target list, interrupting the determination of the acquisition address of the target component library; as well as Providing warning information for the target code.
6. The method according to claim 5, further comprising: Storing the target component library in a cache area; as well as In response to the second sandbox needing to deploy the target component library, the target component library is injected into the second sandbox.
7. The method according to claim 1, wherein the target code calls a target component of a server built-in component library, and based on the user request, deploying the target component library called by the target code in the target sandbox comprises: Determining, based on the user request, a target component of the server built-in component library called by the target code; In response to the target component being recorded in the target manifest, deploying the target component in the target sandbox; as well as In response to the target component not being recorded in the target list, a warning message is provided.
8. The method of claim 1 , wherein in response to the target component library being deployed, executing the target code in the target sandbox comprises: Using a first application programming interface to obtain target hardware resources consumed by the target code; Obtaining constraints on the target hardware resources; as well as In response to consumption of the target hardware resource exceeding the limit, execution of the target code is interrupted in the target sandbox.
9. The method according to claim 8, further comprising: allocating database services to the user request; Initialize the target database using the database service; storing the consumed target hardware resources in the target database; as well as In response to a query for the target hardware resource, data for the target hardware resource is extracted from the target database.
10. The method according to claim 9, further comprising: Obtaining response information for the user request; determining a response time of the response information using a second application programming interface; determining the data volume of the response information using a third application programming interface; as well as The user request, the response time, and the data volume are stored in the target database.
11. The method according to claim 1 , further comprising: Generate a task identifier for the target sandbox; In response to the object code being executed, determining the state of the task identifier as running; In response to the target code being executed to completion, determining the status of the task identifier as completed; In response to the target code being interrupted by an interrupt operation, determining the state of the task identification as suspended; as well as In response to the target code reporting an error during execution, the status of the task identifier is determined to be an error.
12. The method according to claim 11, further comprising: Setting a timeout timer for the task identifier; monitoring the time the object code has been executed; Using the timeout timer to detect whether the execution of the target code has timed out; as well as In response to the execution of the target code timing out, the execution of the code is interrupted and warning information is provided.
13. The method according to claim 11, further comprising: detecting a status of the task identifier; as well as In response to the status being completed or error, reclaiming resources allocated to the target sandbox.
14. An apparatus for executing code, comprising: a sandbox allocation module configured to allocate a target sandbox according to a user request; A component library deployment module configured to deploy a target component library called by the target code in the target sandbox based on the user request; as well as The code execution module is configured to execute the target code in the target sandbox in response to the target component library being deployed.
15. An electronic device comprising: at least one processing unit; At least one memory coupled to the at least one processing unit and storing instructions for execution by the at least one processing unit, the instructions, when executed by the at least one processing unit, causing the electronic device to perform the method according to any one of claims 1 to 13.
16. A computer program product having a computer program stored thereon, wherein when the computer program is executed by a processor, the method according to any one of claims 1 to 13 is implemented.