SDK
Repositories

Repositories

By default a Sandbox works like a repository. It has a .git folder and it pushes to a remote file system when the Sandbox hibernates.

If you rather want to use an existing remote repository, you can do so by simply cloning a repository to the sandbox.

const sandbox = await sdk.sandboxes.create()
const client = await sandbox.connect({
    id: 'some-user-reference',
    git: {
        // required
        email: '[email protected]',
        name: "foo" // Optional, defaults to session id
 
        // Optionally set credentials
        accessToken: '...',
        provider: 'github.com',
        username: "foo" // Optional, defaults to x-access-token
    }
})
 
await client.commands.run("git clone https://github.com/my-org/my-project.git")

This will clone the repository to a nested folder.

💡

Currently we do not support replacing the workspace .git persistence mechanism. That means you should not update that to a new remote. This will risk loss of data when archiving the Sandbox. This will be supported when the SDK Sandboxes are properly decoupled from the CodeSandbox product.