CN114117409A - User code operation method and device, electronic equipment and storage medium - Google Patents

User code operation method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN114117409A
CN114117409A CN202111392308.1A CN202111392308A CN114117409A CN 114117409 A CN114117409 A CN 114117409A CN 202111392308 A CN202111392308 A CN 202111392308A CN 114117409 A CN114117409 A CN 114117409A
Authority
CN
China
Prior art keywords
user code
running
interface
environment
sandbox
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Withdrawn
Application number
CN202111392308.1A
Other languages
Chinese (zh)
Inventor
卞荣辉
张晓军
郑聪瑶
张宁
邹雨竹
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Sensetime Lingang Intelligent Technology Co Ltd
Original Assignee
Shanghai Sensetime Lingang Intelligent Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Sensetime Lingang Intelligent Technology Co Ltd filed Critical Shanghai Sensetime Lingang Intelligent Technology Co Ltd
Priority to CN202111392308.1A priority Critical patent/CN114117409A/en
Publication of CN114117409A publication Critical patent/CN114117409A/en
Priority to PCT/CN2022/093860 priority patent/WO2023087642A1/en
Withdrawn legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/50Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems
    • G06F21/52Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems during program execution, e.g. stack integrity ; Preventing unwanted data erasure; Buffer overflow
    • G06F21/53Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems during program execution, e.g. stack integrity ; Preventing unwanted data erasure; Buffer overflow by executing in a restricted environment, e.g. sandbox or secure virtual machine

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • User Interface Of Digital Computer (AREA)

Abstract

The disclosure relates to a user code running method and device, electronic equipment and a storage medium. The method comprises the following steps: creating a sandbox in a host program, and adding a running environment in the sandbox; acquiring a user code; adding a state perception interface aiming at the user code, wherein the state perception interface is used for perceiving the running state of the user code; and the host program responds to a user code operation request, deploys the user code in the operation environment for operation, and acquires the operation state information of the user code through the state perception interface.

Description

User code operation method and device, electronic equipment and storage medium
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a method and an apparatus for running a user code, an electronic device, and a storage medium.
Background
With the popularization of Artificial Intelligence (AI), Artificial Intelligence programming education is also becoming an important component of K12 education, higher education, professional education, etc., and Artificial Intelligence programming platforms (e.g., Web application-based Artificial Intelligence programming platforms, etc.) are important infrastructures in the field of Artificial Intelligence programming education.
Generally, on an artificial intelligence programming platform, a user can edit codes, run the codes and view results for many times. The mode of the artificial intelligence programming platform for operating the user code has important significance for programming and learning of the user and the like.
Disclosure of Invention
The present disclosure provides a technical scheme for running user codes.
According to an aspect of the present disclosure, there is provided a method for running user code, including:
creating a sandbox in a host program, and adding a running environment in the sandbox;
acquiring a user code;
adding a state perception interface aiming at the user code, wherein the state perception interface is used for perceiving the running state of the user code;
and the host program responds to a user code operation request, deploys the user code in the operation environment for operation, and acquires the operation state information of the user code through the state perception interface.
The sandbox is created in the host program, the operating environment is added in the sandbox, the user code is obtained, the state perception interface is added for the user code, the host program responds to the user code operating request, the user code is deployed in the operating environment to operate, and the operating state information of the user code is obtained through the state perception interface, so that the sandbox can be linked with the host program on the premise that an isolation environment is provided for the user code and the host program is protected, the host program can obtain the operating state of the user code in the sandbox, and therefore programming learning or programming teaching of a user is facilitated.
In one possible implementation, after the obtaining the running state information of the user code through the state-aware interface, the method further includes:
and the host program responds to the running state information with a corresponding preset action and executes the preset action.
In this implementation manner, after the running state information of the user code is acquired through the state sensing interface, the host program responds to the running state information having the corresponding preset action, and executes the preset action, so that the host program can acquire the running state of the user code in the sandbox and trigger the preset action, thereby facilitating the programming learning or the programming teaching of the user.
In one possible implementation form of the method,
after the obtaining the user code, prior to the adding a state-aware interface for the user code, the method further comprises: compiling the user code to obtain a compiled user code;
adding a state-aware interface to the user code, comprising: adding a state perception interface aiming at the compiled user code;
the host program responds to a user code running request, deploys the user code in the running environment to run, and obtains the running state information of the user code through the state perception interface, wherein the running state information comprises: and the host program responds to a user code running request, deploys the compiled user code in the running environment for running, and obtains the running state information of the compiled user code through the state perception interface.
According to the implementation mode, the compiled user code is obtained by compiling the user code, the state perception interface is added for the compiled user code, the host program responds to the user code running request, the compiled user code is deployed in the running environment of the sandbox to run, and the running state information of the compiled user code is obtained through the state perception interface, so that the host program can be protected from being damaged by the user code in the sandbox, the probability of the host program being jammed, crashed and the like due to the running of the user code in the sandbox is reduced, and the robustness and the stability of the host program can be improved.
As an example of this implementation,
the compiling the user code to obtain a compiled user code includes: the host program responds to a user code operation request, calls an operation interface, and compiles the user code through the operation interface to obtain a compiled user code;
adding a state-aware interface to the compiled user code, comprising: adding a state perception interface for the compiled user code through the running interface;
responding to a user code running request by the host program, deploying the compiled user code in the running environment for running, wherein the running environment comprises the following steps: and deploying the compiled user code in the running environment through the running interface to run.
The host program calls the running interface to compile the user code, the state perception interface is added aiming at the compiled user code, and the compiled user code is deployed in the running environment of the sandbox to run, so that the convenience of running the user code in the sandbox can be further improved.
In one possible implementation, the adding a running environment in the sandbox includes:
and the host program responds to the operation environment adding request, calls an adding interface and adds the operation environment in the sandbox through the adding interface.
In the implementation mode, the host program responds to the running environment adding request, the adding interface is called, and the running environment is added into the sandbox through the adding interface, so that the host program can conveniently add the running environment into the sandbox through the adding interface, and convenience of adding the running environment into the sandbox can be improved.
In one possible implementation, the method further includes:
and the host program responds to the running environment reset request, calls a reset interface and restores the running environment to an initial state through the reset interface.
In the implementation mode, the host program responds to the running environment reset request, the reset interface is called, and the running environment in the sandbox is restored to the initial state through the reset interface, so that the user code can run again in the reset running environment according to the user requirement, namely, the independent running of the user code can be realized, and the running of the user code is not influenced by the previous running.
In one possible implementation, the method further includes:
and the host program responds to the operating environment deleting request, calls a deleting interface and deletes the operating environment in the sandbox through the deleting interface.
The host program responds to the operating environment deleting request, the deleting interface is called, and the operating environment in the sandbox is deleted through the deleting interface, so that the host program can conveniently delete the operating environment in the sandbox through the deleting interface, namely, the convenience of deleting the operating environment in the sandbox can be improved.
In one possible implementation, after the obtaining the running state information of the user code through the state-aware interface, the method further includes:
and under the condition that the running state information indicates that the running state of the user code is normally finished, responding to the re-received user code running request, and running the user code again in the running environment after the user code is run last time.
In this implementation manner, when the running state of the user code is normally finished, if the running environment reset request is not received, the change result of the running environment in the sandbox may be maintained, so that the user code runs in the changed running environment, and thus the user code can run in a continuous context.
In one possible implementation, after the obtaining the running state information of the user code through the state-aware interface, the method further includes:
acquiring the modified user code;
and under the condition that the running state information indicates that the running state of the user code is normally finished, responding to the re-reception of the user code running request, and running the modified user code in the running environment after the user code is run last time.
In this implementation manner, when the running state of the user code is normally finished, if the running environment reset request is not received, the change result of the running environment in the sandbox may be maintained, so that the modified user code runs in the changed running environment, and thus the user code before and after modification runs in a continuous context.
According to an aspect of the present disclosure, there is provided a user code execution apparatus, including:
the sandbox creating module is used for creating a sandbox in a host program and adding an operating environment into the sandbox;
the first acquisition module is used for acquiring a user code;
the adding module is used for adding a state perception interface aiming at the user code, wherein the state perception interface is used for perceiving the running state of the user code;
and the first running module is used for responding to a user code running request by the host program, deploying the user code in the running environment for running, and acquiring the running state information of the user code through the state perception interface.
In one possible implementation, the apparatus further includes:
and the execution module is used for responding to the running state information by the host program and executing the preset action.
In one possible implementation form of the method,
the device further comprises: the compiling module is used for compiling the user code to obtain a compiled user code;
the adding module is used for: adding a state perception interface aiming at the compiled user code;
the first operation module is used for: and the host program responds to a user code running request, deploys the compiled user code in the running environment for running, and obtains the running state information of the compiled user code through the state perception interface.
In one possible implementation form of the method,
the compiling module is configured to: the host program responds to a user code operation request, calls an operation interface, and compiles the user code through the operation interface to obtain a compiled user code;
the adding module is used for: adding a state perception interface for the compiled user code through the running interface;
the first operation module is used for: and deploying the compiled user code in the running environment through the running interface to run.
In one possible implementation, the sandbox creation module is configured to:
and the host program responds to the operation environment adding request, calls an adding interface and adds the operation environment in the sandbox through the adding interface.
In one possible implementation form of the method,
the device further comprises: the exposure module is used for externally exposing the running code interface corresponding to the sandbox;
the first operation module is used for: and the host program responds to a user code operation request, calls the operation code interface, and deploys the user code in the operation environment through the operation code interface to operate.
In one possible implementation, the apparatus further includes:
and the reset module is used for responding to a running environment reset request by the host program, calling a reset interface and restoring the running environment to an initial state through the reset interface.
In one possible implementation, the apparatus further includes:
and the deleting module is used for responding to the operating environment deleting request by the host program, calling a deleting interface and deleting the operating environment in the sandbox through the deleting interface.
In one possible implementation, the apparatus further includes:
and the second running module is used for responding to the re-received user code running request under the condition that the running state information indicates that the running state of the user code is normally finished, and running the user code again in the running environment after the user code is run last time.
In one possible implementation, the apparatus further includes:
the second acquisition module is used for acquiring the modified user code;
and the third running module is used for responding to the re-received user code running request under the condition that the running state information indicates that the running state of the user code is normally finished, and running the modified user code in the running environment after the user code is run last time.
According to an aspect of the present disclosure, there is provided an electronic device including: one or more processors; a memory for storing executable instructions; wherein the one or more processors are configured to invoke the memory-stored executable instructions to perform the above-described method.
According to an aspect of the present disclosure, there is provided a computer readable storage medium having stored thereon computer program instructions which, when executed by a processor, implement the above-described method.
In the embodiment of the disclosure, a sandbox is created in a host program, an operating environment is added to the sandbox, a user code is acquired, a state-aware interface is added to the user code, the host program responds to a user code operating request, deploys the user code in the operating environment to operate, and acquires operating state information of the user code through the state-aware interface, so that the sandbox and the host program can be linked on the premise of providing an isolation environment for the user code and protecting the host program, and the host program can acquire the operating state of the user code in the sandbox, thereby facilitating programming learning or programming teaching for a user.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Other features and aspects of the present disclosure will become apparent from the following detailed description of exemplary embodiments, which proceeds with reference to the accompanying drawings.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the disclosure.
Fig. 1 shows a flowchart of an operating method of user code provided by an embodiment of the present disclosure.
Fig. 2 is a block diagram illustrating an apparatus for executing user code according to an embodiment of the present disclosure.
Fig. 3 illustrates a block diagram of an electronic device 800 provided by an embodiment of the disclosure.
Fig. 4 shows a block diagram of an electronic device 1900 provided by an embodiment of the disclosure.
Detailed Description
Various exemplary embodiments, features and aspects of the present disclosure will be described in detail below with reference to the accompanying drawings. In the drawings, like reference numbers can indicate functionally identical or similar elements. While the various aspects of the embodiments are presented in drawings, the drawings are not necessarily drawn to scale unless specifically indicated.
The word "exemplary" is used exclusively herein to mean "serving as an example, embodiment, or illustration. Any embodiment described herein as "exemplary" is not necessarily to be construed as preferred or advantageous over other embodiments.
The term "and/or" herein is merely an association describing an associated object, meaning that three relationships may exist, e.g., a and/or B, may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the term "at least one" herein means any one of a plurality or any combination of at least two of a plurality, for example, including at least one of A, B, C, and may mean including any one or more elements selected from the group consisting of A, B and C.
Furthermore, in the following detailed description, numerous specific details are set forth in order to provide a better understanding of the present disclosure. It will be understood by those skilled in the art that the present disclosure may be practiced without some of these specific details. In some instances, methods, means, elements and circuits that are well known to those skilled in the art have not been described in detail so as not to obscure the present disclosure.
The embodiment of the disclosure provides a user code running method and device, electronic equipment and a storage medium, wherein a sandbox is created in a host program, a running environment is added into the sandbox to obtain a user code, a state perception interface is added for the user code, the host program responds to a user code running request, deploys the user code in the running environment to run, and obtains running state information of the user code through the state perception interface, so that the sandbox can be linked with the host program on the premise of providing an isolation environment for the user code and protecting the host program, and the host program can obtain the running state of the user code in the sandbox, thereby being beneficial to programming learning or programming teaching of a user.
Fig. 1 shows a flowchart of an operating method of user code provided by an embodiment of the present disclosure. In a possible implementation manner, the running method of the user code may be executed by a terminal device or a server or other processing device. The terminal device may be a User Equipment (UE), a mobile device, a User terminal, a cellular phone, a cordless phone, a Personal Digital Assistant (PDA), a handheld device, a computing device, a vehicle-mounted device, or a wearable device. In some possible implementations, the method of execution of the user code may be implemented by a processor invoking computer readable instructions stored in a memory. As shown in fig. 1, the user code execution method includes steps S11 through S14.
In step S11, a sandbox is created in the host program, and a runtime environment is added to the sandbox.
In step S12, a user code is acquired.
In step S13, adding a state-aware interface for the user code, wherein the state-aware interface is used for sensing the running state of the user code.
In step S14, the host program, in response to a user code running request, deploys the user code in the running environment to run, and obtains the running state information of the user code through the state-aware interface.
The embodiment of the present disclosure may be applied to a Web end, for example, an artificial intelligence programming platform based on a Web application or other programming platforms based on a Web application, and may also be applied to a Personal Computer (PC) end software or a mobile end software, and the like, which is not limited herein.
The host program may represent an application program that uses the sandbox as a child module. In the embodiment of the present disclosure, an arbitrary program selected by a user may be used as a host program, so that a sandbox may be embedded in an arbitrary user flow. A sandbox (also called a sandbox) is a security mechanism that provides an isolated environment in a host program, so as to provide experiments for programs whose source is not trusted, which have destructive power, or which cannot determine the intention of the program, so as to protect the host program.
In one possible implementation, a container node may be placed in the host program, and an iframe (inline frame) may be placed as a sandbox in the container node, where the iframe may be set as a sandbox attribute. Of course, the sandbox may be created in the host program in other ways, which are not limited herein.
In one possible implementation, a sandbox may be created in a host program in response to a sandbox creation request. Wherein the sandbox creation request may be triggered by a user.
In another possible implementation, a sandbox may be created in the host program in response to the host program starting. In this implementation, the sandbox may be automatically created by default upon launching the host program, without being triggered by the user.
The execution environment in the disclosed embodiments may also be referred to as a context, a context environment, an execution context, and the like. The execution environment in the sandbox may represent the environment in the sandbox for executing the user code. The operating environment in the sandbox can be flexibly selected according to the user requirement, and for example, the operating environment can be a browser operating environment based on Windows, MacOS, Linux, Android, iOS or the like.
In one possible implementation, the adding a running environment in the sandbox includes: and the host program responds to the operation environment adding request, calls an adding interface and adds the operation environment in the sandbox through the adding interface. In this implementation, the adding interface may be obtained by encapsulating the function code for adding the execution environment in the sandbox. The add interface can be used to add a runtime environment in the sandbox, and the add interface can be called by the host program. The runtime environment addition request may represent a request to add a runtime environment in a sandbox. The runtime environment addition request may be user triggered. The host program responds to the running environment adding request, the adding interface is called, and the running environment is added into the sandbox through the adding interface, so that the host program can conveniently add the running environment into the sandbox through the adding interface, and convenience of adding the running environment into the sandbox can be improved.
In another possible implementation, the running environment may be automatically added to the sandbox after the sandbox is created in the host program. That is, in this implementation, the runtime environment can be added by default when the sandbox is created, without being triggered by the user.
In embodiments of the present disclosure, a User may edit User code in a User Interface (UI) of a host program. Alternatively, the user code may be obtained from outside the host program, which is not limited herein.
In the embodiment of the present disclosure, the state-aware interface is a program for calling back the running state of the user code, the state-aware interface added for the user code may be implemented by inserting a program for calling back the running state of the user code into the user code, and the running state of the user code may be acquired by calling the state-aware interface. The running state of the user code may be active stop, normal end, abnormal end, running, and the like, which is not limited herein. Wherein, actively stopping may mean stopping according to a user instruction. The host program can call back the running state of the user code in the sandbox through the binding state perception interface.
The host program can respond to the user code running request and inject the user code into the running environment of the sandbox to run. Wherein the user code execution request may be triggered by a user. For example, the host program may determine that a user code execution request is received in response to a preset execution button being triggered; alternatively, the host program may determine that a user code operation request is received in response to receiving a preset operation instruction; and so on. After the user code is deployed in the running environment of the sandbox and runs, the host program can call back the running state of the user code in the sandbox through the state-aware interface, that is, the host program can acquire the running state information of the user code in the sandbox through the state-aware interface. The running state information may be any information capable of representing the running state of the user code in the sandbox.
In one possible implementation, after the obtaining the user code, before the adding the state-aware interface for the user code, the method further includes: compiling the user code to obtain a compiled user code; adding a state-aware interface to the user code, comprising: adding a state perception interface aiming at the compiled user code; the host program responds to a user code running request, deploys the user code in the running environment to run, and obtains the running state information of the user code through the state perception interface, wherein the running state information comprises: and the host program responds to a user code running request, deploys the compiled user code in the running environment for running, and obtains the running state information of the compiled user code through the state perception interface. In this implementation manner, the user code may be converted into a Syntax structure such as an Abstract Syntax Tree (AST) to compile the user code, so as to add an operation protection mechanism to the user code. Of course, other compiling manners may be adopted to compile the user code, which is not limited herein. For example, the user code may also be compiled through GCC (GNU Compiler Collection), and an operation protection mechanism may be added to the user code. As another example, the user code may also be compiled by a clone compiler, and an operation protection mechanism may be added to the user code.
In this implementation, the user code may be compiled in response to a user code operation request, and a state awareness interface may be added to the compiled user code; or compiling the user code in response to a user code compiling request, and adding a state-aware interface for the compiled user code, wherein the user code compiling request can be triggered by a user; or, in response to acquiring the user code, compiling the user code, and adding a state perception interface for the compiled user code; and so on.
In the related art, the user code in the sandbox is not compiled, so that the running of the user code in the sandbox may cause the problems of deadlocking, crashing and the like of the host program. According to the implementation mode, the compiled user code is obtained by compiling the user code, the state perception interface is added for the compiled user code, the host program responds to the user code running request, the compiled user code is deployed in the running environment of the sandbox to run, and the running state information of the compiled user code is obtained through the state perception interface, so that the host program can be protected from being damaged by the user code in the sandbox, the probability of the host program being jammed, crashed and the like due to the running of the user code in the sandbox is reduced, and the robustness and the stability of the host program can be improved.
As an example of this implementation, the compiling the user code to obtain a compiled user code includes: the host program responds to a user code operation request, calls an operation interface, and compiles the user code through the operation interface to obtain a compiled user code; adding a state-aware interface to the compiled user code, comprising: adding a state perception interface for the compiled user code through the running interface; responding to a user code running request by the host program, deploying the compiled user code in the running environment for running, wherein the running environment comprises the following steps: and deploying the compiled user code in the running environment through the running interface to run. In this example, the run interface may be obtained by encapsulating the compiled user code, adding a state-aware interface to the compiled user code, and deploying the compiled user code in a run environment of the sandbox. The running interface can be called by the host program. The host program calls the running interface to compile the user code, the state perception interface is added aiming at the compiled user code, and the compiled user code is deployed in the running environment of the sandbox to run, so that the convenience of running the user code in the sandbox can be further improved.
In one possible implementation, the method further includes: exposing an operation code interface corresponding to the sandbox to the outside; responding to a user code running request by the host program, deploying the user code in the running environment for running, and comprising the following steps: and the host program responds to a user code operation request, calls the operation code interface, and deploys the user code in the operation environment through the operation code interface to operate. In this implementation, the run code interface may be used to deploy user code into a runtime environment of the sandbox for execution, and the run code interface may be called by the host program. The running code interface corresponding to the sandbox is exposed, the host program responds to the user code running request, calls the running code interface, and deploys the user code in the running environment of the sandbox to run through the running code interface, so that the sandbox can be linked with the host program, the host program can conveniently deploy the user code in the running environment of the sandbox through the running code interface, and can conveniently and repeatedly run the user code and run again after the user code is modified, and convenience in running the user code in the running environment of the sandbox can be improved.
As an example of the implementation manner, the host program responds to a user code operation request, invokes an operation interface, compiles the user code through the operation interface to obtain a compiled user code, adds a state awareness interface to the compiled user code through the operation interface, invokes the operation code interface through the operation interface, and deploys the compiled user code in the operation environment through the operation code interface to operate. In this example, the run interface may be configured to call a run code interface exposed to the outside of the sandbox, and deploy the user code in the run environment of the sandbox through the run code interface to run. According to the example, the host program can conveniently deploy the user code in the sandbox to run through the running interface, namely, the convenience of running the user code in the sandbox can be improved.
In another possible implementation, the user may edit the user code in a user interface of the sandbox and may control the execution of the user code in the sandbox.
In one possible implementation, after the obtaining the running state information of the user code through the state-aware interface, the method further includes: and the host program responds to the running state information with a corresponding preset action and executes the preset action.
In this implementation, the preset action may represent a preset action triggered based on the operating state. The preset action may be a user-defined action or a default action, and is not limited herein. Whether the running state information of the user code has the corresponding preset action or not can be judged according to the corresponding relation between the running state and the preset action. The number of the preset actions corresponding to any one operation state can be 0, 1 or more than 2.
The host program can respond to the running state information of the user code and have corresponding preset actions, and the preset actions are executed, so that different preset actions can be triggered when the running of the user code enters different states. For example, the preset action may include displaying an error prompt message, displaying an operating state, recording an operating log, and the like. The display error prompt information can be used for displaying prompt information of an error code in the user code, the display running state can be used for displaying the current running state of the user code, and the record running log can be used for recording the log of the current running of the user code. For example, if the running state information indicates that the running state of the user code is normally finished, the corresponding preset action may include displaying the running state; if the running state information indicates that the running state of the user code is abnormally finished, the corresponding preset action can comprise displaying error prompt information, displaying the running state and recording a running log; if the running state information indicates that the running state of the user code is in running, the corresponding preset action may include displaying the running state. The host program responds to the running state information of the user code and has a corresponding preset action, and the preset action is executed, so that user guidance can be performed in time, and interactivity in the teaching process is improved.
In this implementation manner, after the running state information of the user code is acquired through the state sensing interface, the host program responds to the running state information having the corresponding preset action, and executes the preset action, so that the host program can acquire the running state of the user code in the sandbox and trigger the preset action, thereby facilitating the programming learning or the programming teaching of the user.
In one possible implementation, after the obtaining the running state information of the user code through the state-aware interface, the method further includes: and under the condition that the running state information indicates that the running state of the user code is normally finished, responding to the re-received user code running request, and running the user code again in the running environment after the user code is run last time. By running user code in the runtime environment of the sandbox, the runtime environment may be subject to changes. In this implementation manner, when the running state of the user code is normally finished, if the running environment reset request is not received, the change result of the running environment in the sandbox may be maintained, so that the user code runs in the changed running environment, and thus the user code can run in a continuous context.
In one possible implementation, after the obtaining the running state information of the user code through the state-aware interface, the method further includes: acquiring the modified user code; and under the condition that the running state information indicates that the running state of the user code is normally finished, responding to the re-reception of the user code running request, and running the modified user code in the running environment after the user code is run last time. By running user code in the runtime environment of the sandbox, the runtime environment may be subject to changes. In this implementation, after the user code is finished running, the user may modify the user code in the user interface of the host program. Alternatively, the modified user code may be obtained from outside the host program, which is not limited herein. Under the condition that the running state of the user code is normally finished, if the running environment reset request is not received, the changing result of the running environment in the sandbox can be kept, so that the modified user code runs in the changed running environment, and the running of the user code before and after modification in a continuous context can be realized.
In one possible implementation, the method further includes: and the host program responds to the running environment reset request, calls a reset interface and restores the running environment to an initial state through the reset interface. In this implementation, the reset interface may be encapsulated function code that restores the execution environment in the sandbox to an initial state, where the initial state may represent a state in which no user code is executed, i.e., the initial state may represent a state in which no user code is changed. The reset interface may be used to restore the runtime environment in the sandbox to an initial state, and the reset interface may be invoked by the host program. The runtime environment reset request may represent a request to restore the runtime environment in the sandbox to an initial state. The runtime environment reset request may be user triggered. In the implementation mode, the host program responds to the running environment reset request, the reset interface is called, and the running environment in the sandbox is restored to the initial state through the reset interface, so that the user code can run again in the reset running environment according to the user requirement, namely, the independent running of the user code can be realized, and the running of the user code is not influenced by the previous running.
In one possible implementation, the method further includes: and the host program responds to the operating environment deleting request, calls a deleting interface and deletes the operating environment in the sandbox through the deleting interface. In this implementation, the delete interface may be encapsulated with the function code of the runtime environment in the delete sandbox. The delete interface may be used to delete the runtime environment in the sandbox, and the delete interface may be invoked by the host program. The runtime deletion request may represent a request to delete a runtime in a sandbox. The runtime deletion request may be user triggered. The host program responds to the operating environment deleting request, the deleting interface is called, and the operating environment in the sandbox is deleted through the deleting interface, so that the host program can conveniently delete the operating environment in the sandbox through the deleting interface, namely, the convenience of deleting the operating environment in the sandbox can be improved.
In one possible implementation, the method further includes: the host program responds to the operation environment deleting request, calls a deleting interface, and deletes the operation environment in the sandbox through the deleting interface; and the host program responds to the operation environment adding request, calls an adding interface and adds the operation environment in the sandbox through the adding interface. In this implementation, the delete interface may be obtained by encapsulating the function code of the runtime environment of the delete sandbox. The delete interface may be used to delete the runtime environment in the sandbox, the add interface may be used to add the runtime environment in the sandbox, and the delete interface and the add interface may be called by the host program. The runtime deletion request may represent a request to delete a runtime in a sandbox, and the runtime addition request may represent a request to add a runtime in a sandbox. According to the implementation mode, the host program can conveniently replace the running environment in the sandbox by deleting the interface and adding the interface, namely, the convenience of replacing the running environment in the sandbox can be improved.
In one possible implementation, the method further includes: and the host program responds to the operating environment modification request, calls a modification interface and modifies the operating environment in the sandbox through the modification interface. In this implementation, the modification interface may be encapsulated with the function code that modifies the runtime environment in the sandbox. The modification interface may be used to modify the runtime environment in the sandbox, and the modification interface may be invoked by the host program. The runtime environment modification request may represent a request to modify a runtime environment in a sandbox. The runtime environment modification request may be user triggered.
As an example of this implementation, the execution environment modification request may include identification information of the modified execution environment, and the host program may invoke the modification interface in response to the execution environment modification request, and the modification interface modifies the execution environment in the sandbox according to the identification information of the modified execution environment. The identification information of the operating environment may be used to uniquely identify the operating environment, that is, different operating environments may have different identification information. For example, if the running environment modification request includes the identification information a of the running environment, the host program may call the modification interface in response to the running environment modification request, and modify the running environment in the sandbox into the running environment a according to the modified identification information a of the running environment.
As another example of the implementation, the execution environment modification request may include parameter information of the modified execution environment, and the host program may invoke the modification interface in response to the execution environment modification request, and the modification interface modifies the execution environment in the sandbox according to the parameter information of the modified execution environment.
According to the implementation mode, the host program can conveniently modify the running environment in the sandbox through the modification interface, namely, the convenience of modifying the running environment in the sandbox can be improved.
In one possible implementation, the user code in the sandbox may be cleared in response to the user code ending execution. That is, in this implementation, the user code in the sandbox may be cleared each time the user code execution ends. In another possible implementation, the user code in the sandbox may be cleared in response to a user code modification. In another possible implementation, the user code in the sandbox may be cleared in response to a user-triggered clear code request. In another possible implementation, the user code in the sandbox may be cleared in response to a runtime environment reset request.
In another possible implementation, the user code in the sandbox may be cleared in response to a runtime environment delete request.
The embodiment of the disclosure can be applied to application scenes such as online programming, online education, artificial intelligence education, online programming platforms and artificial intelligence scientific and creative platforms.
The following describes a method for running user code provided by the embodiment of the present disclosure through a specific application scenario. In the application scenario, a container node may be placed in a main page host of the web programming platform, and an iframe may be placed as a sandbox in the container node, where the iframe may be set as a sandbox attribute.
The web Programming platform provides a set of APIs (Application Programming interfaces) for sandboxing control. For example, the set of APIs may include add, delete, run, and reset interfaces corresponding to sandboxes. The adding interface can be used for adding an operating environment in the sandbox, the deleting interface can be used for deleting the operating environment in the sandbox, the operating interface can be used for compiling the user code, adding the state perception interface aiming at the compiled user code and calling the externally exposed operating code interface of the sandbox to deploy the compiled user code in the operating environment of the sandbox for operation, and the resetting interface can be used for restoring the operating environment in the sandbox to the initial state. The host program may operate the sandbox through this set of APIs.
The host program can respond to the running environment adding request, call the adding interface and add the running environment in the sandbox. The user may edit the user code in the user interface of the host program. The host program may retrieve the user code through the user interface. The running code interface corresponding to the code in the sandbox may be exposed. The host program can respond to the user code operation request, call an operation interface, compile the user code through the operation interface to obtain the compiled user code, add a state perception interface for the compiled user code through the operation interface, call the operation code interface through the operation interface, and deploy the compiled user code in the operation environment through the operation code interface to operate. The host program can acquire the running state information of the user code through the state perception interface, and can respond to the running state information with corresponding preset actions to execute the preset actions.
By running user code in the runtime environment of the sandbox, the runtime environment may be subject to changes. Under the condition that the running state of the user code is normally finished, if the running environment reset request is not received, the changing result of the running environment in the sandbox can be kept, so that the user code runs in the changed running environment, and the running of the user code in a continuous context can be realized. The host program can also respond to the reset request of the running environment, call a reset interface and restore the running environment to an initial state through the reset interface. In addition, after the user code is modified, the user may also select to run the modified user code in the last maintained execution environment, or may select to run the modified user code in the reset execution environment. Therefore, the running environment in the sandbox can be maintained or reset according to different user requirements, and running of user codes in a continuous or independent running environment can be achieved.
In a programming education platform, by adopting the operation method of the user code provided by the embodiment of the disclosure, the sandbox is subjected to state callback and flexible control, the sandbox can be embedded into any user flow, the user code can be operated in a reset or maintained operation environment, and the presentation of teaching contents is facilitated.
It is understood that the above-mentioned method embodiments of the present disclosure can be combined with each other to form a combined embodiment without departing from the logic of the principle, which is limited by the space, and the detailed description of the present disclosure is omitted. Those skilled in the art will appreciate that in the above methods of the specific embodiments, the specific order of execution of the steps should be determined by their function and possibly their inherent logic.
In addition, the present disclosure also provides an operating apparatus of a user code, an electronic device, a computer-readable storage medium, and a program, which can all be used to implement any one of the operating methods of a user code provided by the present disclosure, and corresponding technical solutions and technical effects can be referred to in corresponding descriptions of the method sections, and are not described again.
Fig. 2 is a block diagram illustrating an apparatus for executing user code according to an embodiment of the present disclosure. As shown in fig. 2, the user code execution device includes:
a sandbox creating module 21, configured to create a sandbox in a host program, and add an operating environment to the sandbox;
a first obtaining module 22, configured to obtain a user code;
an adding module 23, configured to add a state-aware interface to the user code, where the state-aware interface is configured to sense an operating state of the user code;
a first running module 24, configured to, in response to a user code running request, the host program deploys the user code in the running environment to run, and obtains running state information of the user code through the state-aware interface.
In one possible implementation, the apparatus further includes:
and the execution module is used for responding to the running state information by the host program and executing the preset action.
In one possible implementation form of the method,
the device further comprises: the compiling module is used for compiling the user code to obtain a compiled user code;
the adding module 23 is configured to: adding a state perception interface aiming at the compiled user code;
the first operating module 24 is configured to: and the host program responds to a user code running request, deploys the compiled user code in the running environment for running, and obtains the running state information of the compiled user code through the state perception interface.
In one possible implementation form of the method,
the compiling module is configured to: the host program responds to a user code operation request, calls an operation interface, and compiles the user code through the operation interface to obtain a compiled user code;
the adding module 23 is configured to: adding a state perception interface for the compiled user code through the running interface;
the first operating module 24 is configured to: and deploying the compiled user code in the running environment through the running interface to run.
In one possible implementation, the sandbox creating module 21 is configured to:
and the host program responds to the operation environment adding request, calls an adding interface and adds the operation environment in the sandbox through the adding interface.
In one possible implementation form of the method,
the device further comprises: the exposure module is used for externally exposing the running code interface corresponding to the sandbox;
the first operating module 24 is configured to: and the host program responds to a user code operation request, calls the operation code interface, and deploys the user code in the operation environment through the operation code interface to operate.
In one possible implementation, the apparatus further includes:
and the reset module is used for responding to a running environment reset request by the host program, calling a reset interface and restoring the running environment to an initial state through the reset interface.
In one possible implementation, the apparatus further includes:
and the deleting module is used for responding to the operating environment deleting request by the host program, calling a deleting interface and deleting the operating environment in the sandbox through the deleting interface.
In one possible implementation, the apparatus further includes:
and the second running module is used for responding to the re-received user code running request under the condition that the running state information indicates that the running state of the user code is normally finished, and running the user code again in the running environment after the user code is run last time.
In one possible implementation, the apparatus further includes:
the second acquisition module is used for acquiring the modified user code;
and the third running module is used for responding to the re-received user code running request under the condition that the running state information indicates that the running state of the user code is normally finished, and running the modified user code in the running environment after the user code is run last time.
In the embodiment of the disclosure, a sandbox is created in a host program, an operating environment is added to the sandbox, a user code is acquired, a state-aware interface is added to the user code, the host program responds to a user code operating request, deploys the user code in the operating environment to operate, and acquires operating state information of the user code through the state-aware interface, so that the sandbox and the host program can be linked on the premise of providing an isolation environment for the user code and protecting the host program, and the host program can acquire the operating state of the user code in the sandbox, thereby facilitating programming learning or programming teaching for a user.
In some embodiments, functions or modules included in the apparatus provided in the embodiments of the present disclosure may be used to execute the method described in the above method embodiments, and specific implementations and technical effects thereof may refer to the description of the above method embodiments, which are not described herein again for brevity.
Embodiments of the present disclosure also provide a computer-readable storage medium having stored thereon computer program instructions, which when executed by a processor, implement the above-described method. The computer-readable storage medium may be a non-volatile computer-readable storage medium, or may be a volatile computer-readable storage medium.
Embodiments of the present disclosure also provide a computer program, which includes computer readable code, and when the computer readable code runs in an electronic device, a processor in the electronic device executes the above method.
The disclosed embodiments also provide a computer program product comprising computer readable code or a non-volatile computer readable storage medium carrying computer readable code, which when run in an electronic device, a processor in the electronic device performs the above method.
An embodiment of the present disclosure further provides an electronic device, including: one or more processors; a memory for storing executable instructions; wherein the one or more processors are configured to invoke the memory-stored executable instructions to perform the above-described method.
The electronic device may be provided as a terminal, server, or other form of device.
Fig. 3 illustrates a block diagram of an electronic device 800 provided by an embodiment of the disclosure. For example, the electronic device 800 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, or the like terminal.
Referring to fig. 3, electronic device 800 may include one or more of the following components: processing component 802, memory 804, power component 806, multimedia component 808, audio component 810, input/output (I/O) interface 812, sensor component 814, and communication component 816.
The processing component 802 generally controls overall operation of the electronic device 800, such as operations associated with display, telephone calls, data communications, camera operations, and recording operations. The processing components 802 may include one or more processors 820 to execute instructions to perform all or a portion of the steps of the methods described above. Further, the processing component 802 can include one or more modules that facilitate interaction between the processing component 802 and other components. For example, the processing component 802 can include a multimedia module to facilitate interaction between the multimedia component 808 and the processing component 802.
The memory 804 is configured to store various types of data to support operations at the electronic device 800. Examples of such data include instructions for any application or method operating on the electronic device 800, contact data, phonebook data, messages, pictures, videos, and so forth. The memory 804 may be implemented by any type or combination of volatile or non-volatile memory devices such as Static Random Access Memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic or optical disks.
The power supply component 806 provides power to the various components of the electronic device 800. The power components 806 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the electronic device 800.
The multimedia component 808 includes a screen that provides an output interface between the electronic device 800 and a user. In some embodiments, the screen may include a Liquid Crystal Display (LCD) and a Touch Panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive an input signal from a user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundary of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 808 includes a front facing camera and/or a rear facing camera. The front camera and/or the rear camera may receive external multimedia data when the electronic device 800 is in an operation mode, such as a shooting mode or a video mode. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
The audio component 810 is configured to output and/or input audio signals. For example, the audio component 810 includes a Microphone (MIC) configured to receive external audio signals when the electronic device 800 is in an operational mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals may further be stored in the memory 804 or transmitted via the communication component 816. In some embodiments, audio component 810 also includes a speaker for outputting audio signals.
The I/O interface 812 provides an interface between the processing component 802 and peripheral interface modules, which may be keyboards, click wheels, buttons, etc. These buttons may include, but are not limited to: a home button, a volume button, a start button, and a lock button.
The sensor assembly 814 includes one or more sensors for providing various aspects of state assessment for the electronic device 800. For example, the sensor assembly 814 may detect an open/closed state of the electronic device 800, the relative positioning of components, such as a display and keypad of the electronic device 800, the sensor assembly 814 may also detect a change in the position of the electronic device 800 or a component of the electronic device 800, the presence or absence of user contact with the electronic device 800, orientation or acceleration/deceleration of the electronic device 800, and a change in the temperature of the electronic device 800. Sensor assembly 814 may include a proximity sensor configured to detect the presence of a nearby object without any physical contact. The sensor assembly 814 may also include a light sensor, such as a Complementary Metal Oxide Semiconductor (CMOS) or Charge Coupled Device (CCD) image sensor, for use in imaging applications. In some embodiments, the sensor assembly 814 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
The communication component 816 is configured to facilitate wired or wireless communication between the electronic device 800 and other devices. The electronic device 800 may access a wireless network based on a communication standard, such as a wireless network (Wi-Fi), a second generation mobile communication technology (2G), a third generation mobile communication technology (3G), a fourth generation mobile communication technology (4G), a long term evolution of universal mobile communication technology (LTE), a fifth generation mobile communication technology (5G), or a combination thereof. In an exemplary embodiment, the communication component 816 receives a broadcast signal or broadcast related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 816 further includes a Near Field Communication (NFC) module to facilitate short-range communications. For example, the NFC module may be implemented based on Radio Frequency Identification (RFID) technology, infrared data association (IrDA) technology, Ultra Wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
In an exemplary embodiment, the electronic device 800 may be implemented by one or more Application Specific Integrated Circuits (ASICs), Digital Signal Processors (DSPs), Digital Signal Processing Devices (DSPDs), Programmable Logic Devices (PLDs), Field Programmable Gate Arrays (FPGAs), controllers, micro-controllers, microprocessors or other electronic components for performing the above-described methods.
In an exemplary embodiment, a non-transitory computer-readable storage medium, such as the memory 804, is also provided that includes computer program instructions executable by the processor 820 of the electronic device 800 to perform the above-described methods.
Fig. 4 shows a block diagram of an electronic device 1900 provided by an embodiment of the disclosure. For example, the electronic device 1900 may be provided as a server. Referring to fig. 4, electronic device 1900 includes a processing component 1922 further including one or more processors and memory resources, represented by memory 1932, for storing instructions, e.g., applications, executable by processing component 1922. The application programs stored in memory 1932 may include one or more modules that each correspond to a set of instructions. Further, the processing component 1922 is configured to execute instructions to perform the above-described method.
The electronic device 1900 may also include a power component 1926 configured to perform power management of the electronic device 1900, a wired or wireless network interface 1950 configured to connect the electronic device 1900 to a network, and an input/output (I/O) interface 1958. The electronic device 1900 may operate based on an operating system, such as the Microsoft Server operating system (Windows Server), stored in the memory 1932TM) Apple Inc. of the present application based on the graphic user interface operating System (Mac OS X)TM) Multi-user, multi-process computer operating system (Unix)TM) Free and open native code Unix-like operating System (Linux)TM) Open native code Unix-like operating System (FreeBSD)TM) Or the like.
In an exemplary embodiment, a non-transitory computer readable storage medium, such as the memory 1932, is also provided that includes computer program instructions executable by the processing component 1922 of the electronic device 1900 to perform the above-described methods.
The present disclosure may be systems, methods, and/or computer program products. The computer program product may include a computer-readable storage medium having computer-readable program instructions embodied thereon for causing a processor to implement various aspects of the present disclosure.
The computer readable storage medium may be a tangible device that can hold and store the instructions for use by the instruction execution device. The computer readable storage medium may be, for example, but not limited to, an electronic memory device, a magnetic memory device, an optical memory device, an electromagnetic memory device, a semiconductor memory device, or any suitable combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a Static Random Access Memory (SRAM), a portable compact disc read-only memory (CD-ROM), a Digital Versatile Disc (DVD), a memory stick, a floppy disk, a mechanical coding device, such as punch cards or in-groove projection structures having instructions stored thereon, and any suitable combination of the foregoing. Computer-readable storage media as used herein is not to be construed as transitory signals per se, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through a waveguide or other transmission medium (e.g., optical pulses through a fiber optic cable), or electrical signals transmitted through electrical wires.
The computer-readable program instructions described herein may be downloaded from a computer-readable storage medium to a respective computing/processing device, or to an external computer or external storage device via a network, such as the internet, a local area network, a wide area network, and/or a wireless network. The network may include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers and/or edge servers. The network adapter card or network interface in each computing/processing device receives computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in a computer-readable storage medium in the respective computing/processing device.
The computer program instructions for carrying out operations of the present disclosure may be assembler instructions, Instruction Set Architecture (ISA) instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source or object code written in any combination of one or more programming languages, including an object oriented programming language such as Smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The computer-readable program instructions may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider). In some embodiments, the electronic circuitry that can execute the computer-readable program instructions implements aspects of the present disclosure by utilizing the state information of the computer-readable program instructions to personalize the electronic circuitry, such as a programmable logic circuit, a Field Programmable Gate Array (FPGA), or a Programmable Logic Array (PLA).
Various aspects of the present disclosure are described herein with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the 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.
These computer-readable program instructions may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions/acts specified in the flowchart and/or block diagram block or blocks. These computer-readable program instructions may also be stored in a computer-readable storage medium that can direct a computer, programmable data processing apparatus, and/or other devices to function in a particular manner, such that the computer-readable medium storing the instructions comprises an article of manufacture including instructions which implement the function/act specified in the flowchart and/or block diagram block or blocks.
The computer readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other devices to cause a series of operational steps to be performed on the computer, other programmable apparatus or other devices to produce a computer implemented process such that the instructions which execute on the computer, other programmable apparatus or other devices implement the functions/acts specified in the flowchart and/or block diagram block or blocks.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of instructions, which comprises one or more executable instructions for implementing the specified logical function(s). In some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The computer program product may be embodied in hardware, software or a combination thereof. In an alternative embodiment, the computer program product is embodied in a computer storage medium, and in another alternative embodiment, the computer program product is embodied in a Software product, such as a Software Development Kit (SDK), or the like.
Having described embodiments of the present disclosure, the foregoing description is intended to be exemplary, not exhaustive, and not limited to the disclosed embodiments. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is chosen in order to best explain the principles of the embodiments, the practical application, or improvements made to the technology in the marketplace, or to enable others of ordinary skill in the art to understand the embodiments disclosed herein.

Claims (13)

1. A method for executing user code, comprising:
creating a sandbox in a host program, and adding a running environment in the sandbox;
acquiring a user code;
adding a state perception interface aiming at the user code, wherein the state perception interface is used for perceiving the running state of the user code;
and the host program responds to a user code operation request, deploys the user code in the operation environment for operation, and acquires the operation state information of the user code through the state perception interface.
2. The method of claim 1, wherein after the obtaining the running state information of the user code through the state-aware interface, the method further comprises:
and the host program responds to the running state information with a corresponding preset action and executes the preset action.
3. The method according to claim 1 or 2,
after the obtaining the user code, prior to the adding a state-aware interface for the user code, the method further comprises: compiling the user code to obtain a compiled user code;
adding a state-aware interface to the user code, comprising: adding a state perception interface aiming at the compiled user code;
the host program responds to a user code running request, deploys the user code in the running environment to run, and obtains the running state information of the user code through the state perception interface, wherein the running state information comprises: and the host program responds to a user code running request, deploys the compiled user code in the running environment for running, and obtains the running state information of the compiled user code through the state perception interface.
4. The method of claim 3,
the compiling the user code to obtain a compiled user code includes: the host program responds to a user code operation request, calls an operation interface, and compiles the user code through the operation interface to obtain a compiled user code;
adding a state-aware interface to the compiled user code, comprising: adding a state perception interface for the compiled user code through the running interface;
responding to a user code running request by the host program, deploying the compiled user code in the running environment for running, wherein the running environment comprises the following steps: and deploying the compiled user code in the running environment through the running interface to run.
5. The method of any one of claims 1 to 4, wherein adding a running environment in the sandbox comprises:
and the host program responds to the operation environment adding request, calls an adding interface and adds the operation environment in the sandbox through the adding interface.
6. The method according to any one of claims 1 to 5,
the method further comprises the following steps: exposing an operation code interface corresponding to the sandbox to the outside;
responding to a user code running request by the host program, deploying the user code in the running environment for running, and comprising the following steps: and the host program responds to a user code operation request, calls the operation code interface, and deploys the user code in the operation environment through the operation code interface to operate.
7. The method according to any one of claims 1 to 6, further comprising:
and the host program responds to the running environment reset request, calls a reset interface and restores the running environment to an initial state through the reset interface.
8. The method according to any one of claims 1 to 7, further comprising:
and the host program responds to the operating environment deleting request, calls a deleting interface and deletes the operating environment in the sandbox through the deleting interface.
9. The method according to any one of claims 1 to 8, wherein after the obtaining of the running state information of the user code through the state-aware interface, the method further comprises:
and under the condition that the running state information indicates that the running state of the user code is normally finished, responding to the re-received user code running request, and running the user code again in the running environment after the user code is run last time.
10. The method according to any one of claims 1 to 9, wherein after the obtaining of the running state information of the user code through the state-aware interface, the method further comprises:
acquiring the modified user code;
and under the condition that the running state information indicates that the running state of the user code is normally finished, responding to the re-reception of the user code running request, and running the modified user code in the running environment after the user code is run last time.
11. An apparatus for executing a user code, comprising:
the sandbox creating module is used for creating a sandbox in a host program and adding an operating environment into the sandbox;
the first acquisition module is used for acquiring a user code;
the adding module is used for adding a state perception interface aiming at the user code, wherein the state perception interface is used for perceiving the running state of the user code;
and the first running module is used for responding to a user code running request by the host program, deploying the user code in the running environment for running, and acquiring the running state information of the user code through the state perception interface.
12. An electronic device, comprising:
one or more processors;
a memory for storing executable instructions;
wherein the one or more processors are configured to invoke the memory-stored executable instructions to perform the method of any one of claims 1 to 10.
13. A computer readable storage medium having computer program instructions stored thereon, which when executed by a processor implement the method of any one of claims 1 to 10.
CN202111392308.1A 2021-11-19 2021-11-19 User code operation method and device, electronic equipment and storage medium Withdrawn CN114117409A (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202111392308.1A CN114117409A (en) 2021-11-19 2021-11-19 User code operation method and device, electronic equipment and storage medium
PCT/CN2022/093860 WO2023087642A1 (en) 2021-11-19 2022-05-19 User code running method and apparatus, and electronic device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111392308.1A CN114117409A (en) 2021-11-19 2021-11-19 User code operation method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114117409A true CN114117409A (en) 2022-03-01

Family

ID=80439964

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111392308.1A Withdrawn CN114117409A (en) 2021-11-19 2021-11-19 User code operation method and device, electronic equipment and storage medium

Country Status (2)

Country Link
CN (1) CN114117409A (en)
WO (1) WO2023087642A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2023087642A1 (en) * 2021-11-19 2023-05-25 上海商汤智能科技有限公司 User code running method and apparatus, and electronic device and storage medium

Family Cites Families (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8856782B2 (en) * 2007-03-01 2014-10-07 George Mason Research Foundation, Inc. On-demand disposable virtual work system
CN104750537B (en) * 2013-12-31 2020-07-14 腾讯科技(深圳)有限公司 Method and device for executing test case
CN107992308B (en) * 2017-11-22 2020-10-20 竞技世界(北京)网络技术有限公司 Plug-in management method for android terminal application program
US10970390B2 (en) * 2018-02-15 2021-04-06 Intel Corporation Mechanism to prevent software side channels
CN109325345B (en) * 2018-09-21 2022-10-28 百度在线网络技术(北京)有限公司 Method and apparatus for running third party code in a sandbox environment
CN112306566A (en) * 2019-07-15 2021-02-02 阿里巴巴集团控股有限公司 Data processing method and device
CN110688314B (en) * 2019-09-25 2020-12-25 启迪国信(北京)信息技术有限公司 Application performance analysis method and device, electronic equipment and storage medium
CN114117409A (en) * 2021-11-19 2022-03-01 上海商汤临港智能科技有限公司 User code operation method and device, electronic equipment and storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2023087642A1 (en) * 2021-11-19 2023-05-25 上海商汤智能科技有限公司 User code running method and apparatus, and electronic device and storage medium

Also Published As

Publication number Publication date
WO2023087642A1 (en) 2023-05-25

Similar Documents

Publication Publication Date Title
CN108182131B (en) Method and device for monitoring application running state, storage medium and electronic equipment
US9886264B2 (en) Method and device for upgrading firmware
CN106406956B (en) Application program installation method and device
CN111427622B (en) Execution method and device of script codes in application program
CN106991018B (en) Interface skin changing method and device
CN109117144B (en) Page processing method, device, terminal and storage medium
CN111767058A (en) Program compiling method and device, electronic equipment and storage medium
CN114117409A (en) User code operation method and device, electronic equipment and storage medium
CN108762983B (en) Multimedia data recovery method and device
CN109962958B (en) Document processing method and device
CN114035902A (en) Application program development platform and method, electronic device and storage medium
EP3416070A1 (en) Page display method and device and storage medium
CN108469991B (en) Multimedia data processing method and device
CN111858334A (en) Fuzzy testing method and device based on text recognition
CN109992503B (en) Automatic testing method and device
CN111694571A (en) Compiling method and device
CN111290882B (en) Data file backup method, data file backup device and electronic equipment
CN109933357B (en) Application program upgrading method and device
CN113590091A (en) Data processing method and device, electronic equipment and storage medium
CN112860625A (en) Data acquisition method, data storage method, device, equipment and storage medium
CN108959955B (en) File processing method and device
CN111124553B (en) Program execution method, device, terminal and storage medium
CN111596949B (en) Method and device for developing application program
CN113867992B (en) Call chain resource isolation method and device, storage medium and electronic equipment
CN116450534B (en) Method, device, equipment and medium for generating mobile terminal application program

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
REG Reference to a national code

Ref country code: HK

Ref legal event code: DE

Ref document number: 40061478

Country of ref document: HK

WW01 Invention patent application withdrawn after publication
WW01 Invention patent application withdrawn after publication

Application publication date: 20220301