Run a Script#

This section shows how to create a job to run a script.

The ScriptRuntime is designed for you to define job artifacts and configurations supported by OCI Data Science Jobs natively. It can be used with any script types that is supported by the OCI Data Science Jobs, including shell scripts and python scripts.

The source code can be a single script, files in a folder or a zip/tar file.

See also: Preparing Job Artifacts.

Here is an example:

  • Python
  • YAML
from import Job, DataScienceJob, ScriptRuntime

job = (
    Job(name="My Job")
        # Configure logging for getting the job run outputs.
        # Log resource will be auto-generated if log ID is not specified.
        # If you are in an OCI data science notebook session,
        # the following configurations are not required.
        # Configurations from the notebook session will be used as defaults.
        # Shape config details are applicable only for the flexible shapes.
        .with_shape_config_details(memory_in_gbs=16, ocpus=1)
        # Minimum/Default block storage size is 50 (GB).
        # Specify the service conda environment by slug name.
        # The job artifact can be a single Python script, a directory or a zip file.
        # Environment variable
        .with_environment_variable(NAME="Welcome to OCI Data Science.")
        # Command line argument
        .with_argument("100 linux \"hi there\"")
        # The entrypoint is applicable only to directory or zip file as source
        # The entrypoint should be a path relative to the working dir.
        # Here is a file in the code_dir/my_package directory
kind: job
  name: "My Job"
    kind: infrastructure
    type: dataScienceJob
      blockStorageSize: 50
      compartmentId: <compartment_ocid>
      jobInfrastructureType: STANDALONE
      logGroupId: <log_group_ocid>
      logId: <log_ocid>
      projectId: <project_ocid>
        memoryInGBs: 16
        ocpus: 1
      shapeName: VM.Standard.E3.Flex
      subnetId: <subnet_ocid>
    kind: runtime
    type: script
      - 100 linux "hi there"
        slug: pytorch110_p38_cpu_v1
        type: service
      entrypoint: my_package/
      - name: NAME
        value: Welcome to OCI Data Science.
      scriptPathURI: local/path/to/code_dir
# Create the job on OCI Data Science
# Start a job run
run =
# Stream the job run outputs

An example script is available on Data Science AI Sample GitHub Repository.

Working Directory#

The working directory is the parent directory where the job artifacts are decompressed, for example /home/datascience/decompressed_artifact/. When the source code is a compressed file/archive (zip/tar) or a folder, you need to also specify the entrypoint using with_entrypoint(). The path of the entrypoint should be a path relative to the working directory. Note that this directory cannot be changed when using ScriptRuntime. See Python Runtime Working Directory for more details.