> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nebius.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Debugging failed Devlabs, jobs, and endpoints

If a job, endpoint or Devlab created from a custom image fails, gets canceled or returns an error, Serverless AI deletes the underlying virtual machine (VM) and boot disk to avoid costs. In this case, you can't connect to the deployment and debug it. To keep the VM alive for debugging, run the deployment with a "sleep-on-fail" wrapper.

> [!WARNING]
>
> For Devlabs created from a template (`--template`), you can't override the container command or arguments. You cannot add the "sleep-on-fail" wrapper in that mode. Use this approach only for Devlabs created from a custom image (`--image`).

## Prerequisites

> [tab] CLI
>
> [Install and configure](https://docs.nebius.com/cli/install.md) the Nebius AI Cloud CLI.

> [tab] Go SDK
>
> [Install and initialize the Nebius SDK for Go](https://docs.nebius.com/sdk/go/install-auth.md).

> [tab] Python SDK
>
> [Install and initialize the Nebius SDK for Python](https://docs.nebius.com/sdk/python/install-auth.md).

> [tab] JavaScript SDK
>
> [Install and initialize the Nebius SDK for JavaScript](https://docs.nebius.com/sdk/javascript/install-auth.md).

> [tab] REST API
>
> Get an access token to [authenticate to the REST API](https://docs.nebius.com/rest-api/authentication.md).

## Keep the VM alive on failure

To keep the VM alive for debugging when a Devlab, job or endpoint created from a custom image fails, use `bash -lc` and append a long sleep if the main command fails.

> [tab] CLI
>
> Add the following parameters when creating the resource:
>
> ```bash theme={null}
> nebius ai <devlab|job|endpoint> create \
>   ... \
>   --container-command bash \
>   --args "-lc '\"<your_main_command>\" || (echo FAILED; sleep 86400)'"
> ```

> [tab] Go SDK
>
> Add the following parameters to the `Spec` structure in the method that creates a Devlab, job or endpoint:
>
> ```go theme={null}
> Spec: &ai.<DevlabSpec|JobSpec|EndpointSpec>{
>     ContainerCommand: "bash",
>     Args: "-lc \"<your_main_command> || (echo FAILED; sleep 86400)\"",
> }
> ```

> [tab] Python SDK
>
> Add the following parameters to the `spec` object in the method that creates a Devlab, job or endpoint:
>
> ```python theme={null}
> spec=<DevlabSpec|JobSpec|EndpointSpec>(
>     container_command="bash",
>     args="-lc \"<your_main_command> || (echo FAILED; sleep 86400)\""
> )
> ```

> [tab] JavaScript SDK
>
> Add the following parameters to the `spec` object in the method that creates a Devlab, job or endpoint:
>
> ```js theme={null}
> spec: {
>     containerCommand: "bash",
>     args: "-lc \"<your_main_command> || (echo FAILED; sleep 86400)\""
> }
> ```

> [tab] REST API
>
> Add the following parameters to the `spec` object in the body of the request that creates a Devlab, job or endpoint:
>
> ```json theme={null}
> {
>   "containerCommand": "bash",
>   "args": "-lc \"<your_main_command> || (echo FAILED; sleep 86400)\""
> }
> ```

Replace `<your_main_command>` with the actual command you want to run.

When you use this wrapper, the deployment behaves as follows:

* If the main command succeeds, the resource exits normally.
* If the main command fails, the resource keeps running for 24 hours. During this time, you can connect to the underlying VM via SSH and debug.

> [!TIP]
>
> Use `sleep 3600` for one hour if you want a shorter debug window.

## Connect to the container by using SSH

You can connect to the container of a deployment in the following ways:

> [tab] Directly
>
> To connect to the container by using SSH, you should [create a Devlab](https://docs.nebius.com/serverless/devlabs/manage.md#how-to-create-a-devlab), [create a job](https://docs.nebius.com/serverless/jobs/manage.md#how-to-create-a-job) or [create an endpoint](https://docs.nebius.com/serverless/endpoints/manage.md#how-to-create-an-endpoint) with at least one `--ssh-key`.
>
> To run a shell inside the container for debugging, run `nebius ai devlab ssh <devlab_ID>`, `nebius ai job ssh <job_ID>` or `nebius ai endpoint ssh <endpoint_ID>`. A shell starts in the container.
>
> You can add the following parameters to these commands:
>
> * `-i` or `--identity-file`: Identity file for SSH authentication. Default: your SSH key.
> * `-s` or `--shell`: Shell to run inside the container. Default: `sh`.
>
> For example, to use `bash` and a specific key, run:
>
> * For the Devlab:
>
>   ```bash theme={null}
>   nebius ai devlab ssh <devlab_ID> -i ~/.ssh/id_rsa -s bash
>   ```
>
> * For the job:
>
>   ```bash theme={null}
>   nebius ai job ssh <job_ID> -i ~/.ssh/id_rsa -s bash
>   ```
>
> * For the endpoint:
>
>   ```bash theme={null}
>   nebius ai endpoint ssh <endpoint_ID> -i ~/.ssh/id_rsa -s bash
>   ```
>
> After you run the command, a shell inside the container is automatically opened.

> [tab] Through the underlying VM
>
> 1. Get the Devlab, job or endpoint ID:
>
>    * For a Devlab:
>
>      > [tab] CLI
>      >
>      > ```bash theme={null}
>      > nebius ai devlab list
>      > ```
>
>      > [tab] Go SDK
>      >
>      > ```go theme={null}
>      > listDevlabService := sdk.Services().Ai().V1().Devlab()
>      > Devlabs, err := listDevlabService.List(
>      >     ctx,
>      >     &ai.ListDevlabsRequest{ParentId: "<project_ID>"},
>      > )
>      > if err != nil {
>      >     return fmt.Errorf("list Devlabs: %w", err)
>      > }
>      > fmt.Println(Devlabs)
>      > ```
>
>      > [tab] Python SDK
>      >
>      > ```python theme={null}
>      > list_devlab_service = DevlabServiceClient(sdk)
>      > Devlabs = await list_devlab_service.list(
>      >     ListDevlabsRequest(parent_id="<project_ID>"),
>      > )
>      > print(Devlabs)
>      > ```
>
>      > [tab] JavaScript SDK
>      >
>      > ```ts theme={null}
>      > const listDevlabService = new DevlabService(sdk);
>      > const Devlabs = await listDevlabService.list(
>      >   ListDevlabsRequest.create({
>      >     parentId: "<project_ID>",
>      >   }),
>      > );
>      > console.log(Devlabs);
>      > ```
>
>      > [tab] REST API
>      >
>      > ```bash theme={null}
>      > curl --request GET \
>      >   --url "https://api.nebius.cloud/ai/v1/devlabs?parentId=<project_ID>" \
>      >   --header "Authorization: Bearer <access_token>"
>      > ```
>
>    * For a job:
>
>      > [tab] CLI
>      >
>      > ```bash theme={null}
>      > nebius ai job list
>      > ```
>
>      > [tab] Go SDK
>      >
>      > ```go theme={null}
>      > listJobService := sdk.Services().Ai().V1().Job()
>      > jobs, err := listJobService.List(
>      >     ctx,
>      >     &ai.ListJobsRequest{ParentId: "<project_ID>"},
>      > )
>      > if err != nil {
>      >     return fmt.Errorf("list jobs: %w", err)
>      > }
>      > fmt.Println(jobs)
>      > ```
>
>      > [tab] Python SDK
>      >
>      > ```python theme={null}
>      > list_job_service = JobServiceClient(sdk)
>      > jobs = await list_job_service.list(
>      >     ListJobsRequest(parent_id="<project_ID>"),
>      > )
>      > print(jobs)
>      > ```
>
>      > [tab] JavaScript SDK
>      >
>      > ```ts theme={null}
>      > const listJobService = new JobService(sdk);
>      > const jobs = await listJobService.list(
>      >   ListJobsRequest.create({
>      >     parentId: "<project_ID>",
>      >   }),
>      > );
>      > console.log(jobs);
>      > ```
>
>      > [tab] REST API
>      >
>      > ```bash theme={null}
>      > curl --request GET \
>      >   --url "https://api.nebius.cloud/ai/v1/jobs?parentId=<project_ID>" \
>      >   --header "Authorization: Bearer <access_token>"
>      > ```
>
>    * For an endpoint:
>
>      > [tab] CLI
>      >
>      > ```bash theme={null}
>      > nebius ai endpoint list
>      > ```
>
>      > [tab] Go SDK
>      >
>      > ```go theme={null}
>      > listEndpointService := sdk.Services().Ai().V1().Endpoint()
>      > endpoints, err := listEndpointService.List(
>      >     ctx,
>      >     &ai.ListEndpointsRequest{
>      >         ParentId: "<project_ID>",
>      >     },
>      > )
>      > if err != nil {
>      >     return fmt.Errorf("list endpoints: %w", err)
>      > }
>      > fmt.Println(endpoints)
>      > ```
>
>      > [tab] Python SDK
>      >
>      > ```python theme={null}
>      > list_endpoint_service = EndpointServiceClient(sdk)
>      > endpoints = await list_endpoint_service.list(
>      >     ListEndpointsRequest(parent_id="<project_ID>"),
>      > )
>      > print(endpoints)
>      > ```
>
>      > [tab] JavaScript SDK
>      >
>      > ```ts theme={null}
>      > const listEndpointService = new EndpointService(sdk);
>      > const endpoints = await listEndpointService.list(
>      >   ListEndpointsRequest.create({
>      >     parentId: "<project_ID>",
>      >   }),
>      > );
>      > console.log(endpoints);
>      > ```
>
>      > [tab] REST API
>      >
>      > ```bash theme={null}
>      > curl --request GET \
>      >   --url "https://api.nebius.cloud/ai/v1/endpoints?parentId=<project_ID>" \
>      >   --header "Authorization: Bearer <access_token>"
>      > ```
>
> 2. Get the public IP address of the VM.
>
>    For Devlabs and jobs, the IP address of the VM is available only while a Devlab or job is running. When the Devlab is stopped or deleted, or the job is complete or failed, their compute resources (including the VM) are released, so you can't get the IP address of the VM.
>
>    * For a Devlab:
>
>      > [tab] CLI
>      >
>      > ```bash theme={null}
>      > nebius ai devlab get <Devlab_ID> \
>      >   --format json | jq -r '.status.instances[0].public_ip'
>      > ```
>
>      > [tab] Go SDK
>      >
>      > ```go theme={null}
>      > getDevlabService := sdk.Services().Ai().V1().Devlab()
>      > devlab, err := getDevlabService.Get(
>      >     ctx,
>      >     &ai.GetDevlabRequest{Id: "<Devlab_ID>"},
>      > )
>      > if err != nil {
>      >     return fmt.Errorf("get Devlab: %w", err)
>      > }
>      > devlabInstances := devlab.GetStatus().GetInstances()
>      > if len(devlabInstances) == 0 ||
>      >     devlabInstances[0].GetPublicIp() == "" {
>      >     fmt.Println("null")
>      > } else {
>      >     fmt.Println(devlabInstances[0].GetPublicIp())
>      > }
>      > ```
>
>      > [tab] Python SDK
>      >
>      > ```python theme={null}
>      > get_devlab_service = DevlabServiceClient(sdk)
>      > devlab = await get_devlab_service.get(
>      >     GetDevlabRequest(id="<Devlab_ID>"),
>      > )
>      > status = devlab.status
>      > instances = [] if status is None else status.instances
>      > if not instances or not instances[0].public_ip:
>      >     print("null")
>      > else:
>      >     print(instances[0].public_ip)
>      > ```
>
>      > [tab] JavaScript SDK
>      >
>      > ```ts theme={null}
>      > const getDevlabService = new DevlabService(sdk);
>      > const devlab = await getDevlabService.get(
>      >   GetDevlabRequest.create({
>      >     id: "<Devlab_ID>",
>      >   }),
>      > );
>      > const devlabInstances = devlab.status?.instances ?? [];
>      > const devlabPublicIp = devlabInstances[0]?.publicIp;
>      > console.log(devlabPublicIp ? devlabPublicIp : "null");
>      > ```
>
>      > [tab] REST API
>      >
>      > ```bash theme={null}
>      > curl --request GET \
>      >   --url "https://api.nebius.cloud/ai/v1/devlabs/<Devlab_ID>" \
>      >   --header "Authorization: Bearer <access_token>" \
>      >   | jq -r '.status.instances[0].publicIp'
>      > ```
>
>    * For a job:
>
>      > [tab] CLI
>      >
>      > ```bash theme={null}
>      > nebius ai job get <job_ID> \
>      >   --format json | jq -r '.status.instances[0].public_ip'
>      > ```
>
>      > [tab] Go SDK
>      >
>      > ```go theme={null}
>      > getJobService := sdk.Services().Ai().V1().Job()
>      > job, err := getJobService.Get(
>      >     ctx,
>      >     &ai.GetJobRequest{Id: "<job_ID>"},
>      > )
>      > if err != nil {
>      >     return fmt.Errorf("get job: %w", err)
>      > }
>      > jobInstances := job.GetStatus().GetInstances()
>      > if len(jobInstances) == 0 ||
>      >     jobInstances[0].GetPublicIp() == "" {
>      >     fmt.Println("null")
>      > } else {
>      >     fmt.Println(jobInstances[0].GetPublicIp())
>      > }
>      > ```
>
>      > [tab] Python SDK
>      >
>      > ```python theme={null}
>      > get_job_service = JobServiceClient(sdk)
>      > job = await get_job_service.get(
>      >     GetJobRequest(id="<job_ID>"),
>      > )
>      > status = job.status
>      > instances = [] if status is None else status.instances
>      > if not instances or not instances[0].public_ip:
>      >     print("null")
>      > else:
>      >     print(instances[0].public_ip)
>      > ```
>
>      > [tab] JavaScript SDK
>      >
>      > ```ts theme={null}
>      > const getJobService = new JobService(sdk);
>      > const job = await getJobService.get(
>      >   GetJobRequest.create({
>      >     id: "<job_ID>",
>      >   }),
>      > );
>      > const jobInstances = job.status?.instances ?? [];
>      > const jobPublicIp = jobInstances[0]?.publicIp;
>      > console.log(jobPublicIp ? jobPublicIp : "null");
>      > ```
>
>      > [tab] REST API
>      >
>      > ```bash theme={null}
>      > curl --request GET \
>      >   --url "https://api.nebius.cloud/ai/v1/jobs/<job_ID>" \
>      >   --header "Authorization: Bearer <access_token>" \
>      >   | jq -r '.status.instances[0].publicIp'
>      > ```
>
>    * For an endpoint:
>
>      > [tab] CLI
>      >
>      > ```bash theme={null}
>      > nebius ai endpoint get <endpoint_ID> \
>      >   --format json | jq -r '.status.instances[0].public_ip'
>      > ```
>
>      > [tab] Go SDK
>      >
>      > ```go theme={null}
>      > getEndpointService := sdk.Services().Ai().V1().Endpoint()
>      > endpoint, err := getEndpointService.Get(
>      >     ctx,
>      >     &ai.GetEndpointRequest{Id: "<endpoint_ID>"},
>      > )
>      > if err != nil {
>      >     return fmt.Errorf("get endpoint: %w", err)
>      > }
>      > endpointInstances := endpoint.GetStatus().GetInstances()
>      > if len(endpointInstances) == 0 ||
>      >     endpointInstances[0].GetPublicIp() == "" {
>      >     fmt.Println("null")
>      > } else {
>      >     fmt.Println(endpointInstances[0].GetPublicIp())
>      > }
>      > ```
>
>      > [tab] Python SDK
>      >
>      > ```python theme={null}
>      > get_endpoint_service = EndpointServiceClient(sdk)
>      > endpoint = await get_endpoint_service.get(
>      >     GetEndpointRequest(id="<endpoint_ID>"),
>      > )
>      > status = endpoint.status
>      > instances = [] if status is None else status.instances
>      > if not instances or not instances[0].public_ip:
>      >     print("null")
>      > else:
>      >     print(instances[0].public_ip)
>      > ```
>
>      > [tab] JavaScript SDK
>      >
>      > ```ts theme={null}
>      > const getEndpointService = new EndpointService(sdk);
>      > const endpoint = await getEndpointService.get(
>      >   GetEndpointRequest.create({
>      >     id: "<endpoint_ID>",
>      >   }),
>      > );
>      > const endpointInstances = endpoint.status?.instances ?? [];
>      > const endpointPublicIp = endpointInstances[0]?.publicIp;
>      > console.log(endpointPublicIp ? endpointPublicIp : "null");
>      > ```
>
>      > [tab] REST API
>      >
>      > ```bash theme={null}
>      > curl --request GET \
>      >   --url "https://api.nebius.cloud/ai/v1/endpoints/<endpoint_ID>" \
>      >   --header "Authorization: Bearer <access_token>" \
>      >   | jq -r '.status.instances[0].publicIp'
>      > ```
>
> 3. Connect to the VM via SSH by using the `nebius` username and the copied IP address:
>
>    ```bash theme={null}
>    ssh nebius@<VM_IP_address>
>    ```
>
> 4. Find the running container. From the VM, run:
>
>    ```bash theme={null}
>    sudo docker ps
>    ```
>
> 5. Copy the container ID. For example, `aijob-<job_ID>-job-1`.
>
> 6. Open a shell inside the container:
>
>    ```bash theme={null}
>    sudo docker exec -it <container_ID> /bin/bash
>    ```

## Run tests inside the container

After you [connected to the container](#connect-to-the-container-by-using-ssh):

1. Check currently running processes:

   ```bash theme={null}
   ps aux
   ```

   You can identify which processes used the most computing resources, check if the script was running as expected and see when the processes started.

2. Check if GPUs are accessible:

   ```bash theme={null}
   nvidia-smi
   ```

   This test helps confirm whether the GPUs were allocated correctly and whether the Devlab, job or endpoint workloads could use them.
