You are reading a legacy (pre v1.0) document.
kernelID
. You can imagine kernel as a separate environment where code is executed. You can have multiple kernels running at the same time. Each kernel has its own state, so you can have multiple kernels running different code at the same time.
Kernel will be kept alive with the sandbox even if you disconnect.
Creating a new kernel
To create a new kernel there’s acreate_kernel
in Python and createKernel()
in JavaScript/TypeScript method in the CodeInterpreter
class. This method takes two optional arguments:
cwd
- working directory for the kernel, all system commands and file operations will be executed in this directorykernel name
- kernel spec name (defaults to default kernel spec for server). In our case it’spython3
. If you want to use another kernel, you have to install in the template first. In that case you probably want to use Custom Template.
Restarting a kernel
To restart a kernel you can userestart
method. This method takes one argument - kernelID
, if not specifed it will restart the default kernel. This method will restart the kernel and clear its state.
Listing kernels
To list all kernels you can uselist
method. This method returns an array of all running kernels with their IDs and kernel spec names.
Shutting down a kernel
To shutdown a kernel you can useshutdown
method. This method takes one argument - kernelID
, if not specifed it will delete the default kernel. This method will delete the kernel and all its state.