WO2023087642A1 - 用户代码的运行方法及装置、电子设备和存储介质 - Google Patents

用户代码的运行方法及装置、电子设备和存储介质 Download PDF

Info

Publication number
WO2023087642A1
WO2023087642A1 PCT/CN2022/093860 CN2022093860W WO2023087642A1 WO 2023087642 A1 WO2023087642 A1 WO 2023087642A1 CN 2022093860 W CN2022093860 W CN 2022093860W WO 2023087642 A1 WO2023087642 A1 WO 2023087642A1
Authority
WO
WIPO (PCT)
Prior art keywords
user code
running
interface
sandbox
host program
Prior art date
Application number
PCT/CN2022/093860
Other languages
English (en)
French (fr)
Inventor
卞荣辉
张晓军
郑聪瑶
张宁
邹雨竹
Original Assignee
上海商汤智能科技有限公司
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 上海商汤智能科技有限公司 filed Critical 上海商汤智能科技有限公司
Publication of WO2023087642A1 publication Critical patent/WO2023087642A1/zh

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

Definitions

  • the present disclosure relates to the field of computer technology, and in particular to a user code running method and device, electronic equipment and a storage medium.
  • artificial intelligence programming education has gradually become an important part of K12 education, higher education and vocational education, while artificial intelligence programming platforms (such as artificial intelligence based on Web (web) applications Intelligent programming platform, etc.) is an important infrastructure in the field of artificial intelligence programming education.
  • artificial intelligence programming platforms such as artificial intelligence based on Web (web) applications Intelligent programming platform, etc.
  • an artificial intelligence programming platform users can edit the code multiple times, run the code, and view the results.
  • the way the artificial intelligence programming platform runs user code is of great significance to the user's programming learning and other aspects.
  • the present disclosure provides a technical solution for running user codes.
  • a method for running user code including: a host program creates a sandbox in the host program, and adds an operating environment in the sandbox; the host program obtains the user code; The host program adds a state-aware interface to the user code, wherein the state-aware interface is used for the host program to perceive the running state of the user code; The user code is deployed to run in the running environment of the sandbox, and the running state information of the user code is obtained through the state awareness interface.
  • the sandbox is linked with the host program, and the host program can obtain the running status of the user code in the sandbox, thereby helping the user to learn or teach programming.
  • the method further includes: the host program responds to the running state information with a corresponding preset Set an action and execute the preset action.
  • the host program after obtaining the running state information of the user code through the state-aware interface, the host program has a corresponding preset action in response to the running state information, and executes the preset action, so that the host program can obtain the The running state of the user code in the box and trigger the preset action, which is helpful for the user to learn programming or teach programming.
  • the method further includes: compiling the user code to obtain the compiled the user code; the host program adds a state-aware interface to the user code, including: adding a state-aware interface to the compiled user code; the host program deploys the user code in response to a user code running request Running in the running environment of the sandbox, and obtaining the running state information of the user code through the state-aware interface, including: the host program responds to the user code running request, deploying the compiled user code run in the running environment of the sandbox, and obtain the running state information of the compiled user code through the state awareness interface.
  • the compiled user code is obtained by compiling the user code, and a state-aware interface is added to the compiled user code.
  • the host program responds to the user code execution request and deploys the compiled user code to run in the sandbox operating environment. , and obtain the running status information of the compiled user code through the state-aware interface, thereby protecting the host program from being damaged by the user code in the sandbox, and reducing the host program stuck due to the running of the user code in the sandbox , crashes and other problems, which can improve the robustness and stability of the host program.
  • the compiling the user code to obtain the compiled user code includes: the host program responds to the user code running request, calls the running interface, and compiles the user code through the running interface , to obtain the compiled user code;
  • the adding a state-aware interface to the compiled user code includes: adding a state-aware interface to the compiled user code through the running interface;
  • the host program responds to the user A code running request, deploying the compiled user code to run in the sandbox running environment includes: deploying the compiled user code to run in the sandbox running environment through the running interface .
  • Compile user code by calling the running interface from the host program, add a state-aware interface to the compiled user code, and deploy the compiled user code to run in the sandbox running environment, which can further improve the convenience of running user code in the sandbox .
  • the adding a running environment in the sandbox includes: the host program responds to the request for adding a running environment, calls the adding interface, and uses the adding interface in the sandbox Add a running environment.
  • the host program responds to the request for adding the running environment, calls the adding interface, and adds the running environment in the sandbox through the adding interface, so that the host program can conveniently add the running environment in the sandbox through the adding interface,
  • the convenience of adding a running environment in the sandbox can be improved.
  • the method further includes: the host program calls a reset interface in response to the execution environment reset request, and restores the sandbox operation environment to an initial state through the reset interface.
  • the host program calls the reset interface in response to the operating environment reset request, and restores the operating environment in the sandbox to the initial state through the reset interface, so that the user code can It can run again in the reset running environment of the above-mentioned sandbox, that is, the independent running of the user code can be realized, so that the current running of the user code will not be affected by the previous running.
  • the method further includes: the host program calls a deletion interface in response to the deletion request of the runtime environment, and deletes the runtime environment in the sandbox through the deletion interface.
  • the host program responds to the deletion request of the operating environment, calls the deletion interface, and deletes the operating environment in the sandbox through the deletion interface, so that the host program can conveniently delete the operating environment in the sandbox through the deletion interface, that is, It can improve the convenience of deleting the running environment in the sandbox.
  • the method further includes: when the running state information indicates that the running state of the user code is In the case of a normal end, in response to receiving the user code running request again, the user code is run again in the running environment of the sandbox after the user code was run last time.
  • the change result of the running environment in the sandbox can be kept, so that the change of the user code in the sandbox It runs in the subsequent runtime environment, so that user code can run in a continuous context.
  • the method further includes: acquiring the modified user code; when the running status information indicates the If the running state of the user code is normally completed, in response to receiving the user code running request again, the modified user code is run in the running environment of the sandbox after the user code was run last time.
  • the change result of the running environment in the sandbox can be kept, so that the modified user code can run in the sandbox It runs in the changed running environment of the box, so that the user code before and after modification can be run in a continuous context.
  • a device for running user code including: a sandbox creation module, used for a host program to create a sandbox in the host program, and add an operating environment to the sandbox; An acquisition module, used for the host program to acquire user code; an adding module, used for the host program to add a state-aware interface to the user code, wherein the state-aware interface is used for the host program to perceive the user The running state of the code; the first running module is used for the host program to respond to the user code running request, deploy the user code to run in the running environment of the sandbox, and obtain the Running status information for user code.
  • the device further includes: an execution module, configured to execute the preset action when the host program has a corresponding preset action in response to the running state information.
  • the device further includes: a compilation module, configured to compile the user code to obtain the compiled user code; the adding module is configured to: add a state to the compiled user code Awareness interface; the first running module is used for: the host program responds to the user code running request, deploys the compiled user code to run in the sandbox running environment, and uses the state-aware interface Obtain the running status information of the compiled user code.
  • a compilation module configured to compile the user code to obtain the compiled user code
  • the adding module is configured to: add a state to the compiled user code Awareness interface
  • the first running module is used for: the host program responds to the user code running request, deploys the compiled user code to run in the sandbox running environment, and uses the state-aware interface Obtain the running status information of the compiled user code.
  • the compiling module is configured to: the host program calls a running interface in response to a user code running request, compiles the user code through the running interface, and obtains compiled user code;
  • the adding module is used for: adding a state-aware interface to the compiled user code through the running interface;
  • the first running module is used for: deploying the compiled user code in the Runs in a sandbox environment.
  • the sandbox creation module is configured to: the host program calls an adding interface in response to a running environment addition request, and adds a running environment in the sandbox through the adding interface.
  • the device further includes: an exposure module, configured to expose the running code interface corresponding to the sandbox to the outside; the first running module is configured to: the host program responds to user code running request, call the running code interface, and deploy the user code to run in the sandbox running environment through the running code interface.
  • the device further includes: a reset module, configured for the host program to call a reset interface in response to the request for operating environment reset, and restore the operating environment of the sandbox through the reset interface to the initial state.
  • a reset module configured for the host program to call a reset interface in response to the request for operating environment reset, and restore the operating environment of the sandbox through the reset interface to the initial state.
  • the device further includes: a deletion module, configured for the host program to call a deletion interface in response to the runtime environment deletion request, and delete the runtime environment in the sandbox through the deletion interface .
  • a deletion module configured for the host program to call a deletion interface in response to the runtime environment deletion request, and delete the runtime environment in the sandbox through the deletion interface .
  • the device further includes: a second running module, configured to respond to receiving the user code again when the running state information indicates that the running state of the user code is normally completed The execution request is to execute the user code again in the execution environment of the sandbox after the user code was executed last time.
  • a second running module configured to respond to receiving the user code again when the running state information indicates that the running state of the user code is normally completed The execution request is to execute the user code again in the execution environment of the sandbox after the user code was executed last time.
  • the device further includes: a second acquiring module, configured to acquire the modified user code; a third running module, configured to indicate the running status of the user code in the running status information
  • a second acquiring module configured to acquire the modified user code
  • a third running module configured to indicate the running status of the user code in the running status information
  • an electronic device comprising: one or more processors; a memory for storing executable instructions; wherein the one or more processors are configured to call the memory storage executable instructions to perform the above method.
  • a computer-readable storage medium on which computer program instructions are stored, and the above-mentioned method is implemented when the computer program instructions are executed by a processor.
  • a computer program product including computer readable codes, or a non-volatile computer readable storage medium bearing computer readable codes, when the computer readable codes are stored in an electronic device During operation, the processor in the electronic device executes the above method.
  • a sandbox is created in the host program through the host program, an operating environment is added in the sandbox, user code is obtained, and a state-aware interface is added for the user code, and the host program responds to User code running request, deploying the user code to run in the running environment of the sandbox, and obtaining the running status information of the user code through the state awareness interface, thereby providing an isolated environment for the user code,
  • the sandbox and the host program are linked, and the host program can obtain the running status of the user code in the sandbox, which helps users to learn programming or teach programming.
  • Fig. 1 shows a flow chart of a user code running method provided by an embodiment of the present disclosure.
  • Fig. 2 shows a block diagram of a user code running device provided by an embodiment of the present disclosure.
  • FIG. 3 shows a block diagram of an electronic device 800 provided by an embodiment of the present disclosure.
  • FIG. 4 shows a block diagram of an electronic device 1900 provided by an embodiment of the present disclosure.
  • Embodiments of the present disclosure provide a method and device for running user codes, electronic equipment, and a storage medium. Create a sandbox in the host program through the host program, add a running environment in the sandbox, obtain user code, add a state-aware interface for the user code, and the host program responds to the user code running request and converts all The user code is deployed to run in the running environment of the sandbox, and the running status information of the user code is acquired through the state awareness interface.
  • the sandbox can be linked with the host program, and the host program can obtain the running status of the user code in the sandbox, thereby contributing to Users learn programming or teach programming.
  • Fig. 1 shows a flow chart of a user code running method provided by an embodiment of the present disclosure.
  • the user code running method may be executed by a terminal device or a server or other processing device.
  • the terminal device can be user equipment (User Equipment, UE), mobile device, user terminal, cellular phone, cordless phone, personal digital assistant (Personal Digital Assistant, PDA), handheld device, computing device, vehicle-mounted device or wearable device wait.
  • the method for running the user code may be implemented by calling a computer-readable instruction stored in a memory by a processor.
  • the user code running method includes steps S11 to S14.
  • step S11 the host program creates a sandbox in the host program, and adds an operating environment in the sandbox.
  • step S12 the host program obtains the user code.
  • step S13 the host program adds a state-aware interface to the user code, wherein the state-aware interface is used for the host program to perceive the running state of the user code.
  • step S14 the host program responds to the user code running request, deploys the user code to run in the sandbox running environment, and obtains the running state information of the user code through the state awareness interface.
  • Embodiments of the present disclosure can be applied to the Web side, such as an artificial intelligence programming platform based on Web applications or other programming platforms based on Web applications, and can also be applied to PC (Personal Computer, personal computer) software or mobile software. This is not limited.
  • PC Personal Computer, personal computer
  • a host program can represent an application that uses the sandbox as a submodule.
  • any program selected by the user can be used as the host program, so that the sandbox can be embedded in any user process.
  • Sandbox sandbox, also known as sandbox
  • Sandbox is a security mechanism that can provide an isolated environment in the host program, so that it can provide experiments for programs whose sources are untrustworthy, destructive, or unable to determine the intention of the program to protect host program.
  • a container node may be placed in the host program, and an iframe (inline frame) is placed on the container node as a sandbox, wherein the iframe is set as a sandbox attribute.
  • iframe inline frame
  • other methods can also be used to create a sandbox in the host program, which is not limited here.
  • the host program may create a sandbox in the host program in response to the sandbox creation request.
  • the sandbox creation request may be triggered by a user.
  • the host program may create a sandbox in the host program in response to the start of the host program. That is, the sandbox can be automatically created by default when the host program is started, without being triggered by the user.
  • the execution environment in the embodiments of the present disclosure may also be referred to as context, context environment, execution environment, execution context, and so on.
  • the execution environment in the sandbox may mean an environment in the sandbox for running user code.
  • the operating environment in the sandbox can be flexibly selected according to user needs, for example, it can be a browser operating environment based on Windows, MacOS, Linux, Android, or iOS.
  • the adding a running environment in the sandbox includes: the host program responds to the request for adding a running environment, calls the adding interface, and uses the adding interface in the sandbox Add a running environment.
  • the adding interface may be obtained by encapsulating the function code for adding the running environment in the sandbox.
  • the added interface can be used to add a running environment in the sandbox, and the added interface can be called by the host program.
  • the execution environment addition request may mean a request for adding an execution environment in the sandbox.
  • the execution environment addition request may be triggered by a user. Adding an interface to easily add a running environment in the sandbox can improve the convenience of adding a running environment in the sandbox.
  • the host program may automatically add a running environment to the sandbox after the sandbox is created in the host program. That is, the runtime environment can be added by default when the sandbox is created without being triggered by the user.
  • the user can edit the user code in the user interface (User Interface, UI) of the host program.
  • the user code can be obtained from outside the host program, which is not limited here.
  • 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 can be implemented by inserting a program in the user code that calls back the running state of the user code.
  • the host program can obtain the running status of the user code by calling the status awareness interface.
  • the running state of the user code may be active stop, normal end, abnormal end, running, etc., which is not limited here.
  • actively stopping may refer to stopping the running of the user code according to a user instruction.
  • the host program can call back the running state of the user code in the sandbox.
  • the host program can respond to the user code running request, and deploy the user code to run in the sandbox running environment.
  • the user code execution request may be triggered by a user.
  • the host program may determine that a user code execution request is received in response to a preset run button being triggered by the user; or, the host program may determine that a user code execution request is received in response to receiving a preset run instruction; and so on.
  • the host program can call back the running status of the user code in the sandbox through the state awareness interface, that is, obtain the running status information of the user code in the sandbox.
  • the running state information may be any information that can represent the running state of the user code in the sandbox.
  • the method further includes: compiling the user code to obtain the compiled user code.
  • the host program adding a state-aware interface to the user code includes: adding a state-aware interface to the compiled user code.
  • the host program responds to the user code running request, deploys the compiled user code to run in the sandbox running environment, and obtains the compiled user code information through the state awareness interface. Running status information.
  • the user code can be converted into an abstract syntax tree (Abstract Syntax Tree, AST) and other grammatical structures, so as to realize the compilation of the user code, so as to add a running protection mechanism in the user code.
  • AST Abstract Syntax Tree
  • other compiling methods may also be used to compile the user code, which is not limited here.
  • the user code can also be compiled by GCC (GNU Compiler Collection, GNU Compiler Suite), and a running protection mechanism can be added in the user code.
  • GCC GPU Compiler Collection, GNU Compiler Suite
  • a running protection mechanism can be added in the user code.
  • the user code can also be compiled by the clang compiler, and a running protection mechanism can be added to the user code.
  • the adding of the running protection mechanism in the user code may be, for example, adding exception handling code in the user code to prevent the program from crashing due to an abnormal result, which is not limited in the present disclosure.
  • the host program may respond to the user code execution request, compile the user code, and add a state-aware interface to the compiled user code; or, respond to the user code compilation request, compile the user code, And add a state-aware interface for the compiled user code, wherein the user code compilation request can be triggered by the user; or, the host program can compile the user code in response to obtaining the user code, and target the compiled user code User code adds a state-aware interface; and so on.
  • the running of the user code in the sandbox may cause problems such as freezing and crashing of the host program.
  • This implementation method compiles the user code to obtain the compiled user code, adds a state-aware interface to the compiled user code, deploys the compiled user code to run in the sandbox operating environment, and obtains the compiled user code through the state-aware interface.
  • the running status information of the user code in the sandbox can protect the host program from being damaged by the user code in the sandbox, and reduce the probability of the host program being stuck or crashed due to the running of the user code in the sandbox. Improve the robustness and stability of the host program.
  • the compiling the user code to obtain the compiled user code may include: the host program responds to the user code running request, calls the running interface, and compiles the user code through the running interface Code to get the compiled user code.
  • a state-aware interface is added to the compiled user code through the running interface, and the compiled user code is deployed to run in the sandbox running environment through the running interface.
  • the running interface may be obtained by encapsulating functional code for compiling user code, adding a state-aware interface to the compiled user code, and deploying the compiled user code to run in a sandbox running environment.
  • the running interface can be called by the host program.
  • Compile user code by calling the running interface from the host program, add a state-aware interface to the compiled user code, and deploy the compiled user code to run in the sandbox running environment, which can further improve the convenience of running user code in the sandbox sex.
  • the method further includes: exposing the running code interface corresponding to the sandbox to the outside.
  • the host program calls the running code interface in response to the user code running request, and deploys the user code to run in the sandbox running environment through the running code interface.
  • the running code interface can be used to deploy the user code to run in the sandbox running environment, and the running code interface can be called by the host program.
  • the host program can respond to the user code running request, call the running code interface, and deploy the user code to run in the sandbox running environment through the running code interface, by This enables linkage between the sandbox and the host program.
  • the host program can easily deploy user code in the sandbox operating environment through the running code interface, and can easily repeat the user code and run it again after the user code is modified, thereby improving the ability to run in the sandbox operating environment. Convenience of user code.
  • the host program calls the running interface in response to the user code running request, compiles the user code through the running interface, adds a state-aware interface to the compiled user code, calls the running code interface, and passes
  • the running code interface deploys the compiled user code to run in the running environment of the sandbox.
  • the running interface can be used to call the running code interface exposed by the sandbox, and the user code is deployed to run in the running environment of the sandbox through the running code interface.
  • the host program can conveniently deploy the user code to run in the sandbox through the running interface, that is, it can improve the convenience of running the user code in the sandbox.
  • the user can edit the user code in the user interface of the sandbox, and can control the running of the user code in the sandbox.
  • the method further includes: the host program responds to the running state information with a corresponding preset Set an action and execute the preset action.
  • the preset action may refer to a preset action triggered based on the running state.
  • the preset action may be a user-defined action or a default action, which is not limited here. According to the corresponding relationship between the running state and the preset action, it can be judged whether the running state information of the user code has a corresponding preset action. Wherein, the number of preset actions corresponding to any running state may be 0, 1, 2 or more.
  • the host program may have corresponding preset actions in response to the running state information of the user code, and execute the preset actions, so that different preset actions can be triggered when the user code runs into different states.
  • the preset actions may include displaying error message, displaying running status, recording running logs, and so on.
  • the error prompt information may be prompt information for an error code in the user code
  • the running state may be the current running state of the user code
  • the running log may be the current running log of the user code.
  • the corresponding preset action may include displaying the running state; if the running state information indicates that the running state of the user code ends abnormally, the corresponding preset action The preset action may include displaying error message, displaying the running state and recording the running log; if the running state information indicates that the running state of the user code is running, the corresponding preset action may include displaying the running state.
  • the host program has a corresponding preset action in response to the running state information of the user code, and executing the preset action can provide user guidance in a timely manner and improve the interactivity in the teaching process.
  • the host program after obtaining the running state information of the user code through the state-aware interface, the host program has a corresponding preset action in response to the running state information, and executes the preset action, so that the host program can obtain the The running state of the user code in the box and trigger the preset action, which is helpful for the user to learn programming or teach programming.
  • the method further includes: when the running state information indicates that the running state of the user code is In the case of a normal end, in response to receiving the user code running request again, the user code is run again in the running environment of the sandbox after the user code was run last time.
  • the runtime environment may change.
  • the change result of the running environment in the sandbox can be kept, so that the user code can run in the sandbox. Continue running in the changed running environment, so that user code can run in a continuous context.
  • the method further includes: acquiring the modified user code; when the running status information indicates the If the running state of the user code is normally completed, in response to receiving the user code running request again, the modified user code is run in the running environment of the sandbox after the user code was run last time.
  • the runtime environment may change.
  • the user can modify the user code in the user interface of the host program to obtain the modified user code.
  • the modified user code can be obtained from outside the host program, which is not limited here.
  • the change result of the running environment in the sandbox can be kept, so that the modified user code can be in the sandbox after the change.
  • Run in the runtime environment so that the user code before and after modification can run in a continuous context.
  • the modified user code in this implementation may, for example, include a code newly input by the user.
  • the method further includes: the host program calls a reset interface in response to the execution environment reset request, and restores the sandbox operation environment to an initial state through the reset interface.
  • the reset interface can be obtained by encapsulating the function code used to restore the running environment in the sandbox to the initial state, or it can be used to re-add a sandbox after the running environment in the sandbox It is obtained by encapsulating the function code of the operating environment of the box.
  • the initial state may represent a state in which no user code is running, that is, the initial state may represent a state in which the running environment in the sandbox is not changed by any user code.
  • the reset interface can be used to restore the running environment in the sandbox to the initial state, and the reset interface can be called by the host program.
  • the execution environment reset request may represent a request for restoring the execution environment in the sandbox to an initial state.
  • the runtime environment reset request may be triggered by a user.
  • the host program calls the reset interface in response to the reset request of the operating environment, and restores the operating environment in the sandbox to the initial state through the reset interface. Run again in the reset running environment, that is, the independent running of the user code can be realized, so that the current running of the user code will not be affected by the previous running.
  • the method further includes: the host program calls a deletion interface in response to the deletion request of the runtime environment, and deletes the runtime environment in the sandbox through the deletion interface.
  • the deletion interface may be obtained by encapsulating the function code for deleting the running environment in the sandbox.
  • the deletion interface can be used to delete the running environment in the sandbox, and the deletion interface can be called by the host program.
  • the runtime deletion request may represent a request to delete the runtime in the sandbox.
  • the runtime deletion request may be user-triggered.
  • the host program responds to the deletion request of the operating environment, calls the deletion interface, and deletes the operating environment in the sandbox through the deletion interface, so that the host program can conveniently delete the operating environment in the sandbox through the deletion interface, that is, It can improve the convenience of deleting the running environment in the sandbox.
  • the method further includes: the host program calls a deletion interface in response to the runtime environment deletion request, and deletes the runtime environment in the sandbox through the deletion interface; the host program In response to the adding request of the running environment, the adding interface is called, and the running environment is added in the sandbox through the adding interface.
  • the deletion interface may be obtained by encapsulating the function code for deleting the running environment of the sandbox.
  • the delete interface can be used to delete the running environment in the sandbox
  • the add interface can be used to add the running environment in the sandbox
  • the delete interface and add interface can be called by the host program.
  • the runtime environment deletion request may represent a request for deleting the runtime environment in the sandbox
  • the runtime environment addition request may represent a request for adding a runtime environment in the sandbox.
  • the host program can easily replace the running environment in the sandbox by deleting and adding interfaces, that is, the convenience of replacing the running environment in the sandbox can be improved.
  • the method further includes: the host program calls a modification interface in response to the runtime environment modification request, and modifies the runtime environment in the sandbox through the modification interface.
  • the modification interface may be obtained by encapsulating function codes for modifying the running environment in the sandbox.
  • the modification interface can be used to modify the running environment in the sandbox, and the modification interface can be called by the host program.
  • the execution environment modification request may represent a request for modifying the execution environment in the sandbox.
  • the runtime environment modification request may be triggered by a user.
  • the runtime environment modification request may include identification information of the runtime environment to be modified (also referred to herein as a "modified runtime environment"), and the host program may respond to the runtime environment modification request by calling the The modification interface is used to modify the operating environment in the sandbox according to the identification information of the modified operating 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 runtime environment modification request includes the identification information A of the runtime environment, the host program may call the modification interface in response to the runtime environment modification request, and the modification interface converts the Change the operating environment of the operating environment to operating environment A.
  • the request for modifying the operating environment may include parameter information of the modified operating environment, and the host program may respond to the request for modifying the operating environment and call the modification interface to modify the interface according to the modified operating environment. parameter information to modify the running environment in the sandbox.
  • the host program can conveniently modify the running environment in the sandbox through the modification interface, that is, the convenience of modifying the running environment in the sandbox can be improved.
  • the user code in the sandbox may be cleared in response to the completion of the execution of the user code. That is, in this implementation manner, the user code in the sandbox may be cleared after each execution of the user code ends. In another possible implementation manner, the user code in the sandbox may be cleared in response to modification of the user code. In another possible implementation manner, the user code in the sandbox may be cleared in response to a code clearing request triggered by the user. In another possible implementation manner, the user code in the sandbox may be cleared in response to the runtime environment reset request. In another possible implementation manner, the user code in the sandbox may be cleared in response to the runtime environment deletion request.
  • Embodiments of the present disclosure can be applied to application scenarios such as online programming, online education, artificial intelligence, artificial intelligence education, online programming education, online programming platform, and artificial intelligence technology innovation platform.
  • a container node can be placed in the host program of the main page of the web programming platform, and an iframe can be placed on the container node as a sandbox, wherein the iframe is set as a sandbox attribute.
  • the Web programming platform provides a set of API (Application Programming Interface, Application Programming Interface) for sandbox control.
  • this group of APIs may include an add interface, a delete interface, an operation interface and a reset interface corresponding to the sandbox.
  • the add interface can be used to add a running environment in the sandbox
  • the delete interface can be used to delete the running environment in the sandbox
  • the running interface can be used to compile user code
  • add a state-aware interface to the compiled user code and call the sandbox
  • the running code interface exposed by the box can deploy the compiled user code to run in the sandbox running environment
  • the reset interface can be used to restore the running environment in the sandbox to the initial state.
  • the host program can operate the sandbox through this set of APIs.
  • the host program can respond to the request for adding the running environment, call the adding interface, and add the running environment in the sandbox.
  • the user can edit the user code in the user interface of the host program.
  • the host program can obtain user code through the user interface.
  • the running code interface corresponding to the user code in the sandbox can be exposed.
  • the host program can respond to the user code running request, call the running interface, compile the user code through the running interface, add a state awareness interface to the compiled user code, call the running code interface, and compile the compiled user code through the running code interface Deployments run in the sandboxed runtime environment.
  • the host program can acquire the running state information of the user code through the state-aware interface, and can have a corresponding preset action in response to the running state information, and execute the preset action.
  • the runtime environment may change.
  • the running state of the user code ends normally, if the running environment reset request is not received, the change result of the running environment in the sandbox can be kept, so that the user code can be in the changed running environment of the sandbox Continue to run, so that user code can be run in a continuous context.
  • the host program may also call a reset interface in response to an execution environment reset request, and restore the execution environment in the sandbox to an initial state through the reset interface.
  • the user can also choose to run the modified user code in the last running environment kept by the sandbox, or can choose to run the modified user code in the reset running environment of the sandbox. user code.
  • the running environment in the sandbox can be maintained or reset according to different user requirements, so that user codes can run in the continuous or independent running environment of the sandbox.
  • the state callback and flexible control of the running environment in the sandbox can be performed, and the sandbox can be embedded in any user process, which can realize The user code runs in the reset or maintained running environment of the sandbox, which facilitates the presentation of teaching content.
  • the present disclosure also provides user code running devices, electronic equipment, computer-readable storage media, and programs, all of which can be used to implement any user code running method provided in the present disclosure.
  • the corresponding technical solutions and technical effects can be found in The corresponding records in the method part will not be repeated here.
  • Fig. 2 shows a block diagram of a user code running device provided by an embodiment of the present disclosure.
  • the running device of the user code may include: a sandbox creation module 21, which is used for the host program to create a sandbox in the host program, and add an operating environment in the sandbox; the first acquisition Module 22, used for the host program to obtain the user code; adding module 23, used for the host program to add a state-aware interface for the user code, wherein the state-aware interface is used for the host program to perceive the user code
  • the apparatus may further include: an execution module, configured to execute the preset action in response to the host program having a corresponding preset action in response to the running status information.
  • the device may further include: a compiling module, configured to compile the user code to obtain compiled user code.
  • the adding module 23 can be used to add a state-aware interface to the compiled user code; the first running module 24 can be used for the host program to respond to the user code running request, The deployed user code runs in the running environment of the sandbox, and obtains the running state information of the compiled user code through the state awareness interface.
  • the compiling module may be used for: the host program calls a running interface in response to a user code running request, compiles the user code through the running interface, and obtains compiled user code;
  • the adding module 23 can be used to: add a state-aware interface to the compiled user code through the running interface;
  • the first running module 24 can be used to: deploy the compiled user code on the running interface through the running interface run in the sandbox runtime environment.
  • the sandbox creation module 21 may be configured to: the host program calls an adding interface in response to a running environment addition request, and adds a running environment in the sandbox through the adding interface.
  • the device may further include: an exposure module, configured to expose a running code interface corresponding to the sandbox to the outside.
  • the first running module 24 can be used for: the host program calls the running code interface in response to the user code running request, and deploys the user code on the running code interface through the running code interface. Run in the sandbox runtime environment described above.
  • the device may further include: a reset module, configured to call the reset interface by the host program in response to the request for resetting the running environment, and reset the running environment of the sandbox to Return to the original state.
  • a reset module configured to call the reset interface by the host program in response to the request for resetting the running environment, and reset the running environment of the sandbox to Return to the original state.
  • the device may further include: a deletion module, configured for the host program to call a deletion interface in response to the deletion request of the running environment, and delete the running environment in the sandbox through the deletion interface. environment.
  • a deletion module configured for the host program to call a deletion interface in response to the deletion request of the running environment, and delete the running environment in the sandbox through the deletion interface. environment.
  • the device may further include: a second running module, configured for the host program to respond to The user code running request is received again, and the user code is run again in the running environment of the sandbox after the user code was run last time.
  • a second running module configured for the host program to respond to The user code running request is received again, and the user code is run again in the running environment of the sandbox after the user code was run last time.
  • the device may further include: a second acquiring module, configured to acquire the modified user code; a third running module, configured to execute the host program when the running state information indicates the When the running state of the user code is normally completed, in response to receiving the user code running request again, the modified user code is run in the running environment of the sandbox after the user code was run last time.
  • a second acquiring module configured to acquire the modified user code
  • a third running module configured to execute the host program when the running state information indicates the When the running state of the user code is normally completed, in response to receiving the user code running request again, the modified user code is run in the running environment of the sandbox after the user code was run last time.
  • the device may further include: a modification module, configured to call a modification interface by the host program in response to a modification request of the operating environment, and modify the operating environment in the sandbox through the modification interface .
  • a modification module configured to call a modification interface by the host program in response to a modification request of the operating environment, and modify the operating environment in the sandbox through the modification interface .
  • a host program is used to create a sandbox in the host program, add an operating environment in the sandbox, obtain user code, add a state-aware interface for the user code, and the host program
  • the host program In response to the user code running request, deploying the user code to run in the sandbox running environment, and obtaining the running status information of the user code through the state awareness interface, thereby providing isolation for the user code
  • the sandbox is linked with the host program, and the host program can obtain the running status of the user code in the sandbox, thereby helping users to learn programming or teach programming.
  • the functions or modules included in the device provided by the embodiments of the present disclosure can be used to execute the methods described in the above method embodiments, and its specific implementation and technical effects can refer to the descriptions of the above method embodiments, for It is concise and will not be repeated here.
  • An embodiment of the present disclosure also provides a computer-readable storage medium, on which computer program instructions are stored, and when the computer program instructions are executed by a processor, the foregoing method is implemented.
  • the computer-readable storage medium may be a non-volatile computer-readable storage medium, or may be a volatile computer-readable storage medium.
  • An embodiment of the present disclosure also proposes a computer program, including computer readable codes, and when the computer readable codes are run in an electronic device, a processor in the electronic device executes the above method.
  • An embodiment of the present disclosure also provides a computer program product, including computer-readable codes, or a non-volatile computer-readable storage medium carrying computer-readable codes, when the computer-readable codes are run in an electronic device , the processor in the electronic device executes the above method.
  • An embodiment of the present disclosure also provides an electronic device, including: one or more processors; a memory for storing executable instructions; wherein the one or more processors are configured to call the executable instructions stored in the memory instruction to perform the above method.
  • Electronic devices may be provided as terminals, servers, or other forms of devices.
  • FIG. 3 shows a block diagram of an electronic device 800 provided by an embodiment of the present disclosure.
  • the electronic device 800 may be a terminal such as a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, or a personal digital assistant.
  • electronic device 800 may include one or more of the following components: processing component 802, memory 804, power supply component 806, multimedia component 808, audio component 810, input/output (I/O) interface 812, sensor component 814 , and the communication component 816.
  • the processing component 802 generally controls the overall operations of the electronic device 800, such as those associated with display, telephone calls, data communications, camera operations, and recording operations.
  • the processing component 802 may include one or more processors 820 to execute instructions to complete all or part of the steps of the above method. Additionally, processing component 802 may include one or more modules that facilitate interaction between processing component 802 and other components. For example, processing component 802 may include a multimedia module to facilitate interaction between multimedia component 808 and 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 the like.
  • the memory 804 can be implemented by any type of volatile or non-volatile storage device or their combination, 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 Disk.
  • SRAM static random access memory
  • EEPROM electrically erasable programmable read-only memory
  • EPROM erasable Programmable Read Only Memory
  • PROM Programmable Read Only Memory
  • ROM Read Only Memory
  • Magnetic Memory Flash Memory
  • Magnetic or Optical Disk Magnetic Disk
  • the power supply component 806 provides power to various components of the electronic device 800 .
  • 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 electronic device 800 .
  • the multimedia component 808 includes a screen providing an output interface between the electronic device 800 and the user.
  • 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 input signals from a user.
  • the touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensor may not only sense a boundary of a touch or swipe action, but also detect duration and pressure associated with the touch or swipe action.
  • the multimedia component 808 includes a front camera and/or a rear camera. When the electronic device 800 is in an operation mode, such as a shooting mode or a video mode, the front camera and/or the rear camera can receive external multimedia data. Each front camera and rear camera can be a fixed optical lens system or have focal length and optical zoom capability.
  • the audio component 810 is configured to output and/or input audio signals.
  • the audio component 810 includes a microphone (MIC), which is configured to receive external audio signals when the electronic device 800 is in operation modes, such as call mode, recording mode and voice recognition mode. Received audio signals may be further stored in memory 804 or sent via communication component 816 .
  • the 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 a peripheral interface module, which may be a keyboard, a click wheel, a button, and the like. These buttons may include, but are not limited to: a home button, volume buttons, start button, and lock button.
  • Sensor assembly 814 includes one or more sensors for providing status assessments of various aspects of electronic device 800 .
  • the sensor component 814 can detect the open/closed state of the electronic device 800, the relative positioning of components, such as the display and the keypad of the electronic device 800, the sensor component 814 can also detect the electronic device 800 or a Changes in position of components, presence or absence of user contact with electronic device 800 , electronic device 800 orientation or acceleration/deceleration and temperature changes in electronic device 800 .
  • Sensor assembly 814 may include a proximity sensor configured to detect the presence of nearby objects in the absence of any physical contact.
  • Sensor assembly 814 may also include an optical sensor, such as a complementary metal-oxide-semiconductor (CMOS) or charge-coupled device (CCD) image sensor, for use in imaging applications.
  • CMOS complementary metal-oxide-semiconductor
  • CCD charge-coupled device
  • the sensor component 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 can access wireless networks based on communication standards, such as wireless networks (Wi-Fi), second-generation mobile communication technologies (2G), third-generation mobile communication technologies (3G), fourth-generation mobile communication technologies (4G ), the long-term evolution (LTE) of the universal mobile communication technology, the fifth generation mobile communication technology (5G) or their combination.
  • the communication component 816 receives broadcast signals or broadcast related information from an external broadcast management system via a broadcast channel.
  • the communication component 816 also includes a near field communication (NFC) module to facilitate short-range communication.
  • the NFC module may be implemented based on Radio Frequency Identification (RFID) technology, Infrared Data Association (IrDA) technology, Ultra Wide Band (UWB) technology, Bluetooth (BT) technology and other technologies.
  • RFID Radio Frequency Identification
  • IrDA Infrared Data Association
  • UWB Ultra Wide Band
  • Bluetooth Bluetooth
  • 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 A programmable gate array (FPGA), controller, microcontroller, microprocessor or other electronic component implementation for performing the methods described above.
  • ASICs application specific integrated circuits
  • DSPs digital signal processors
  • DSPDs digital signal processing devices
  • PLDs programmable logic devices
  • FPGA field programmable A programmable gate array
  • controller microcontroller, microprocessor or other electronic component implementation for performing the methods described above.
  • a non-volatile computer-readable storage medium such as a memory 804 including computer program instructions, which can be executed by the processor 820 of the electronic device 800 to implement the above method.
  • FIG. 4 shows a block diagram of an electronic device 1900 provided by an embodiment of the present disclosure.
  • electronic device 1900 may be provided as a server.
  • electronic device 1900 includes processing component 1922 , which further includes one or more processors, and a memory resource represented by memory 1932 for storing instructions executable by processing component 1922 , such as application programs.
  • the application programs stored in memory 1932 may include one or more modules each corresponding to a set of instructions.
  • the processing component 1922 is configured to execute instructions to perform the above method.
  • Electronic device 1900 may also include a power supply component 1926 configured to perform power management of electronic device 1900, a wired or wireless network interface 1950 configured to connect electronic device 1900 to a network, and an input-output (I/O) interface 1958 .
  • the electronic device 1900 can operate based on the operating system stored in the memory 1932, such as the Microsoft server operating system (Windows ServerTM), the graphical user interface-based operating system (Mac OS XTM) introduced by Apple Inc., and the multi-user and multi-process computer operating system (UnixTM). ), a free and open source Unix-like operating system (LinuxTM), an open source Unix-like operating system (FreeBSDTM), or similar.
  • a non-transitory computer-readable storage medium such as the memory 1932 including computer program instructions, which can be executed by the processing component 1922 of the electronic device 1900 to implement the above method.
  • the present disclosure can be a system, method and/or computer program product.
  • a computer program product may include a computer readable storage medium having computer readable program instructions thereon for causing a processor to implement various aspects of the present disclosure.
  • a computer readable storage medium may be a tangible device that can retain and store instructions for use by an instruction execution device.
  • a computer readable storage medium may be, for example, but is not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing.
  • Computer-readable storage media include: portable computer diskettes, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), or flash memory), static random access memory (SRAM), compact disc read only memory (CD-ROM), digital versatile disc (DVD), memory stick, floppy disk, mechanically encoded device, such as a printer with instructions stored thereon A hole card or a raised structure in a groove, and any suitable combination of the above.
  • RAM random access memory
  • ROM read-only memory
  • EPROM erasable programmable read-only memory
  • flash memory static random access memory
  • SRAM static random access memory
  • CD-ROM compact disc read only memory
  • DVD digital versatile disc
  • memory stick floppy disk
  • mechanically encoded device such as a printer with instructions stored thereon
  • a hole card or a raised structure in a groove and any suitable combination of the above.
  • computer-readable storage media are not to be construed as transient signals per se, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through waveguides or other transmission media (e.g., pulses of light through fiber optic cables), or transmitted electrical signals.
  • Computer-readable program instructions described herein may be downloaded from a computer-readable storage medium to a respective computing/processing device, or downloaded to an external computer or external storage device over 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.
  • a network adapter card or a 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 each computing/processing device .
  • Computer program instructions for performing the operations of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, state setting data, or Source or object code written in any combination, including object-oriented programming languages—such as Smalltalk, C++, etc., and conventional procedural programming languages—such as the “C” language or similar programming languages.
  • 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 implement.
  • the remote computer can be connected to the user computer through any kind of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (such as via the Internet using an Internet service provider). connect).
  • LAN local area network
  • WAN wide area network
  • an electronic circuit such as a programmable logic circuit, field programmable gate array (FPGA), or programmable logic array (PLA)
  • FPGA field programmable gate array
  • PDA programmable logic array
  • 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 when executed by the processor of the computer or other programmable data processing apparatus , producing an apparatus for realizing the functions/actions specified in one or more blocks in the flowchart and/or block diagram.
  • These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause computers, programmable data processing devices and/or other devices to work in a specific way, so that the computer-readable medium storing instructions includes An article of manufacture comprising instructions for implementing various aspects of the functions/acts specified in one or more blocks in flowcharts and/or block diagrams.
  • each block in a flowchart or block diagram may represent a module, a portion of a program segment, or an instruction that includes one or more Executable instructions.
  • the functions noted in the block may occur out of the order noted in the figures. For example, two blocks in succession may, in fact, be executed substantially concurrently, or they may sometimes be executed in the reverse order, depending upon the functionality involved.
  • each block of the block diagrams and/or flowchart illustrations, and combinations of blocks in the block diagrams and/or flowchart illustrations can be implemented by a dedicated hardware-based system that performs the specified function or action , or may be implemented by a combination of dedicated hardware and computer instructions.
  • the computer program product can be specifically realized by means of hardware, software or a combination thereof.
  • the computer program product is embodied as a computer storage medium, and in another optional embodiment, the computer program product is embodied as a software product, such as a software development kit (Software Development Kit, SDK) etc. wait.
  • a software development kit Software Development Kit, SDK

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

一种用户代码的运行方法及装置、电子设备和存储介质。方法包括:宿主程序在宿主程序中创建沙盒(S11),并在沙盒中添加运行环境;宿主程序获取用户代码(S12);宿主程序针对用户代码添加状态感知接口,其中,状态感知接口用于感知用户代码的运行状态(S13);宿主程序响应于用户代码运行请求,将用户代码部署在运行环境中运行,并通过状态感知接口获取用户代码的运行状态信息(S14)。

Description

用户代码的运行方法及装置、电子设备和存储介质
相关申请的交叉引用
本公开要求于2021年11月19日提交的,申请号为202111392308.1的中国专利公开的优先权,该中国专利公开的全部内容以引用的方式并入本文中。
技术领域
本公开涉及计算机技术领域,尤其涉及一种用户代码的运行方法及装置、电子设备和存储介质。
背景技术
随着人工智能(Artificial Intelligence,AI)的普及,人工智能编程教育也逐渐成为K12教育、高等教育和职业教育等的一个重要组成部分,而人工智能编程平台(例如基于Web(网页)应用的人工智能编程平台等)是人工智能编程教育领域的重要基础设施。
通常,在人工智能编程平台上,用户可以多次编辑代码,运行代码,查看结果。人工智能编程平台运行用户代码的方式,对于用户的编程学习等方面具有重要意义。
发明内容
本公开提供了一种用户代码的运行技术方案。
根据本公开的一方面,提供了一种用户代码的运行方法,包括:宿主程序在所述宿主程序中创建沙盒,并在所述沙盒中添加运行环境;所述宿主程序获取用户代码;所述宿主程序针对所述用户代码添加状态感知接口,其中,所述状态感知接口用于所述宿主程序感知所述用户代码的运行状态;所述宿主程序响应于用户代码运行请求,将所述用户代码部署在所述沙盒的运行环境中运行,并通过所述状态感知接口获取所述用户代码的运行状态信息。
通过宿主程序在所述宿主程序中创建沙盒,在所述沙盒中添加运行环境,获取用户代码,针对所述用户代码添加状态感知接口,所述宿主程序响应于用户代码运行请求,将所述用户代码部署在所述沙盒的运行环境中运行,并通过所述状态感知接口获取所述用户代码的运行状态信息,由此能够在为用户代码提供隔离环境、保护宿主程序的前提下,使沙盒与宿主程序联动,宿主程序能够获取沙盒中的用户代码的运行状态,从而有助于用户进行编程学习或者编程教学。
在一种可能的实现方式中,在所述通过所述状态感知接口获取所述用户代码的运行状态信息之后,所述方法还包括:所述宿主程序响应于所述运行状态信息具有对应的预 设动作,执行所述预设动作。
在该实现方式中,在通过状态感知接口获取用户代码的运行状态信息之后,宿主程序响应于所述运行状态信息具有对应的预设动作,执行所述预设动作,由此宿主程序能够获取沙盒中的用户代码的运行状态并触发预设动作,从而有助于用户进行编程学习或者编程教学。
在一种可能的实现方式中,在所述宿主程序获取用户代码之后,在所述宿主程序针对所述用户代码添加状态感知接口之前,所述方法还包括:编译所述用户代码,得到编译后的用户代码;所述宿主程序针对所述用户代码添加状态感知接口,包括:针对所述编译后的用户代码添加状态感知接口;所述宿主程序响应于用户代码运行请求,将所述用户代码部署在所述沙盒的运行环境中运行,并通过所述状态感知接口获取所述用户代码的运行状态信息,包括:所述宿主程序响应于用户代码运行请求,将所述编译后的用户代码部署在所述沙盒的运行环境中运行,并通过所述状态感知接口获取所述编译后的用户代码的运行状态信息。
该实现方式通过编译用户代码,得到编译后的用户代码,针对编译后的用户代码添加状态感知接口,宿主程序响应于用户代码运行请求,将编译后的用户代码部署在沙盒的运行环境中运行,并通过状态感知接口获取编译后的用户代码的运行状态信息,由此能够保护宿主程序不被沙盒中的用户代码破坏,降低因沙盒中的用户代码的运行而导致宿主程序发生卡死、崩溃等问题的概率,从而能够提高宿主程序的鲁棒性和稳定性。
作为该实现方式的一个示例,所述编译所述用户代码,得到编译后的用户代码,包括:所述宿主程序响应于用户代码运行请求,调用运行接口,通过所述运行接口编译所述用户代码,得到编译后的用户代码;所述针对所述编译后的用户代码添加状态感知接口,包括:通过所述运行接口针对所述编译后的用户代码添加状态感知接口;所述宿主程序响应于用户代码运行请求,将所述编译后的用户代码部署在所述沙盒的运行环境中运行,包括:通过所述运行接口将所述编译后的用户代码部署在所述沙盒的运行环境中运行。
通过宿主程序调用运行接口编译用户代码、针对编译后的用户代码添加状态感知接口以及将编译后的用户代码部署在沙盒的运行环境中运行,能够进一步提高在沙盒中运行用户代码的便捷性。
在一种可能的实现方式中,所述在所述沙盒中添加运行环境,包括:所述宿主程序响应于运行环境添加请求,调用添加接口,并通过所述添加接口在所述沙盒中添加运行环境。
在该实现方式中,通过宿主程序响应于运行环境添加请求,调用添加接口,并通过添加接口在沙盒中添加运行环境,由此宿主程序能够通过添加接口便捷地在沙盒中添加运行环境,从而能够提高在沙盒中添加运行环境的便捷性。
在一种可能的实现方式中,所述方法还包括:所述宿主程序响应于运行环境复位请求,调用复位接口,并通过所述复位接口将所述沙盒的运行环境恢复至初始状态。
在该实现方式中,通过宿主程序响应于运行环境复位请求,调用复位接口,并通过所述复位接口将沙盒中的运行环境恢复至初始状态,由此能够根据用户需求,使用户代码在所述沙盒的重置的运行环境中再次运行,即,能够实现用户代码的独立运行,使用户代码的本次运行不受到之前的运行的影响。
在一种可能的实现方式中,所述方法还包括:所述宿主程序响应于运行环境删除请求,调用删除接口,并通过所述删除接口删除所述沙盒中的运行环境。
通过宿主程序响应于运行环境删除请求,调用所述删除接口,并通过所述删除接口删除沙盒中的运行环境,由此宿主程序能够通过删除接口便捷地删除沙盒中的运行环境,即,能够提高删除沙盒中的运行环境的便捷性。
在一种可能的实现方式中,在所述通过所述状态感知接口获取所述用户代码的运行状态信息之后,所述方法还包括:在所述运行状态信息指示所述用户代码的运行状态为正常结束的情况下,响应于再次接收到用户代码运行请求,在所述沙盒的上一次运行所述用户代码后的运行环境中再次运行所述用户代码。
在该实现方式中,在用户代码的运行状态为正常结束的情况下,若未接收到运行环境复位请求,则可以保持沙盒中运行环境的改变结果,使用户代码在所述沙盒的改变后的运行环境中运行,从而能够实现用户代码在连续的上下文中运行。
在一种可能的实现方式中,在所述通过所述状态感知接口获取所述用户代码的运行状态信息之后,所述方法还包括:获取修改后的用户代码;在所述运行状态信息指示所述用户代码的运行状态为正常结束的情况下,响应于再次接收到用户代码运行请求,在所述沙盒的上一次运行所述用户代码后的运行环境中运行所述修改后的用户代码。
在该实现方式中,在用户代码的运行状态为正常结束的情况下,若未接收到运行环境复位请求,则可以保持沙盒中运行环境的改变结果,使修改后的用户代码在所述沙盒的改变后的运行环境中运行,从而能够实现修改前后的用户代码在连续的上下文中运行。
根据本公开的一方面,提供了一种用户代码的运行装置,包括:沙盒创建模块,用于宿主程序在所述宿主程序中创建沙盒,并在所述沙盒中添加运行环境;第一获取模块,用于所述宿主程序获取用户代码;添加模块,用于所述宿主程序针对所述用户代码添加状态感知接口,其中,所述状态感知接口用于所述宿主程序感知所述用户代码的运行状态;第一运行模块,用于所述宿主程序响应于用户代码运行请求,将所述用户代码部署在所述沙盒的运行环境中运行,并通过所述状态感知接口获取所述用户代码的运行状态信息。
在一种可能的实现方式中,所述装置还包括:执行模块,用于所述宿主程序响应于 所述运行状态信息具有对应的预设动作,执行所述预设动作。
在一种可能的实现方式中,所述装置还包括:编译模块,用于编译所述用户代码,得到编译后的用户代码;所述添加模块用于:针对所述编译后的用户代码添加状态感知接口;所述第一运行模块用于:所述宿主程序响应于用户代码运行请求,将所述编译后的用户代码部署在所述沙盒的运行环境中运行,并通过所述状态感知接口获取所述编译后的用户代码的运行状态信息。
在一种可能的实现方式中,所述编译模块用于:所述宿主程序响应于用户代码运行请求,调用运行接口,通过所述运行接口编译所述用户代码,得到编译后的用户代码;所述添加模块用于:通过所述运行接口针对所述编译后的用户代码添加状态感知接口;所述第一运行模块用于:通过所述运行接口将所述编译后的用户代码部署在所述沙盒的运行环境中运行。
在一种可能的实现方式中,所述沙盒创建模块用于:所述宿主程序响应于运行环境添加请求,调用添加接口,并通过所述添加接口在所述沙盒中添加运行环境。
在一种可能的实现方式中,所述装置还包括:暴露模块,用于对外暴露所述沙盒对应的运行代码接口;所述第一运行模块用于:所述宿主程序响应于用户代码运行请求,调用所述运行代码接口,并通过所述运行代码接口将所述用户代码部署在所述沙盒的运行环境中运行。
在一种可能的实现方式中,所述装置还包括:复位模块,用于所述宿主程序响应于运行环境复位请求,调用复位接口,并通过所述复位接口将所述沙盒的运行环境恢复至初始状态。
在一种可能的实现方式中,所述装置还包括:删除模块,用于所述宿主程序响应于运行环境删除请求,调用删除接口,并通过所述删除接口删除所述沙盒中的运行环境。
在一种可能的实现方式中,所述装置还包括:第二运行模块,用于在所述运行状态信息指示所述用户代码的运行状态为正常结束的情况下,响应于再次接收到用户代码运行请求,在所述沙盒的上一次运行所述用户代码后的运行环境中再次运行所述用户代码。
在一种可能的实现方式中,所述装置还包括:第二获取模块,用于获取修改后的用户代码;第三运行模块,用于在所述运行状态信息指示所述用户代码的运行状态为正常结束的情况下,响应于再次接收到用户代码运行请求,在所述沙盒的上一次运行所述用户代码后的运行环境中运行所述修改后的用户代码。
根据本公开的一方面,提供了一种电子设备,包括:一个或多个处理器;用于存储可执行指令的存储器;其中,所述一个或多个处理器被配置为调用所述存储器存储的可执行指令,以执行上述方法。
根据本公开的一方面,提供了一种计算机可读存储介质,其上存储有计算机程序指 令,所述计算机程序指令被处理器执行时实现上述方法。
根据本公开的一方面,提供了一种计算机程序产品,包括计算机可读代码,或者承载有计算机可读代码的非易失性计算机可读存储介质,当所述计算机可读代码在电子设备中运行时,所述电子设备中的处理器执行上述方法。
在本公开实施例中,通过宿主程序在所述宿主程序中创建沙盒,在所述沙盒中添加运行环境,获取用户代码,针对所述用户代码添加状态感知接口,所述宿主程序响应于用户代码运行请求,将所述用户代码部署在所述沙盒的运行环境中运行,并通过所述状态感知接口获取所述用户代码的运行状态信息,由此能够在为用户代码提供隔离环境、保护宿主程序的前提下,使沙盒与宿主程序联动,宿主程序能够获取沙盒中的用户代码的运行状态,从而有助于用户进行编程学习或者编程教学。
应当理解的是,以上的一般描述和后文的细节描述仅是示例性和解释性的,而非限制本公开。根据下面参考附图对示例性实施例的详细说明,本公开的其它特征及方面将变得清楚。
附图说明
此处的附图示出了符合本公开的实施例,并与说明书一起用于说明本公开的技术方案。
图1示出本公开实施例提供的用户代码的运行方法的流程图。
图2示出本公开实施例提供的用户代码的运行装置的框图。
图3示出本公开实施例提供的一种电子设备800的框图。
图4示出本公开实施例提供的一种电子设备1900的框图。
具体实施方式
以下将参考附图详细说明本公开的各种示例性实施例、特征和方面。附图中相同的附图标记表示功能相同或相似的元件。尽管在附图中示出了实施例的各种方面,但是除非特别指出,不必按比例绘制附图。
在这里专用的词“示例性”意为“用作例子、实施例或说明性”。这里作为“示例性”所说明的任何实施例不必解释为优于或好于其它实施例。
本文中术语“和/或”,仅仅是一种描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B可以表示单独存在A、同时存在A和B、单独存在B这三种情况。另外,本文中术语“至少一种”表示多种中的任意一种或多种中的至少两种的任意组合,例如,包括A、B、C中的至少一种可以表示包括从A、B和C构成的集合中选择的任意 一个或多个元素。
另外,为了更好地说明本公开,在下文的具体实施方式中给出了众多的具体细节。本领域技术人员应当理解,没有某些具体细节,本公开同样可以实施。在一些实例中,对于本领域技术人员熟知的方法、手段、元件和电路未作详细描述,以便于凸显本公开的主旨。
本公开实施例提供了一种运行用户代码的方法及装置、电子设备和存储介质。通过宿主程序在所述宿主程序中创建沙盒,在所述沙盒中添加运行环境,获取用户代码,针对所述用户代码添加状态感知接口,所述宿主程序响应于用户代码运行请求,将所述用户代码部署在所述沙盒的运行环境中运行,并通过所述状态感知接口获取所述用户代码的运行状态信息。由此,能够在利用沙盒为用户代码提供隔离环境、保护宿主程序的前提下,使沙盒与宿主程序联动,并使得宿主程序能够获取沙盒中的用户代码的运行状态,从而有助于用户进行编程学习或者编程教学。
图1示出本公开实施例提供的用户代码的运行方法的流程图。在一种可能的实现方式中,所述用户代码的运行方法可以由终端设备或服务器或其它处理设备执行。其中,终端设备可以是用户设备(User Equipment,UE)、移动设备、用户终端、蜂窝电话、无绳电话、个人数字助理(Personal Digital Assistant,PDA)、手持设备、计算设备、车载设备或者可穿戴设备等。在一些可能的实现方式中,所述用户代码的运行方法可以通过处理器调用存储器中存储的计算机可读指令的方式来实现。如图1所示,所述用户代码的运行方法包括步骤S11至步骤S14。
在步骤S11中,宿主程序在所述宿主程序中创建沙盒,并在所述沙盒中添加运行环境。
在步骤S12中,宿主程序获取用户代码。
在步骤S13中,宿主程序针对所述用户代码添加状态感知接口,其中,所述状态感知接口用于所述宿主程序感知所述用户代码的运行状态。
在步骤S14中,所述宿主程序响应于用户代码运行请求,将所述用户代码部署在所述沙盒的运行环境中运行,并通过所述状态感知接口获取所述用户代码的运行状态信息。
本公开实施例可以应用于Web端,例如基于Web应用的人工智能编程平台或者基于Web应用的其他编程平台,也可以应用于PC(Personal Computer,个人计算机)端软件或者移动端软件等中,在此不做限定。
宿主程序可以表示将沙盒作为子模块使用的应用程序。在本公开实施例中,可以将用户选择的任意程序作为宿主程序,从而可以将沙盒嵌入到任意的用户流程中。沙盒(sandbox,又称为沙箱)是一种安全机制,可以在宿主程序中提供隔离环境,从而可以为来源不可信、具有破坏力或无法判定程序意图的程序提供实验之用,以保护宿主程 序。
在一种可能的实现方式中,可以在宿主程序中放置一个容器节点,在该容器节点放置一个iframe(内联框架)作为沙盒,其中,iframe被设置为沙盒属性。当然,也可以采用其他方式在宿主程序中创建沙盒,在此不做限定。
在一种可能的实现方式中,宿主程序可以响应于沙盒创建请求,在宿主程序中创建沙盒。其中,沙盒创建请求可以是由用户触发的。
在另一种可能的实现方式中,宿主程序可以响应于宿主程序启动,在宿主程序中创建沙盒。即可以默认在启动宿主程序时自动创建沙盒,而无需由用户触发。
本公开实施例中的运行环境也可以称为上下文、上下文环境、执行环境、执行上下文等等。沙盒中的运行环境可以表示沙盒中用于运行用户代码的环境。沙盒中的运行环境可以根据用户需求灵活选择,例如可以为基于Windows、MacOS、Linux、Android或者iOS等的浏览器运行环境。
在一种可能的实现方式中,所述在所述沙盒中添加运行环境,包括:所述宿主程序响应于运行环境添加请求,调用添加接口,并通过所述添加接口在所述沙盒中添加运行环境。在该实现方式中,添加接口可以是对在沙盒中添加运行环境的功能代码进行封装得到的。添加接口可以用于在沙盒中添加运行环境,且添加接口可以供宿主程序调用。运行环境添加请求可以表示用于在沙盒中添加运行环境的请求。运行环境添加请求可以是由用户触发的。通过添加接口便捷地在沙盒中添加运行环境,能够提高在沙盒中添加运行环境的便捷性。
在另一种可能的实现方式中,宿主程序可以在宿主程序中创建沙盒后,自动在沙盒中添加运行环境。即,可以在创建沙盒时默认添加运行环境,而无需由用户触发。
在本公开实施例中,用户可以在宿主程序的用户界面(User Interface,UI)中编辑用户代码。或者,可以从宿主程序的外部获取用户代码,在此不做限定。
在本公开实施例中,状态感知接口是用于回调用户代码运行状态的程序,针对用户代码添加的状态感知接口可以通过在用户代码中插入回调用户代码运行状态的程序来实现。这样,宿主程序通过调用状态感知接口即可获取用户代码的运行状态。其中,用户代码的运行状态可以为主动停止、正常结束、异常结束、运行中等,在此不做限定。其中,主动停止可以表示根据用户指令停止用户代码的运行。宿主程序通过绑定状态感知接口,可以回调沙盒中的用户代码的运行状态。
宿主程序可以响应于用户代码运行请求,将用户代码部署在沙盒的运行环境中运行。其中,用户代码运行请求可以是由用户触发的。例如,宿主程序可以响应于预设的运行按钮被用户触发,确定接收到用户代码运行请求;或者,宿主程序可以响应于接收到预设的运行指令,确定接收到用户代码运行请求;等等。在将用户代码部署在沙盒的运行 环境中运行之后,宿主程序可以通过状态感知接口回调沙盒中的用户代码的运行状态,即获取沙盒中的用户代码的运行状态信息。其中,所述运行状态信息可以是能够表示沙盒中的用户代码的运行状态的任意信息。
在一种可能的实现方式中,在所述宿主程序获取用户代码之后,在所述宿主程序针对所述用户代码添加状态感知接口之前,所述方法还包括:编译所述用户代码,得到编译后的用户代码。所述宿主程序针对所述用户代码添加状态感知接口,包括:针对所述编译后的用户代码添加状态感知接口。相应地,所述宿主程序响应于用户代码运行请求,将所述编译后的用户代码部署在所述沙盒的运行环境中运行,并通过所述状态感知接口获取所述编译后的用户代码的运行状态信息。在该实现方式中,可以将用户代码转化为抽象语法树(Abstract Syntax Tree,AST)等语法结构,以实现对用户代码进行编译,从而在用户代码中添加运行保护机制。当然,也可以采用其他编译方式对用户代码进行编译,在此不做限定。例如,还可以通过GCC(GNU Compiler Collection,GNU编译器套件)对用户代码进行编译,并在用户代码中添加运行保护机制。又如,还可以通过clang编译器对用户代码进行编译,并在用户代码中添加运行保护机制。所述在用户代码中添加运行保护机制,例如可以是在用户代码中添加异常处理代码,避免程序因出现异常结果而崩溃,本公开对此不作限制。
在该实现方式中,宿主程序可以响应于用户代码运行请求,编译所述用户代码,并针对编译后的用户代码添加状态感知接口;或者,可以响应于用户代码编译请求,编译所述用户代码,并针对编译后的用户代码添加状态感知接口,其中,用户代码编译请求可以是由用户触发的;或者,宿主程序可以响应于获取到所述用户代码,编译所述用户代码,并针对编译后的用户代码添加状态感知接口;等等。
相关技术中,由于未对沙盒中的用户代码进行编译,导致沙盒中的用户代码的运行可能会造成宿主程序的卡死、崩溃等问题。该实现方式通过编译用户代码,得到编译后的用户代码,针对编译后的用户代码添加状态感知接口,将编译后的用户代码部署在沙盒的运行环境中运行,并通过状态感知接口获取编译后的用户代码的运行状态信息,由此能够保护宿主程序不被沙盒中的用户代码破坏,降低因沙盒中的用户代码的运行而导致宿主程序发生卡死、崩溃等问题的概率,从而能够提高宿主程序的鲁棒性和稳定性。
作为该实现方式的一个示例,所述编译所述用户代码,得到编译后的用户代码,可包括:所述宿主程序响应于用户代码运行请求,调用运行接口,通过所述运行接口编译所述用户代码,得到编译后的用户代码。相应地,通过所述运行接口针对所述编译后的用户代码添加状态感知接口,并通过所述运行接口将所述编译后的用户代码部署在所述沙盒的运行环境中运行。在该示例中,运行接口可以是将用于编译用户代码、针对编译后的用户代码添加状态感知接口、将编译后的用户代码部署在沙盒的运行环境中运行的功能代码进行封装得到的。运行接口可以供宿主程序调用。通过宿主程序调用运行接口来编译用户代码、针对编译后的用户代码添加状态感知接口以及将编译后的用户代码部 署在沙盒的运行环境中运行,能够进一步提高在沙盒中运行用户代码的便捷性。
在一种可能的实现方式中,所述方法还包括:对外暴露所述沙盒对应的运行代码接口。相应地,所述宿主程序响应于用户代码运行请求,调用所述运行代码接口,并通过所述运行代码接口将所述用户代码部署在所述沙盒的运行环境中运行。在该实现方式中,运行代码接口可以用于将用户代码部署到沙盒的运行环境中运行,运行代码接口可以供宿主程序调用。通过将沙盒对应的运行代码接口进行暴露,宿主程序可以响应于用户代码运行请求,调用所述运行代码接口,并通过所述运行代码接口将用户代码部署在沙盒的运行环境中运行,由此能够使沙盒与宿主程序联动。这样,宿主程序能够通过运行代码接口便捷地在沙盒的运行环境中部署用户代码,且能够方便地重复运行用户代码以及在用户代码修改后再次运行,从而能够提高在沙盒的运行环境中运行用户代码的便捷性。
作为该实现方式的一个示例,所述宿主程序响应于用户代码运行请求,调用运行接口,通过运行接口编译所述用户代码、针对编译后的用户代码添加状态感知接口、调用运行代码接口,并通过运行代码接口将编译后的用户代码部署在所述沙盒的运行环境中运行。在该示例中,运行接口可以用于调用沙盒对外暴露的运行代码接口,并通过所述运行代码接口将用户代码部署在沙盒的运行环境中运行。根据该示例,宿主程序能够通过运行接口便捷地将用户代码部署在沙盒中运行,即,能够提高在沙盒中运行用户代码的便捷性。
在另一种可能的实现方式中,用户可以在沙盒的用户界面中编辑用户代码,并可以在沙盒中控制用户代码的运行。
在一种可能的实现方式中,在所述通过所述状态感知接口获取所述用户代码的运行状态信息之后,所述方法还包括:所述宿主程序响应于所述运行状态信息具有对应的预设动作,执行所述预设动作。
在该实现方式中,预设动作可以表示预设的基于运行状态触发的动作。预设动作可以是用户自定义的动作,也可以是默认的动作,在此不做限定。可以根据运行状态与预设动作之间的对应关系,判断用户代码的运行状态信息是否具有对应的预设动作。其中,任一运行状态对应的预设动作的数量可以是0、1、2或以上。
宿主程序可以响应于用户代码的运行状态信息具有对应的预设动作,执行所述预设动作,从而能够在用户代码的运行进入不同状态时触发不同的预设动作。例如,预设动作可以包括显示错误提示信息、显示运行状态、记录运行日志等等。其中,错误提示信息可以是针对用户代码中的错误代码的提示信息,运行状态可以是用户代码的当前运行状态,运行日志可以是用户代码本次运行的日志。例如,若所述运行状态信息指示用户代码的运行状态为正常结束,则对应的预设动作可以包括显示运行状态;若所述运行状态信息指示用户代码的运行状态为异常结束,则对应的预设动作可以包括显示错误提示信息、显示运行状态和记录运行日志;若所述运行状态信息指示用户代码的运行状态为 运行中,则对应的预设动作可以包括显示运行状态。通过宿主程序响应于用户代码的运行状态信息具有对应的预设动作,执行所述预设动作,能够及时地进行用户指引,提高教学过程中的互动性。
在该实现方式中,在通过状态感知接口获取用户代码的运行状态信息之后,宿主程序响应于所述运行状态信息具有对应的预设动作,执行所述预设动作,由此宿主程序能够获取沙盒中的用户代码的运行状态并触发预设动作,从而有助于用户进行编程学习或者编程教学。
在一种可能的实现方式中,在所述通过所述状态感知接口获取所述用户代码的运行状态信息之后,所述方法还包括:在所述运行状态信息指示所述用户代码的运行状态为正常结束的情况下,响应于再次接收到用户代码运行请求,在所述沙盒的上一次运行所述用户代码后的运行环境中再次运行所述用户代码。通过在沙盒的运行环境中运行用户代码,运行环境可能发生改变。在该实现方式中,在用户代码的运行状态为正常结束的情况下,若未接收到运行环境复位请求,则可以保持沙盒中运行环境的改变结果,使得用户代码可以在所述沙盒的改变后的运行环境中继续运行,从而能够实现用户代码在连续的上下文中运行。
在一种可能的实现方式中,在所述通过所述状态感知接口获取所述用户代码的运行状态信息之后,所述方法还包括:获取修改后的用户代码;在所述运行状态信息指示所述用户代码的运行状态为正常结束的情况下,响应于再次接收到用户代码运行请求,在所述沙盒的上一次运行所述用户代码后的运行环境中运行所述修改后的用户代码。通过在沙盒的运行环境中运行用户代码,运行环境可能发生改变。在该实现方式中,在所述用户代码运行结束后,用户可以在宿主程序的用户界面中修改用户代码,得到修改后的用户代码。或者,可以从宿主程序的外部获取修改后的用户代码,在此不做限定。在用户代码的运行状态为正常结束的情况下,若未接收到运行环境复位请求,则可以保持沙盒中运行环境的改变结果,使修改后的用户代码可以在所述沙盒的改变后的运行环境中运行,从而能够实现修改前后的用户代码在连续的上下文中运行。该实现方式中修改后的用户代码,例如,可以包括用户新输入的代码。
在一种可能的实现方式中,所述方法还包括:所述宿主程序响应于运行环境复位请求,调用复位接口,并通过所述复位接口将所述沙盒的运行环境恢复至初始状态。在该实现方式中,复位接口可以是对用于将沙盒中的运行环境恢复至初始状态的功能代码进行封装得到的,还可以是对用于将沙盒中的运行环境后重新添加一个沙盒的运行环境的功能代码进行封装得到。其中,初始状态可以表示未运行任何用户代码的状态,即,初始状态可以表示沙盒中的运行环境未被任何用户代码改变的状态。复位接口可以用于将沙盒中的运行环境恢复至初始状态,且复位接口可以供宿主程序调用。运行环境复位请求可以表示用于将沙盒中的运行环境恢复至初始状态的请求。运行环境复位请求可以是由用户触发的。在该实现方式中,通过宿主程序响应于运行环境复位请求,调用复位接 口,并通过所述复位接口将沙盒中的运行环境恢复至初始状态,能够根据用户需求使用户代码在所述沙盒的重置后的运行环境中再次运行,即,能够实现用户代码的独立运行,使用户代码的本次运行不受到之前的运行的影响。
在一种可能的实现方式中,所述方法还包括:所述宿主程序响应于运行环境删除请求,调用删除接口,并通过所述删除接口删除所述沙盒中的运行环境。在该实现方式中,删除接口可以是对用于删除沙盒中的运行环境的功能代码进行封装得到的。删除接口可以用于删除沙盒中的运行环境,且删除接口可以供宿主程序调用。运行环境删除请求可以表示用于删除沙盒中的运行环境的请求。运行环境删除请求可以是由用户触发的。通过宿主程序响应于运行环境删除请求,调用所述删除接口,并通过所述删除接口删除沙盒中的运行环境,由此宿主程序能够通过删除接口便捷地删除沙盒中的运行环境,即,能够提高删除沙盒中的运行环境的便捷性。
在一种可能的实现方式中,所述方法还包括:所述宿主程序响应于运行环境删除请求,调用删除接口,并通过所述删除接口删除所述沙盒中的运行环境;所述宿主程序响应于运行环境添加请求,调用添加接口,并通过所述添加接口在所述沙盒中添加运行环境。在该实现方式中,删除接口可以是对用于删除沙盒的运行环境的功能代码进行封装得到的。删除接口可以用于删除沙盒中的运行环境,添加接口可以用于在沙盒中添加运行环境,且删除接口和添加接口可以供宿主程序调用。运行环境删除请求可以表示用于删除沙盒中的运行环境的请求,运行环境添加请求可以表示用于在沙盒中添加运行环境的请求。根据该实现方式,宿主程序能够通过删除接口和添加接口便捷地替换沙盒中的运行环境,即,能够提高替换沙盒中的运行环境的便捷性。
在一种可能的实现方式中,所述方法还包括:所述宿主程序响应于运行环境修改请求,调用修改接口,并通过所述修改接口修改所述沙盒中的运行环境。在该实现方式中,修改接口可以是对用于修改沙盒中的运行环境的功能代码进行封装得到的。修改接口可以用于修改沙盒中的运行环境,且修改接口可以供宿主程序调用。运行环境修改请求可以表示用于修改沙盒中的运行环境的请求。运行环境修改请求可以是由用户触发的。
作为该实现方式的一个示例,运行环境修改请求可以包括要修改为的运行环境(本文也可称为“修改后的运行环境”)的标识信息,宿主程序可以响应于运行环境修改请求,调用所述修改接口,修改接口根据修改后的运行环境的标识信息修改所述沙盒中的运行环境。其中,运行环境的标识信息可以用于唯一标识运行环境,即,不同的运行环境可以具有不同的标识信息。例如,运行环境修改请求包括运行环境的标识信息A,则宿主程序可以响应于运行环境修改请求,调用所述修改接口,修改接口根据修改后的运行环境的标识信息A,将所述沙盒中的运行环境修改为运行环境A。
作为该实现方式的另一个示例,运行环境修改请求可以包括修改后的运行环境的参数信息,宿主程序可以响应于运行环境修改请求,调用所述修改接口,以通过修改接口 根据修改后的运行环境的参数信息,修改所述沙盒中的运行环境。
根据该实现方式,宿主程序能够通过修改接口便捷地修改沙盒中的运行环境,即,能够提高修改沙盒中的运行环境的便捷性。
在一种可能的实现方式中,可以响应于用户代码运行结束,清除沙盒中的用户代码。即,在该实现方式中,可以在每次用户代码运行结束后,清除沙盒中的用户代码。在另一种可能的实现方式中,可以响应于用户代码发生修改,清除沙盒中的用户代码。在另一种可能的实现方式中,可以响应于用户触发的清除代码请求,清除沙盒中的用户代码。在另一种可能的实现方式中,可以响应于运行环境复位请求,清除沙盒中的用户代码。在另一种可能的实现方式中,可以响应于运行环境删除请求,清除沙盒中的用户代码。
本公开实施例可以应用于在线编程、在线教育、人工智能、人工智能教育、在线编程教育、在线编程平台、人工智能科创平台等应用场景中。
下面通过一个具体的应用场景说明本公开实施例提供的用户代码的运行方法。在该应用场景中,可以在web编程平台的主页面宿主程序中放置一个容器节点,在该容器节点放置一个iframe作为沙盒,其中,iframe被设置为沙盒属性。
Web编程平台提供一组API(Application Programming Interface,应用程序编程接口)用于沙盒的控制。例如,这组API可以包括沙盒对应的添加接口、删除接口、运行接口和复位接口。其中,添加接口可以用于在沙盒中添加运行环境,删除接口可以用于删除沙盒中的运行环境,运行接口可以用于编译用户代码、针对编译后的用户代码添加状态感知接口以及调用沙盒对外暴露的运行代码接口以将编译后的用户代码部署在沙盒的运行环境中运行,复位接口可以用于将沙盒中的运行环境恢复至初始状态。宿主程序可以通过这组API操作沙盒。
宿主程序可以响应于运行环境添加请求,调用添加接口,在沙盒中添加运行环境。用户可以在宿主程序的用户界面中编辑用户代码。宿主程序可以通过用户界面获取用户代码。可以将沙盒中的用户代码对应的运行代码接口进行暴露。宿主程序可以响应于用户代码运行请求,调用运行接口,通过运行接口编译所述用户代码、针对编译后的用户代码添加状态感知接口、调用运行代码接口,并通过运行代码接口将编译后的用户代码部署在所述沙盒的运行环境中运行。宿主程序可以通过状态感知接口获取用户代码的运行状态信息,并可以响应于所述运行状态信息具有对应的预设动作,执行所述预设动作。
通过在沙盒的运行环境中运行用户代码,运行环境可能发生改变。在用户代码的运行状态为正常结束的情况下,若未接收到运行环境复位请求,则可以保持沙盒中运行环境的改变结果,使用户代码可以在所述沙盒的改变后的运行环境中继续运行,从而能够实现用户代码在连续的上下文中运行。宿主程序还可以响应于运行环境复位请求,调用复位接口,并通过所述复位接口将所述沙盒中的运行环境恢复至初始状态。另外,在用户代码修改后,用户也可以选择在所述沙盒保持的上次运行环境中运行修改后的用户代 码,或者可以选择在所述沙盒的重置后的运行环境中运行修改后的用户代码。由此,可以根据不同的用户需求保持或者重置沙盒中的运行环境,从而能够实现用户代码在所述沙盒的连续或者独立的运行环境中运行。
在编程教育平台中,通过采用本公开实施例提供的用户代码的运行方法,可以对沙盒中的运行环境进行状态回调和灵活的控制,能够将沙盒嵌入到任意的用户流程中,能够实现用户代码在所述沙盒的重置或者保持的运行环境中运行,方便教学内容的呈现。
可以理解,本公开提及的上述各个方法实施例,在不违背原理逻辑的情况下,均可以彼此相互结合形成结合后的实施例,限于篇幅,本公开不再赘述。本领域技术人员可以理解,在具体实施方式的上述方法中,各步骤的具体执行顺序应当以其功能和可能的内在逻辑确定。
此外,本公开还提供了用户代码的运行装置、电子设备、计算机可读存储介质、程序,上述均可用来实现本公开提供的任一种用户代码的运行方法,相应技术方案和技术效果可参见方法部分的相应记载,不再赘述。
图2示出本公开实施例提供的用户代码的运行装置的框图。如图2所示,所述用户代码的运行装置可包括:沙盒创建模块21,用于宿主程序在所述宿主程序中创建沙盒,并在所述沙盒中添加运行环境;第一获取模块22,用于宿主程序获取用户代码;添加模块23,用于所述宿主程序针对所述用户代码添加状态感知接口,其中,所述状态感知接口用于所述宿主程序感知所述用户代码的运行状态;第一运行模块24,用于所述宿主程序响应于用户代码运行请求,将所述用户代码部署在所述沙盒的运行环境中运行,并通过所述状态感知接口获取所述用户代码的运行状态信息。
在一种可能的实现方式中,所述装置还可包括:执行模块,用于所述宿主程序响应于所述运行状态信息具有对应的预设动作,执行所述预设动作。
在一种可能的实现方式中,所述装置还可包括:编译模块,用于编译所述用户代码,得到编译后的用户代码。在该实现方式中,所述添加模块23可用于针对所述编译后的用户代码添加状态感知接口;所述第一运行模块24可用于所述宿主程序响应于用户代码运行请求,将所述编译后的用户代码部署在所述沙盒的运行环境中运行,并通过所述状态感知接口获取所述编译后的用户代码的运行状态信息。
在一种可能的实现方式中,所述编译模块可用于:所述宿主程序响应于用户代码运行请求,调用运行接口,通过所述运行接口编译所述用户代码,得到编译后的用户代码;所述添加模块23可用于:通过所述运行接口针对所述编译后的用户代码添加状态感知接口;所述第一运行模块24可用于:通过所述运行接口将所述编译后的用户代码部署在所述沙盒的运行环境中运行。
在一种可能的实现方式中,所述沙盒创建模块21可用于:所述宿主程序响应于运行 环境添加请求,调用添加接口,并通过所述添加接口在所述沙盒中添加运行环境。
在一种可能的实现方式中,所述装置还可包括:暴露模块,用于对外暴露所述沙盒对应的运行代码接口。在这种实现方式下,所述第一运行模块24可用于:所述宿主程序响应于用户代码运行请求,调用所述运行代码接口,并通过所述运行代码接口将所述用户代码部署在所述沙盒的运行环境中运行。
在一种可能的实现方式中,所述装置还可包括:复位模块,用于所述宿主程序响应于运行环境复位请求,调用复位接口,并通过所述复位接口将所述沙盒的运行环境恢复至初始状态。
在一种可能的实现方式中,所述装置还可包括:删除模块,用于所述宿主程序响应于运行环境删除请求,调用删除接口,并通过所述删除接口删除所述沙盒中的运行环境。
在一种可能的实现方式中,所述装置还可包括:第二运行模块,用于所述宿主程序在所述运行状态信息指示所述用户代码的运行状态为正常结束的情况下,响应于再次接收到用户代码运行请求,在所述沙盒的上一次运行所述用户代码后的运行环境中再次运行所述用户代码。
在一种可能的实现方式中,所述装置还可包括:第二获取模块,用于获取修改后的用户代码;第三运行模块,用于所述宿主程序在所述运行状态信息指示所述用户代码的运行状态为正常结束的情况下,响应于再次接收到用户代码运行请求,在所述沙盒的上一次运行所述用户代码后的运行环境中运行所述修改后的用户代码。
在一种可能的实现方式,所述装置还可包括:修改模块,用于所述宿主程序响应于运行环境修改请求,调用修改接口,并通过所述修改接口修改所述沙盒中的运行环境。
在本公开实施例中,通过宿主程序在所述宿主程序中创建沙盒,并在所述沙盒中添加运行环境,获取用户代码,针对所述用户代码添加状态感知接口,并所述宿主程序响应于用户代码运行请求,将所述用户代码部署在所述沙盒的运行环境中运行,以及通过所述状态感知接口获取所述用户代码的运行状态信息,由此能够在为用户代码提供隔离环境、保护宿主程序的前提下,使沙盒与宿主程序联动,宿主程序能够获取沙盒中的用户代码的运行状态,从而有助于用户进行编程学习或者编程教学。
在一些实施例中,本公开实施例提供的装置具有的功能或包含的模块可以用于执行上文方法实施例描述的方法,其具体实现和技术效果可以参照上文方法实施例的描述,为了简洁,这里不再赘述。
本公开实施例还提供一种计算机可读存储介质,其上存储有计算机程序指令,所述计算机程序指令被处理器执行时实现上述方法。其中,所述计算机可读存储介质可以是非易失性计算机可读存储介质,或者可以是易失性计算机可读存储介质。
本公开实施例还提出一种计算机程序,包括计算机可读代码,当所述计算机可读代 码在电子设备中运行时,所述电子设备中的处理器执行上述方法。
本公开实施例还提供了一种计算机程序产品,包括计算机可读代码,或者承载有计算机可读代码的非易失性计算机可读存储介质,当所述计算机可读代码在电子设备中运行时,所述电子设备中的处理器执行上述方法。
本公开实施例还提供一种电子设备,包括:一个或多个处理器;用于存储可执行指令的存储器;其中,所述一个或多个处理器被配置为调用所述存储器存储的可执行指令,以执行上述方法。
电子设备可以被提供为终端、服务器或其它形态的设备。
图3示出本公开实施例提供的一种电子设备800的框图。例如,电子设备800可以是移动电话,计算机,数字广播终端,消息收发设备,游戏控制台,平板设备,医疗设备,健身设备,个人数字助理等终端。
参照图3,电子设备800可以包括以下一个或多个组件:处理组件802,存储器804,电源组件806,多媒体组件808,音频组件810,输入/输出(I/O)的接口812,传感器组件814,以及通信组件816。
处理组件802通常控制电子设备800的整体操作,诸如与显示,电话呼叫,数据通信,相机操作和记录操作相关联的操作。处理组件802可以包括一个或多个处理器820来执行指令,以完成上述的方法的全部或部分步骤。此外,处理组件802可以包括一个或多个模块,便于处理组件802和其他组件之间的交互。例如,处理组件802可以包括多媒体模块,以方便多媒体组件808和处理组件802之间的交互。
存储器804被配置为存储各种类型的数据以支持在电子设备800的操作。这些数据的示例包括用于在电子设备800上操作的任何应用程序或方法的指令,联系人数据,电话簿数据,消息,图片,视频等。存储器804可以由任何类型的易失性或非易失性存储设备或者它们的组合实现,如静态随机存取存储器(SRAM),电可擦除可编程只读存储器(EEPROM),可擦除可编程只读存储器(EPROM),可编程只读存储器(PROM),只读存储器(ROM),磁存储器,快闪存储器,磁盘或光盘。
电源组件806为电子设备800的各种组件提供电力。电源组件806可以包括电源管理系统,一个或多个电源,及其他与为电子设备800生成、管理和分配电力相关联的组件。
多媒体组件808包括在所述电子设备800和用户之间的提供一个输出接口的屏幕。在一些实施例中,屏幕可以包括液晶显示器(LCD)和触摸面板(TP)。如果屏幕包括触摸面板,屏幕可以被实现为触摸屏,以接收来自用户的输入信号。触摸面板包括一个或多个触摸传感器以感测触摸、滑动和触摸面板上的手势。所述触摸传感器可以不仅感测触摸或滑动动作的边界,而且还检测与所述触摸或滑动操作相关的持续时间和压力。 在一些实施例中,多媒体组件808包括一个前置摄像头和/或后置摄像头。当电子设备800处于操作模式,如拍摄模式或视频模式时,前置摄像头和/或后置摄像头可以接收外部的多媒体数据。每个前置摄像头和后置摄像头可以是一个固定的光学透镜系统或具有焦距和光学变焦能力。
音频组件810被配置为输出和/或输入音频信号。例如,音频组件810包括一个麦克风(MIC),当电子设备800处于操作模式,如呼叫模式、记录模式和语音识别模式时,麦克风被配置为接收外部音频信号。所接收的音频信号可以被进一步存储在存储器804或经由通信组件816发送。在一些实施例中,音频组件810还包括一个扬声器,用于输出音频信号。
I/O接口812为处理组件802和外围接口模块之间提供接口,上述外围接口模块可以是键盘,点击轮,按钮等。这些按钮可包括但不限于:主页按钮、音量按钮、启动按钮和锁定按钮。
传感器组件814包括一个或多个传感器,用于为电子设备800提供各个方面的状态评估。例如,传感器组件814可以检测到电子设备800的打开/关闭状态,组件的相对定位,例如所述组件为电子设备800的显示器和小键盘,传感器组件814还可以检测电子设备800或电子设备800一个组件的位置改变,用户与电子设备800接触的存在或不存在,电子设备800方位或加速/减速和电子设备800的温度变化。传感器组件814可以包括接近传感器,被配置用来在没有任何的物理接触时检测附近物体的存在。传感器组件814还可以包括光传感器,如互补金属氧化物半导体(CMOS)或电荷耦合装置(CCD)图像传感器,用于在成像应用中使用。在一些实施例中,该传感器组件814还可以包括加速度传感器,陀螺仪传感器,磁传感器,压力传感器或温度传感器。
通信组件816被配置为便于电子设备800和其他设备之间有线或无线方式的通信。电子设备800可以接入基于通信标准的无线网络,如无线网络(Wi-Fi)、第二代移动通信技术(2G)、第三代移动通信技术(3G)、第四代移动通信技术(4G)、通用移动通信技术的长期演进(LTE)、第五代移动通信技术(5G)或它们的组合。在一个示例性实施例中,通信组件816经由广播信道接收来自外部广播管理系统的广播信号或广播相关信息。在一个示例性实施例中,所述通信组件816还包括近场通信(NFC)模块,以促进短程通信。例如,在NFC模块可基于射频识别(RFID)技术,红外数据协会(IrDA)技术,超宽带(UWB)技术,蓝牙(BT)技术和其他技术来实现。
在示例性实施例中,电子设备800可以被一个或多个应用专用集成电路(ASIC)、数字信号处理器(DSP)、数字信号处理设备(DSPD)、可编程逻辑器件(PLD)、现场可编程门阵列(FPGA)、控制器、微控制器、微处理器或其他电子元件实现,用于执行上述方法。
在示例性实施例中,还提供了一种非易失性计算机可读存储介质,例如包括计算机 程序指令的存储器804,上述计算机程序指令可由电子设备800的处理器820执行以完成上述方法。
图4示出本公开实施例提供的一种电子设备1900的框图。例如,电子设备1900可以被提供为一服务器。参照图4,电子设备1900包括处理组件1922,其进一步包括一个或多个处理器,以及由存储器1932所代表的存储器资源,用于存储可由处理组件1922的执行的指令,例如应用程序。存储器1932中存储的应用程序可以包括一个或一个以上的每一个对应于一组指令的模块。此外,处理组件1922被配置为执行指令,以执行上述方法。
电子设备1900还可以包括一个电源组件1926被配置为执行电子设备1900的电源管理,一个有线或无线网络接口1950被配置为将电子设备1900连接到网络,和一个输入输出(I/O)接口1958。电子设备1900可以操作基于存储在存储器1932的操作系统,例如微软服务器操作系统(Windows ServerTM),苹果公司推出的基于图形用户界面操作系统(Mac OS XTM),多用户多进程的计算机操作系统(UnixTM),自由和开放原代码的类Unix操作系统(LinuxTM),开放原代码的类Unix操作系统(FreeBSDTM)或类似。
在示例性实施例中,还提供了一种非易失性计算机可读存储介质,例如包括计算机程序指令的存储器1932,上述计算机程序指令可由电子设备1900的处理组件1922执行以完成上述方法。
本公开可以是系统、方法和/或计算机程序产品。计算机程序产品可以包括计算机可读存储介质,其上载有用于使处理器实现本公开的各个方面的计算机可读程序指令。
计算机可读存储介质可以是可以保持和存储由指令执行设备使用的指令的有形设备。计算机可读存储介质例如可以是――但不限于――电存储设备、磁存储设备、光存储设备、电磁存储设备、半导体存储设备或者上述的任意合适的组合。计算机可读存储介质的更具体的例子(非穷举的列表)包括:便携式计算机盘、硬盘、随机存取存储器(RAM)、只读存储器(ROM)、可擦式可编程只读存储器(EPROM或闪存)、静态随机存取存储器(SRAM)、便携式压缩盘只读存储器(CD-ROM)、数字多功能盘(DVD)、记忆棒、软盘、机械编码设备、例如其上存储有指令的打孔卡或凹槽内凸起结构、以及上述的任意合适的组合。这里所使用的计算机可读存储介质不被解释为瞬时信号本身,诸如无线电波或者其他自由传播的电磁波、通过波导或其他传输媒介传播的电磁波(例如,通过光纤电缆的光脉冲)、或者通过电线传输的电信号。
这里所描述的计算机可读程序指令可以从计算机可读存储介质下载到各个计算/处理设备,或者通过网络、例如因特网、局域网、广域网和/或无线网下载到外部计算机或外部存储设备。网络可以包括铜传输电缆、光纤传输、无线传输、路由器、防火墙、交换机、网关计算机和/或边缘服务器。每个计算/处理设备中的网络适配卡或者网络接口 从网络接收计算机可读程序指令,并转发该计算机可读程序指令,以供存储在各个计算/处理设备中的计算机可读存储介质中。
用于执行本公开操作的计算机程序指令可以是汇编指令、指令集架构(ISA)指令、机器指令、机器相关指令、微代码、固件指令、状态设置数据、或者以一种或多种编程语言的任意组合编写的源代码或目标代码,所述编程语言包括面向对象的编程语言—诸如Smalltalk、C++等,以及常规的过程式编程语言—诸如“C”语言或类似的编程语言。计算机可读程序指令可以完全地在用户计算机上执行、部分地在用户计算机上执行、作为一个独立的软件包执行、部分在用户计算机上部分在远程计算机上执行、或者完全在远程计算机或服务器上执行。在涉及远程计算机的情形中,远程计算机可以通过任意种类的网络—包括局域网(LAN)或广域网(WAN)—连接到用户计算机,或者,可以连接到外部计算机(例如利用因特网服务提供商来通过因特网连接)。在一些实施例中,通过利用计算机可读程序指令的状态信息来个性化定制电子电路,例如可编程逻辑电路、现场可编程门阵列(FPGA)或可编程逻辑阵列(PLA),该电子电路可以执行计算机可读程序指令,从而实现本公开的各个方面。
这里参照根据本公开实施例的方法、装置(系统)和计算机程序产品的流程图和/或框图描述了本公开的各个方面。应当理解,流程图和/或框图的每个方框以及流程图和/或框图中各方框的组合,都可以由计算机可读程序指令实现。
这些计算机可读程序指令可以提供给通用计算机、专用计算机或其它可编程数据处理装置的处理器,从而生产出一种机器,使得这些指令在通过计算机或其它可编程数据处理装置的处理器执行时,产生了实现流程图和/或框图中的一个或多个方框中规定的功能/动作的装置。也可以把这些计算机可读程序指令存储在计算机可读存储介质中,这些指令使得计算机、可编程数据处理装置和/或其他设备以特定方式工作,从而,存储有指令的计算机可读介质则包括一个制造品,其包括实现流程图和/或框图中的一个或多个方框中规定的功能/动作的各个方面的指令。
也可以把计算机可读程序指令加载到计算机、其它可编程数据处理装置、或其它设备上,使得在计算机、其它可编程数据处理装置或其它设备上执行一系列操作步骤,以产生计算机实现的过程,从而使得在计算机、其它可编程数据处理装置、或其它设备上执行的指令实现流程图和/或框图中的一个或多个方框中规定的功能/动作。
附图中的流程图和框图显示了根据本公开的多个实施例的系统、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段或指令的一部分,所述模块、程序段或指令的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。在有些作为替换的实现中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个连续的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意 的是,框图和/或流程图中的每个方框、以及框图和/或流程图中的方框的组合,可以用执行规定的功能或动作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。
该计算机程序产品可以具体通过硬件、软件或其结合的方式实现。在一个可选实施例中,所述计算机程序产品具体体现为计算机存储介质,在另一个可选实施例中,计算机程序产品具体体现为软件产品,例如软件开发包(Software Development Kit,SDK)等等。
以上已经描述了本公开的各实施例,上述说明是示例性的,并非穷尽性的,并且也不限于所披露的各实施例。在不偏离所说明的各实施例的范围和精神的情况下,对于本技术领域的普通技术人员来说许多修改和变更都是显而易见的。本文中所用术语的选择,旨在最好地解释各实施例的原理、实际应用或对市场中的技术的改进,或者使本技术领域的其它普通技术人员能理解本文披露的各实施例。

Claims (15)

  1. 一种用户代码的运行方法,其中,包括:
    宿主程序在所述宿主程序中创建沙盒,并在所述沙盒中添加运行环境;
    所述宿主程序获取用户代码;
    所述宿主程序针对所述用户代码添加状态感知接口,其中,所述状态感知接口用于所述宿主程序感知所述用户代码的运行状态;
    所述宿主程序响应于用户代码运行请求,将所述用户代码部署在所述沙盒的运行环境中运行,并通过所述状态感知接口获取所述用户代码的运行状态信息。
  2. 根据权利要求1所述的方法,其中,所述方法还包括:
    所述宿主程序响应于所述运行状态信息具有对应的预设动作,执行所述预设动作。
  3. 根据权利要求1或2所述的方法,其中,
    在所述宿主程序获取用户代码之后,在所述宿主程序针对所述用户代码添加状态感知接口之前,所述方法还包括:编译所述用户代码,得到编译后的用户代码;
    所述宿主程序针对所述用户代码添加状态感知接口,包括:针对所述编译后的用户代码添加状态感知接口;
    所述宿主程序响应于用户代码运行请求,将所述用户代码部署在所述沙盒的运行环境中运行,并通过所述状态感知接口获取所述用户代码的运行状态信息,包括:所述宿主程序响应于用户代码运行请求,将所述编译后的用户代码部署在所述沙盒的运行环境中运行,并通过所述状态感知接口获取所述编译后的用户代码的运行状态信息。
  4. 根据权利要求3所述的方法,其中,
    所述编译所述用户代码,得到编译后的用户代码,包括:所述宿主程序响应于用户代码运行请求,调用运行接口,通过所述运行接口编译所述用户代码,得到编译后的用户代码;
    所述宿主程序针对所述编译后的用户代码添加状态感知接口,包括:通过所述运行接口针对所述编译后的用户代码添加状态感知接口;
    所述宿主程序响应于用户代码运行请求,将所述编译后的用户代码部署在所述沙盒的运行环境中运行,包括:通过所述运行接口将所述编译后的用户代码部署在所述沙盒的运行环境中运行。
  5. 根据权利要求1至4中任意一项所述的方法,其中,所述在所述沙盒中添加运行环境,包括:
    所述宿主程序响应于运行环境添加请求,调用添加接口,并通过所述添加接口在所述沙盒中添加运行环境。
  6. 根据权利要求1至5中任意一项所述的方法,其中,
    所述方法还包括:对外暴露所述沙盒对应的运行代码接口;
    所述宿主程序响应于用户代码运行请求,将所述用户代码部署在所述沙盒的运行环境中运行,包括:所述宿主程序响应于用户代码运行请求,调用所述运行代码接口,并 通过所述运行代码接口将所述用户代码部署在所述沙盒的运行环境中运行。
  7. 根据权利要求1至6中任意一项所述的方法,其中,所述方法还包括:
    所述宿主程序响应于运行环境复位请求,调用复位接口,并通过所述复位接口将所述沙盒的运行环境恢复至初始状态。
  8. 根据权利要求1至7中任意一项所述的方法,其中,所述方法还包括:
    所述宿主程序响应于运行环境删除请求,调用删除接口,并通过所述删除接口删除所述沙盒中的运行环境。
  9. 根据权利要求1至8中任意一项所述的方法,其中,在所述通过所述状态感知接口获取所述用户代码的运行状态信息之后,所述方法还包括:
    在所述运行状态信息指示所述用户代码的运行状态为正常结束的情况下,响应于再次接收到用户代码运行请求,在所述沙盒的上一次运行所述用户代码后的运行环境中再次运行所述用户代码。
  10. 根据权利要求1至9中任意一项所述的方法,其中,在所述通过所述状态感知接口获取所述用户代码的运行状态信息之后,所述方法还包括:
    获取修改后的用户代码;
    在所述运行状态信息指示所述用户代码的运行状态为正常结束的情况下,响应于再次接收到用户代码运行请求,在所述沙盒的上一次运行所述用户代码后的运行环境中运行所述修改后的用户代码。
  11. 根据权利要求1至10中任意一项所述的方法,其中,在所述通过所述状态感知接口获取所述用户代码的运行状态信息之后,所述方法还包括:
    所述宿主程序响应于运行环境修改请求,调用修改接口,并通过所述修改接口修改所述运行环境。
  12. 一种用户代码的运行装置,其中,包括:
    沙盒创建模块,用于宿主程序在所述宿主程序中创建沙盒,并在所述沙盒中添加运行环境;
    第一获取模块,用于所述宿主程序获取用户代码;
    添加模块,用于所述宿主程序针对所述用户代码添加状态感知接口,其中,所述状态感知接口用于所述宿主程序感知所述用户代码的运行状态;
    第一运行模块,用于所述宿主程序响应于用户代码运行请求,将所述用户代码部署在所述沙盒的运行环境中运行,并通过所述状态感知接口获取所述用户代码的运行状态信息。
  13. 一种电子设备,其中,包括:
    一个或多个处理器;
    用于存储可执行指令的存储器;
    其中,所述一个或多个处理器被配置为调用所述存储器存储的可执行指令,以执行权利要求1至11中任意一项所述的方法。
  14. 一种计算机可读存储介质,其上存储有计算机程序指令,其中,所述计算机程序指令被处理器执行时实现权利要求1至11中任意一项所述的方法。
  15. 一种计算机程序产品,包括计算机可读代码,或者承载有计算机可读代码的非易失性计算机可读存储介质,当所述计算机可读代码在电子设备中运行时,所述电子设备中的处理器执行权利要求1至11中任意一项所述的方法。
PCT/CN2022/093860 2021-11-19 2022-05-19 用户代码的运行方法及装置、电子设备和存储介质 WO2023087642A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111392308.1 2021-11-19
CN202111392308.1A CN114117409A (zh) 2021-11-19 2021-11-19 用户代码的运行方法及装置、电子设备和存储介质

Publications (1)

Publication Number Publication Date
WO2023087642A1 true WO2023087642A1 (zh) 2023-05-25

Family

ID=80439964

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/093860 WO2023087642A1 (zh) 2021-11-19 2022-05-19 用户代码的运行方法及装置、电子设备和存储介质

Country Status (2)

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

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114117409A (zh) * 2021-11-19 2022-03-01 上海商汤临港智能科技有限公司 用户代码的运行方法及装置、电子设备和存储介质

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104750537A (zh) * 2013-12-31 2015-07-01 腾讯科技(深圳)有限公司 一种执行测试用例的方法和装置
US20180046479A1 (en) * 2007-03-01 2018-02-15 George Mason Research Foundation, Inc. On-demand disposable virtual work system
CN107992308A (zh) * 2017-11-22 2018-05-04 竞技世界(北京)网络技术有限公司 一种安卓终端应用程序的插件化管理方法
CN109325345A (zh) * 2018-09-21 2019-02-12 百度在线网络技术(北京)有限公司 用于在沙盒环境中运行第三方代码的方法和装置
US20190251257A1 (en) * 2018-02-15 2019-08-15 Intel Corporation Mechanism to prevent software side channels
CN110688314A (zh) * 2019-09-25 2020-01-14 启迪国信(北京)信息技术有限公司 一种应用的性能分析方法、装置、电子设备和存储介质
CN112306566A (zh) * 2019-07-15 2021-02-02 阿里巴巴集团控股有限公司 数据处理方法及装置
CN114117409A (zh) * 2021-11-19 2022-03-01 上海商汤临港智能科技有限公司 用户代码的运行方法及装置、电子设备和存储介质

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20180046479A1 (en) * 2007-03-01 2018-02-15 George Mason Research Foundation, Inc. On-demand disposable virtual work system
CN104750537A (zh) * 2013-12-31 2015-07-01 腾讯科技(深圳)有限公司 一种执行测试用例的方法和装置
CN107992308A (zh) * 2017-11-22 2018-05-04 竞技世界(北京)网络技术有限公司 一种安卓终端应用程序的插件化管理方法
US20190251257A1 (en) * 2018-02-15 2019-08-15 Intel Corporation Mechanism to prevent software side channels
CN109325345A (zh) * 2018-09-21 2019-02-12 百度在线网络技术(北京)有限公司 用于在沙盒环境中运行第三方代码的方法和装置
CN112306566A (zh) * 2019-07-15 2021-02-02 阿里巴巴集团控股有限公司 数据处理方法及装置
CN110688314A (zh) * 2019-09-25 2020-01-14 启迪国信(北京)信息技术有限公司 一种应用的性能分析方法、装置、电子设备和存储介质
CN114117409A (zh) * 2021-11-19 2022-03-01 上海商汤临港智能科技有限公司 用户代码的运行方法及装置、电子设备和存储介质

Also Published As

Publication number Publication date
CN114117409A (zh) 2022-03-01

Similar Documents

Publication Publication Date Title
WO2016090822A1 (zh) 对固件进行升级的方法及装置
CN108182131B (zh) 监控应用运行状态的方法、装置、存储介质及电子设备
WO2016041312A1 (zh) 应用程序运行方法及装置
US20160162284A1 (en) Method and device for upgrading firmware
US20190012153A1 (en) Method and device for supporting multi-framework syntax
CN111427622B (zh) 应用程序中脚本代码的执行方法及装置
WO2021012583A1 (zh) 教学系统及方法、电子设备和存储介质
WO2023087642A1 (zh) 用户代码的运行方法及装置、电子设备和存储介质
CN109117144B (zh) 页面处理方法、装置、终端及存储介质
WO2023087751A1 (zh) 应用程序开发平台及方法、电子设备、存储介质和计算机程序产品
CN113377370A (zh) 一种文件处理方法、装置、电子设备及存储介质
CN111767058A (zh) 程序编译方法及装置、电子设备和存储介质
US11729602B2 (en) Terminal software upgrade method, terminal software upgrade apparatus and storage medium
US11210449B2 (en) Page display method and device and storage medium
CN111858334A (zh) 基于文本识别的模糊测试方法及装置
CN111338961B (zh) 应用调试方法及装置、电子设备及存储介质
CN111131000B (zh) 一种信息传输方法、装置、服务器、终端
TWI708181B (zh) 頁面的顯示方法及裝置
CN108549570B (zh) 用户界面的更新方法及装置
CN109933357B (zh) 应用程序升级方法及装置
CN111596949B (zh) 一种开发应用程序的方法及装置
CN111124553B (zh) 一种程序执行方法、装置、终端及存储介质
CN110647351B (zh) 源代码地图文件还原方法、装置及存储介质
CN109726118B (zh) 一种应用程序开发方法、装置、电子设备及存储介质
CN110347394B (zh) 软件代码解析方法及装置

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22894187

Country of ref document: EP

Kind code of ref document: A1