@daytonaio/sdk
TypeScript icon, indicating that this package has built-in type declarations

0.14.0 • Public • Published

Daytona SDK for TypeScript

A TypeScript SDK for interacting with the Daytona API, providing a simple interface for Daytona Sandbox management, Git operations, file system operations, and language server protocol support.

Installation

You can install the package using npm:

npm install @daytonaio/sdk

Or using yarn:

yarn add @daytonaio/sdk

Quick Start

Here's a simple example of using the SDK:

import { Daytona } from '@daytonaio/sdk'

// Initialize using environment variables
const daytona = new Daytona()

// Create a sandbox
const sandbox = await daytona.create()

// Run code in the sandbox
const response = await sandbox.process.codeRun('console.log("Hello World!")')
console.log(response.result)

// Clean up when done
await daytona.remove(sandbox)

Configuration

The SDK can be configured using environment variables or by passing a configuration object:

import { Daytona } from '@daytonaio/sdk'

// Initialize with configuration
const daytona = new Daytona({
  apiKey: 'your-api-key',
  apiUrl: 'your-api-url',
  target: 'us',
})

Or using environment variables:

  • DAYTONA_API_KEY: Your Daytona API key
  • DAYTONA_API_URL: The Daytona API URL
  • DAYTONA_TARGET: Your target environment

You can also customize sandbox creation:

const sandbox = await daytona.create({
  language: 'typescript',
  envVars: { NODE_ENV: 'development' },
  autoStopInterval: 60, // Auto-stop after 1 hour of inactivity
})

Features

  • Sandbox Management: Create, manage and remove sandboxes
  • Git Operations: Clone repositories, manage branches, and more
  • File System Operations: Upload, download, search and manipulate files
  • Language Server Protocol: Interact with language servers for code intelligence
  • Process Management: Execute code and commands in sandboxes

Examples

Execute Commands

// Execute a shell command
const response = await sandbox.process.executeCommand('echo "Hello, World!"')
console.log(response.result)

// Run TypeScript code
const response = await sandbox.process.codeRun(`
const x = 10
const y = 20
console.log(\`Sum: \${x + y}\`)
`)
console.log(response.result)

File Operations

// Upload a file
await sandbox.fs.uploadFile(
  '/path/to/file.txt',
  new File([Buffer.from('Hello, World!')], 'file.txt', { type: 'text/plain' }),
)

// Download a file
const content = await sandbox.fs.downloadFile('/path/to/file.txt')

// Search for files
const matches = await sandbox.fs.findFiles(root_dir, 'search_pattern')

Git Operations

// Clone a repository
await sandbox.git.clone('https://github.com/example/repo', '/path/to/clone')

// List branches
const branches = await sandbox.git.branches('/path/to/repo')

// Add files
await sandbox.git.add('/path/to/repo', ['file1.txt', 'file2.txt'])

Language Server Protocol

// Create and start a language server
const lsp = sandbox.createLspServer('typescript', '/path/to/project')
await lsp.start()

// Notify the lsp for the file
await lsp.didOpen('/path/to/file.ts')

// Get document symbols
const symbols = await lsp.documentSymbols('/path/to/file.ts')

// Get completions
const completions = await lsp.completions('/path/to/file.ts', {
  line: 10,
  character: 15,
})

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the Apache License, Version 2.0 - see below for details:

Copyright 2024 Daytona

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

For the full license text, please see the Apache License 2.0.

Readme

Keywords

none

Package Sidebar

Install

npm i @daytonaio/sdk

Weekly Downloads

346

Version

0.14.0

License

MIT

Unpacked Size

172 kB

Total Files

29

Last publish

Collaborators

  • gdraganic
  • zzorica
  • vedran.jukic
  • mdzaja