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

# Delete a Secret

`Novita.s``ecret.delete()` deletes an active Secret by name. A deleted Secret can no longer be referenced by new sandbox create, resume, or clone operations; already-running sandboxes are not rewritten. It returns the name of the deleted Secret.

## Prerequisites

```bash CLI icon="terminal" theme={"system"}
export OPENAI_API_KEY="your-openai-api-key"
```

## Example

The example creates a Secret, launches a sandbox that references it, uses the placeholder from inside the sandbox, kills the sandbox, and finally deletes the Secret once it is no longer needed.

<CodeGroup>
  ```python Python icon="python" theme={"system"}
  import os
  import uuid

  from novita_sandbox import Novita

  secret_name = f"openai-example-{uuid.uuid4().hex[:12]}"
  openai_api_key = os.environ["OPENAI_API_KEY"]
  novita = Novita()

  # Create the Secret used by the sandbox.
  novita.secret.create(
      name=secret_name,
      value=openai_api_key,
      hosts=["api.openai.com"],
      description="Sandbox Secrets example",
  )

  # Create sandbox: reference the Secret by name.
  sandbox = novita.sandbox.create(
      secret_envs={"OPENAI_API_KEY": secret_name},
  )

  try:
      # Use the secret: the proxy substitutes the real value for the allow-listed host.
      result = sandbox.commands.run(
          'curl -s https://api.openai.com/v1/models '
          '-H "Authorization: Bearer $OPENAI_API_KEY"'
      )
      print(result.stdout)
  finally:
      # Kill sandbox when done.
      sandbox.kill()

  # Handle secret: delete the Secret once no sandbox needs it anymore.
  deleted_name = novita.secret.delete(secret_name)
  print("Deleted:", deleted_name)
  ```

  ```js JavaScript & TypeScript icon="js" theme={"system"}
  import 'dotenv/config'
  import { randomUUID } from 'crypto'
  import { Novita } from 'novita-sandbox'

  const secretName = `openai-example-${randomUUID().slice(0, 12)}`
  const openaiApiKey = process.env.OPENAI_API_KEY
  const novita = new Novita()

  // Create the Secret used by the sandbox.
  await novita.secret.create({
    name: secretName,
    value: openaiApiKey,
    hosts: ['api.openai.com'],
    description: 'Sandbox Secrets example',
  })

  // Create sandbox: reference the Secret by name.
  const sandbox = await novita.sandbox.create({
    secretEnvs: { OPENAI_API_KEY: secretName },
  })

  try {
    const result = await sandbox.commands.run(
      'curl -s https://api.openai.com/v1/models -H "Authorization: Bearer $OPENAI_API_KEY"'
    )
    console.log(result.stdout)
  } finally {
    await sandbox.kill()
  }

  // Handle secret: delete the Secret once no sandbox needs it anymore.
  const deletedName = await novita.secret.delete(secretName)
  console.log('Deleted:', deletedName)
  ```
</CodeGroup>

<Note>
  Deleting a Secret does not rewrite already-running sandboxes; it only prevents new create, resume, and clone operations from referencing it. The underlying retired value is cleaned up asynchronously once no active execution authorization references it. You can reuse the same name to create a new Secret, which gets a new version and placeholder.
</Note>
