from daytona import Daytona, DaytonaConfig, CreateSandboxParams\n\n# Initialize the Daytona client
daytona = Daytona(DaytonaConfig(api_key="YOUR_API_KEY"))\n\n# Create the Sandbox instance
sandbox = daytona.create(CreateSandboxParams(language="python"))\n\n# Run code securely inside the Sandbox
response = sandbox.process.code_run('print("Sum of 3 and 4 is " + str(3 + 4))')
if response.exit_code != 0:
print(f"Error running code: {response.exit_code} {response.result}")
else:
print(response.result)\n\n# Clean up the Sandbox
daytona.remove(sandbox)
Typescript SDK
import { Daytona } from '@daytonaio/sdk'
async function main() {
// Initialize the Daytona client
const daytona = new Daytona({ apiKey: 'YOUR_API_KEY', })
let sandbox
try {
// Create the Sandbox instance
sandbox = await daytona.create({ language: 'python', })
// Run code securely inside the Sandbox
const response = await sandbox.process.codeRun('print("Sum of 3 and 4 is " + str(3 + 4))')
if (response.exitCode !== 0) {
console.error('Error running code:', response.exitCode, response.result)
} else {
console.log(response.result)
}
} catch (error) {
console.error('Sandbox flow error:', error)
} finally {
if (sandbox) await daytona.remove(sandbox)
}
}
main().catch(console.error)