> ## 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.

# Crie Seu Primeiro Sandbox de Agente

## Crie uma Conta

Se você não tiver uma conta da Novita, <Link href="https://novita.ai/user/register" target="_blank">cadastre-se</Link> primeiro. Para obter detalhes, consulte o <Link href="/docs/pt-BR/guides/quickstart">guia de início rápido</Link>.

Novos usuários podem concluir uma pesquisa rápida de configuração da conta para resgatar US\$ 100 em créditos gratuitos de Sandbox. Não é necessário cartão de crédito.

## Crie uma Chave de API

Acesse a <Link href="https://novita.ai/settings/key-management" target="_blank">página de Gerenciamento de Chaves</Link> da Novita, crie uma chave de API e salve o valor da chave de API para usar nas etapas seguintes.

## Instale o SDK

Você pode instalar o SDK da Novita executando os comandos a seguir.

<CodeGroup isTerminalCommand>
  ```bash JavaScript & TypeScript SDK icon="terminal" theme={"system"}
  npm i novita-sandbox
  ```

  ```bash Python SDK icon="terminal" theme={"system"}
  pip install novita-sandbox
  ```
</CodeGroup>

## Configure as Variáveis de Ambiente

Crie um arquivo `.env` na pasta do seu projeto se ele ainda não existir e configure sua chave de API.

<Warning>
  Para projetos JavaScript e TypeScript, você precisa importar o pacote `dotenv/config` no seu projeto; para projetos Python, você precisa importar a biblioteca `dotenv` no seu projeto e chamar o método `load_dotenv` para carregar as variáveis de ambiente.
  Para obter detalhes, consulte o [exemplo](#use-sdk-to-start-agent-sandbox).
</Warning>

```bash .env icon="terminal" highlight={2} theme={"system"}
NOVITA_API_KEY=sk_*** # Novita API key obtained from previous steps
```

Ou você pode configurar a chave de API definindo uma variável de ambiente no seu terminal.

```bash Bash icon="terminal" highlight={2} theme={"system"}
export NOVITA_API_KEY=sk_*** # Novita API key obtained from previous steps
```

## Use o SDK para Iniciar o Sandbox de Agente

Abaixo há um exemplo simples que mostra como criar um sandbox, executar código dentro dele e listar arquivos no sistema de arquivos do sandbox.

<CodeGroup>
  ```js JavaScript & TypeScript icon="js" theme={"system"}
  // index.ts
  import 'dotenv/config'
  import { Sandbox } from 'novita-sandbox/code-interpreter'

  // The .env file should be located in the project root directory
  // dotenv/config will automatically look for .env in the current working directory
  // Or 
  // You can set the environment variable in the command line
  // export NOVITA_API_KEY=sk_***

  async function main() {
    const sandbox = await Sandbox.create()
    try {
      const execution = await sandbox.runCode('print("hello world")')
      console.log(execution.logs)

      const files = await sandbox.files.list('/tmp')
      console.log(files)
    } finally {
      // Close sandbox when no longer needed
      await sandbox.kill()
    }
  }
  main().catch((err) => {
    console.error(err)
    process.exit(1)
  })

  ```

  ```python Python icon="python" theme={"system"}
  # main.py
  from dotenv import load_dotenv
  from novita_sandbox.code_interpreter import Sandbox


  # The .env file should be located in the project root directory
  # dotenv will automatically look for .env in the current working directory
  load_dotenv()

  # Or 
  # You can set the environment variable in the command line
  # export NOVITA_API_KEY=sk_***

  sandbox = Sandbox.create()
  execution = sandbox.run_code("print('hello world')")
  print(execution.logs)

  files = sandbox.files.list("/")
  print(files)

  # Close sandbox when no longer needed
  sandbox.kill()
  ```
</CodeGroup>

Execute os comandos a seguir para executar o código.

<CodeGroup isTerminalCommand>
  ```bash index.ts icon="terminal" theme={"system"}
  npx tsx ./index.ts
  ```

  ```bash main.py icon="terminal" theme={"system"}
  python main.py
  ```
</CodeGroup>
