Ctrl + K

Git Clone & Repository Setup

Learn how to clone repositories and initialize Git in your Sandbox environment.

Clone Repository

Clone any Git repository into your sandbox.

const result = await sandbox.git.clone({
  url: 'https://github.com/user/repository',
  targetDir: '/opt/app',
  branch: 'main'
});

console.log(`Cloned to: ${result.path}`);
console.log(`Current commit: ${result.commit}`);
const response = await fetch(`${sandbox.url}/git/clone`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${sandbox.token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    url: 'https://github.com/user/repository',
    targetDir: '/opt/app',
    branch: 'main'
  })
});

const result = await response.json();
curl -X POST https://sandbox.oblien.com/git/clone \
  -H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
  -H "Content-Type: application/json"

Response:

{
  "success": true,
  "message": "Repository cloned successfully",
  "path": "/opt/app",
  "branch": "main",
  "commit": "a1b2c3d4e5f6"
}

Parameters:

ParameterTypeRequiredDescription
urlstringYesGit repository URL
targetDirstringYesDirectory to clone into
branchstringNoBranch to clone (default: repository default)
authobjectNoAuthentication configuration
rootbooleanNoClone as root (default: true)

Authentication Methods

GitHub Personal Access Token

await sandbox.git.clone({
  url: 'https://github.com/user/private-repo',
  targetDir: '/opt/app',
  auth: {
    type: 'token',
    token: 'ghp_xxxxxxxxxxxxxxxxxxxx'
  }
});
await fetch(`${sandbox.url}/git/clone`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${sandbox.token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    url: 'https://github.com/user/private-repo',
    targetDir: '/opt/app',
    auth: {
      type: 'token',
      token: 'ghp_xxxxxxxxxxxxxxxxxxxx'
    }
  })
});
curl -X POST https://sandbox.oblien.com/git/clone \
  -H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
  -H "Content-Type: application/json"

SSH Key Authentication

await sandbox.git.clone({
  url: 'git@github.com:user/private-repo.git',
  targetDir: '/opt/app',
  auth: {
    type: 'ssh',
    sshKey: process.env.SSH_PRIVATE_KEY
  }
});
await fetch(`${sandbox.url}/git/clone`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${sandbox.token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    url: 'git@github.com:user/private-repo.git',
    targetDir: '/opt/app',
    auth: {
      type: 'ssh',
      sshKey: process.env.SSH_PRIVATE_KEY
    }
  })
});
curl -X POST https://sandbox.oblien.com/git/clone \
  -H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
  -H "Content-Type: application/json"

Username & Password

await sandbox.git.clone({
  url: 'https://gitlab.com/user/repo.git',
  targetDir: '/opt/app',
  auth: {
    type: 'token',
    username: 'your-username',
    password: 'your-password-or-token'
  }
});
await fetch(`${sandbox.url}/git/clone`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${sandbox.token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    url: 'https://gitlab.com/user/repo.git',
    targetDir: '/opt/app',
    auth: {
      type: 'token',
      username: 'your-username',
      password: 'your-password-or-token'
    }
  })
});
curl -X POST https://sandbox.oblien.com/git/clone \
  -H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
  -H "Content-Type: application/json"

Initialize New Repository

Create a new Git repository in an existing directory:

await sandbox.git.init({
  repoPath: '/opt/app/my-project'
});
await fetch(`${sandbox.url}/git/init`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${sandbox.token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    repoPath: '/opt/app/my-project'
  })
});
curl -X POST https://sandbox.oblien.com/git/init \
  -H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
  -H "Content-Type: application/json"

Configure Git User

Set user name and email for commits:

await sandbox.git.configUser({
  repoPath: '/opt/app',
  name: 'AI Agent',
  email: 'ai@oblien.com'
});
await fetch(`${sandbox.url}/git/config/user`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${sandbox.token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    repoPath: '/opt/app',
    name: 'AI Agent',
    email: 'ai@oblien.com'
  })
});
curl -X POST https://sandbox.oblien.com/git/config/user \
  -H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
  -H "Content-Type: application/json"

Check Repository Status

Verify if a directory is a Git repository:

const result = await sandbox.git.check({
  repoPath: '/opt/app'
});

if (result.isGitRepository) {
  console.log('This is a Git repository');
} else {
  console.log('Not a Git repository');
}
const response = await fetch(`${sandbox.url}/git/check`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${sandbox.token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    repoPath: '/opt/app'
  })
});

const result = await response.json();
curl -X POST https://sandbox.oblien.com/git/check \
  -H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
  -H "Content-Type: application/json"

List SSH Keys

View available SSH keys in the sandbox:

const keys = await sandbox.git.listKeys();
console.log('Available SSH keys:', keys);
const response = await fetch(`${sandbox.url}/git/keys`, {
  headers: {
    'Authorization': `Bearer ${sandbox.token}`
  }
});

const keys = await response.json();
curl https://sandbox.oblien.com/git/keys \
  -H "Authorization: Bearer YOUR_SANDBOX_TOKEN"

Complete Example

// Clone repository
await sandbox.git.clone({
  url: 'https://github.com/user/project',
  targetDir: '/opt/app',
  branch: 'main',
  auth: {
    type: 'token',
    token: process.env.GITHUB_TOKEN
  }
});

// Configure user
await sandbox.git.configUser({
  repoPath: '/opt/app',
  name: 'AI Agent',
  email: 'ai@oblien.com'
});

// Make changes
await sandbox.files.edit({
  filePath: '/opt/app/README.md',
  content: '# Updated Project\n\nNew content here.'
});

// Stage and commit
await sandbox.git.add({
  repoPath: '/opt/app',
  files: ['.']
});

await sandbox.git.commit({
  repoPath: '/opt/app',
  message: 'Update README'
});

// Push to remote
await sandbox.git.push({
  repoPath: '/opt/app',
  branch: 'main',
  auth: {
    type: 'token',
    token: process.env.GITHUB_TOKEN
  }
});
// Clone repository
await fetch(`${sandbox.url}/git/clone`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${sandbox.token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    url: 'https://github.com/user/project',
    targetDir: '/opt/app',
    branch: 'main',
    auth: {
      type: 'token',
      token: process.env.GITHUB_TOKEN
    }
  })
});

// Configure user
await fetch(`${sandbox.url}/git/config/user`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${sandbox.token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    repoPath: '/opt/app',
    name: 'AI Agent',
    email: 'ai@oblien.com'
  })
});

// (Make file changes, then stage and commit)
await fetch(`${sandbox.url}/git/add`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${sandbox.token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    repoPath: '/opt/app',
    files: ['.']
  })
});

await fetch(`${sandbox.url}/git/commit`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${sandbox.token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    repoPath: '/opt/app',
    message: 'Update README'
  })
});

// Push
await fetch(`${sandbox.url}/git/push`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${sandbox.token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    repoPath: '/opt/app',
    branch: 'main',
    auth: {
      type: 'token',
      token: process.env.GITHUB_TOKEN
    }
  })
});
curl -X POST https://sandbox.oblien.com/git/clone \
  -H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
  -H "Content-Type: application/json"

Best Practices

  1. Store credentials securely: Use environment variables for tokens and SSH keys

  2. Configure Git user: Always set name and email before committing

  3. Use specific branches: Specify branch name instead of relying on defaults

  4. Handle authentication errors: Catch and handle authentication failures gracefully

Next Steps