ファイルの読み取り
サンドボックスのファイルシステムからファイルを読み取るには、files.read() メソッドを使用できます。
import { Sandbox } from 'novita-sandbox/code-interpreter'
const sandbox = await Sandbox.create()
// Create a file in the sandbox for testing
const filePathInSandbox = '/tmp/test-file'
await sandbox.files.write(filePathInSandbox, "test-file-content")
const fileContent = await sandbox.files.read(filePathInSandbox)
console.log(fileContent)
await sandbox.kill()
from novita_sandbox.code_interpreter import Sandbox
sandbox = Sandbox.create()
file_path_in_sandbox = '/tmp/test-file'
sandbox.files.write(file_path_in_sandbox, "test-file-content")
file_content = sandbox.files.read(file_path_in_sandbox)
print(file_content)
sandbox.kill()
単一ファイルの書き込み
サンドボックスのファイルシステムに単一ファイルを書き込むには、files.write() メソッドを使用できます。
import { Sandbox } from 'novita-sandbox/code-interpreter'
const sandbox = await Sandbox.create()
const filePathInSandbox = '/tmp/test-file'
const result = await sandbox.files.write(filePathInSandbox, "test-file-content")
console.log(result)
await sandbox.kill()
from novita_sandbox.code_interpreter import Sandbox
sandbox = Sandbox.create()
file_path_in_sandbox = '/tmp/test-file'
result = sandbox.files.write(file_path_in_sandbox, "test-file-content")
print(result)
sandbox.kill()
複数ファイルの書き込み
サンドボックスのファイルシステムに複数のファイルを書き込むには、files.write() メソッドも使用できます。
import { Sandbox } from 'novita-sandbox/code-interpreter'
const sandbox = await Sandbox.create()
const result = await sandbox.files.write([
{ path: '/tmp/test-file-1', data: 'file content 1' },
{ path: '/tmp/test-file-2', data: 'file content 2' }
])
console.log(result)
await sandbox.kill()
from novita_sandbox.code_interpreter import Sandbox
sandbox = Sandbox.create()
result = sandbox.files.write_files([
{ "path": "/tmp/test-file-1", "data": "file content 1" },
{ "path": "/tmp/test-file-2", "data": "file content 2" }
])
print(result)
sandbox.kill()