Sandbox Kit

Read an error

Branch on the error kind. The same kinds come back from every provider.

A failed call throws in TypeScript and returns an error in Go. Both carry a kind, the provider, the operation, and, when a setting was rejected, the field that failed.

Branch on the kind. The same list applies to every provider. The kind names a category. It does not mean the call is safe to retry. Sandbox Kit does not retry for you.

KindWhat happened
InvalidArgumentThe request shape is wrong
UnsupportedThis provider does not implement the call or the field
AuthenticationThe credentials were rejected
PermissionDeniedThe account cannot perform this operation
NotFoundThe sandbox or the file path was not found
RateLimitedThe provider rate limit was reached
ResourceExhaustedThe provider quota or capacity was reached
CanceledThe caller canceled the operation
TimeoutThe deadline fired

Branch on the kind

import { ErrorKind, SandboxError } from "@sandbox-kit/sandbox";

try {
  await client.create(request);
} catch (error) {
  if (!(error instanceof SandboxError)) throw error;

  switch (error.kind) {
    case ErrorKind.InvalidArgument:
    case ErrorKind.Unsupported:
      console.error("Check configuration:", error.field, error.message);
      break;
    case ErrorKind.Authentication:
      console.error("Check your provider credentials.");
      break;
    case ErrorKind.PermissionDenied:
      console.error(
        "Your account does not have permission for this operation.",
      );
      break;
    case ErrorKind.NotFound:
      console.error("The sandbox or file path was not found.");
      break;
    case ErrorKind.RateLimited:
    case ErrorKind.ResourceExhausted:
      console.error("The provider's rate or resource limit was reached.");
      break;
    case ErrorKind.Canceled:
      console.error("The operation was canceled.");
      break;
    case ErrorKind.Timeout:
      console.error("The operation timed out.");
      break;
    default:
      console.error(error);
  }
}

The provider's own error is error.cause.

Read the field

Go and TypeScript use the same field string. A rule about one setting names that setting, such as resources.cpu_cores. A rule about several settings names their parent, such as network.

In TypeScript, compare error.field with the constants exported from @sandbox-kit/sandbox, such as CreateFieldResourcesCpuCores.

After a failure

An error does not prove that no sandbox exists. The provider may have created one before a later step failed, and the error does not include that id. A lifecycle call can fail after the provider has already changed the sandbox.

On Daytona, look the sandbox up with get before you retry. Modal attach does not perform that lookup.

Runnable projects: Daytona errors and Modal errors. The Go projects sit beside them under examples/go/.

On this page