Transfer files between your local machine and sandboxes, or manage files directly inside the sandbox filesystem.
File operations use the sandbox proxy URL: https://<sandbox-id-or-name>.sandbox.tensorlake.ai Named sandboxes can use the sandbox name in place of the ID in the proxy hostname. The file APIs documented here run on the management URL on port 9501, which always requires authentication. Unauthenticated proxy access applies only to exposed user ports.
Copy Files
CLI
Python
TypeScript
HTTP
# Copy a local file into the sandbox
tl sbx cp data.csv < sandbox-i d > :/workspace/data.csv
# Copy a file from the sandbox to local
tl sbx cp < sandbox-i d > :/workspace/data.csv ./data.csv
from tensorlake.sandbox import SandboxClient
client = SandboxClient()
sandbox = client.create_and_connect()
sandbox.write_file( "/workspace/data.csv" , b "name,score \n Alice,95 \n Bob,87" )
content = sandbox.read_file( "/workspace/data.csv" )
print ( bytes (content).decode( "utf-8" ))
await sandbox . writeFile (
"/workspace/data.csv" ,
new TextEncoder (). encode ( "name,score \n Alice,95 \n Bob,87" ),
);
const content = await sandbox . readFile ( "/workspace/data.csv" );
console . log ( new TextDecoder (). decode ( content ));
curl -X PUT "https://<sandbox-id>.sandbox.tensorlake.ai/api/v1/files?path=/workspace/data.csv" \
-H "Authorization: Bearer $TL_API_KEY " \
-H "Content-Type: application/octet-stream" \
--data-binary "name,score\nAlice,95\nBob,87"
curl "https://<sandbox-id>.sandbox.tensorlake.ai/api/v1/files?path=/workspace/data.csv" \
-H "Authorization: Bearer $TL_API_KEY "
tl sbx cp is file-only today. Directory copy workflows should use the Python SDK, TypeScript SDK, or the raw file API.
Read Files
CLI
Python
TypeScript
HTTP
tl sbx cp < sandbox-i d > :/workspace/data.csv ./data.csv
tl sbx exec < sandbox-i d > cat /workspace/data.csv
content = sandbox.read_file( "/workspace/data.csv" )
print ( bytes (content).decode( "utf-8" ))
image_bytes = sandbox.read_file( "/workspace/chart.png" )
with open ( "chart.png" , "wb" ) as f:
f.write(image_bytes)
const content = await sandbox . readFile ( "/workspace/data.csv" );
console . log ( new TextDecoder (). decode ( content ));
const bytes = await sandbox . readFile ( "/workspace/chart.png" );
console . log ( `Read ${ bytes . byteLength } bytes` );
curl "https://<sandbox-id>.sandbox.tensorlake.ai/api/v1/files?path=/workspace/data.csv" \
-H "Authorization: Bearer $TL_API_KEY "
curl "https://<sandbox-id>.sandbox.tensorlake.ai/api/v1/files?path=/workspace/chart.png" \
-H "Authorization: Bearer $TL_API_KEY " \
-o chart.png
Write Files
CLI
Python
TypeScript
HTTP
tl sbx cp config.json < sandbox-i d > :/workspace/config.json
sandbox.write_file( "/workspace/config.json" , b '{"debug": true, "port": 8080}' )
with open ( "model.pkl" , "rb" ) as f:
sandbox.write_file( "/workspace/model.pkl" , f.read())
import { readFile } from "node:fs/promises" ;
await sandbox . writeFile (
"/workspace/config.json" ,
new TextEncoder (). encode ( '{"debug": true, "port": 8080}' ),
);
const modelBytes = await readFile ( "model.pkl" );
await sandbox . writeFile ( "/workspace/model.pkl" , modelBytes );
curl -X PUT "https://<sandbox-id>.sandbox.tensorlake.ai/api/v1/files?path=/workspace/config.json" \
-H "Authorization: Bearer $TL_API_KEY " \
-H "Content-Type: application/octet-stream" \
--data-binary '{"debug": true, "port": 8080}'
curl -X PUT "https://<sandbox-id>.sandbox.tensorlake.ai/api/v1/files?path=/workspace/model.pkl" \
-H "Authorization: Bearer $TL_API_KEY " \
-H "Content-Type: application/octet-stream" \
--data-binary @model.pkl
List Directory Contents
CLI
Python
TypeScript
HTTP
tl sbx exec < sandbox-i d > ls -la /workspace
entries = sandbox.list_directory( "/workspace" )
for entry in entries.entries:
print ( f " { entry.name } ( { entry.size } bytes)" )
const listing = await sandbox . listDirectory ( "/workspace" );
for ( const entry of listing . entries ) {
console . log ( ` ${ entry . name } ( ${ entry . size ?? 0 } bytes)` );
}
curl "https://<sandbox-id>.sandbox.tensorlake.ai/api/v1/files/list?path=/workspace" \
-H "Authorization: Bearer $TL_API_KEY "
Delete Files
CLI
Python
TypeScript
HTTP
tl sbx exec < sandbox-i d > rm -rf /workspace/temp
sandbox.delete_file( "/workspace/temp" )
await sandbox . deleteFile ( "/workspace/temp" );
curl -X DELETE "https://<sandbox-id>.sandbox.tensorlake.ai/api/v1/files?path=/workspace/temp" \
-H "Authorization: Bearer $TL_API_KEY "
Organize Files
CLI
Python
TypeScript
HTTP
tl sbx exec < sandbox-i d > mkdir -p /workspace/src/components
tl sbx exec < sandbox-i d > mv /workspace/old.txt /workspace/new.txt
sandbox.run( "mkdir" , [ "-p" , "/workspace/src/components" ])
sandbox.run( "mv" , [ "/workspace/old.txt" , "/workspace/new.txt" ])
await sandbox . run ( "mkdir" , {
args: [ "-p" , "/workspace/src/components" ],
});
await sandbox . run ( "mv" , {
args: [ "/workspace/old.txt" , "/workspace/new.txt" ],
});
Not supported in the HTTP API.
Best Practices
Use /workspace as the default directory for application files.
Use absolute paths to avoid ambiguity.
Use write_file / read_file for programmatic access.
Use tl sbx cp for single-file transfers.
Use the Python SDK, TypeScript SDK, or raw file API for directory-oriented workflows.
Learn More
Commands Execute commands in sandboxes.
Snapshots Save and restore sandbox filesystem, memory, and running processes.
Lifecycle Sandbox states, resources, and timeouts.